test_devola_patio_heater.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.components.sensor import SensorDeviceClass
  6. from homeassistant.const import (
  7. PERCENTAGE,
  8. UnitOfTime,
  9. UnitOfTemperature,
  10. )
  11. from ..const import DEVOLA_PATIO_HEATER_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.lock import BasicLockTests
  15. from ..mixins.number import BasicNumberTests
  16. from ..mixins.sensor import MultiSensorTests
  17. from .base_device_tests import TuyaDeviceTestCase
  18. HVACMODE_DPS = "1"
  19. TEMPERATURE_DPS = "2"
  20. CURRENTTEMP_DPS = "3"
  21. MODE_DPS = "4"
  22. POWERLEVEL_DPS = "5"
  23. PRESET_DPS = "6"
  24. LOCK_DPS = "7"
  25. TIMER_DPS = "12"
  26. HVACACTION_DPS = "14"
  27. UNIT_DPS = "19"
  28. TEMPF_DPS = "20"
  29. CURTEMPF_DPS = "21"
  30. class TestDevolaPatioHeater(
  31. BasicLockTests,
  32. BasicNumberTests,
  33. MultiSensorTests,
  34. TargetTemperatureTests,
  35. TuyaDeviceTestCase,
  36. ):
  37. __test__ = True
  38. def setUp(self):
  39. self.setUpForConfig("devola_patio_heater.yaml", DEVOLA_PATIO_HEATER_PAYLOAD)
  40. self.subject = self.entities.get("climate")
  41. self.setUpTargetTemperature(
  42. TEMPERATURE_DPS,
  43. self.subject,
  44. min=5,
  45. max=45,
  46. )
  47. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  48. self.setUpBasicNumber(
  49. TIMER_DPS,
  50. self.entities.get("number_timer"),
  51. max=1440,
  52. step=1.0,
  53. unit=UnitOfTime.MINUTES,
  54. )
  55. self.setUpMultiSensors(
  56. [
  57. {
  58. "dps": POWERLEVEL_DPS,
  59. "name": "sensor_power_level",
  60. "unit": PERCENTAGE,
  61. "device_class": SensorDeviceClass.POWER_FACTOR,
  62. "testdata": ("2", 50),
  63. "options": [25, 50, 75, 100],
  64. },
  65. {
  66. "dps": MODE_DPS,
  67. "name": "sensor_mode",
  68. "testdata": ("test", "test"),
  69. },
  70. ],
  71. )
  72. self.mark_secondary(
  73. [
  74. "lock_child_lock",
  75. "number_timer",
  76. "sensor_power_level",
  77. "sensor_mode",
  78. ]
  79. )
  80. def test_supported_features(self):
  81. self.assertEqual(
  82. self.subject.supported_features,
  83. (
  84. ClimateEntityFeature.TARGET_TEMPERATURE
  85. | ClimateEntityFeature.PRESET_MODE
  86. ),
  87. )
  88. def test_icon(self):
  89. self.dps[HVACMODE_DPS] = True
  90. self.assertEqual(self.subject.icon, "mdi:fire")
  91. self.dps[HVACMODE_DPS] = False
  92. self.assertEqual(self.subject.icon, "mdi:fire-off")
  93. def test_temperature_unit(self):
  94. self.dps[UNIT_DPS] = "c"
  95. self.assertEqual(
  96. self.subject.temperature_unit,
  97. UnitOfTemperature.CELSIUS,
  98. )
  99. self.dps[UNIT_DPS] = "f"
  100. self.assertEqual(
  101. self.subject.temperature_unit,
  102. UnitOfTemperature.FAHRENHEIT,
  103. )
  104. async def test_legacy_set_temperature_with_preset_mode(self):
  105. async with assert_device_properties_set(
  106. self.subject._device, {PRESET_DPS: True}
  107. ):
  108. await self.subject.async_set_temperature(preset_mode="Eco")
  109. async def test_legacy_set_temperature_with_both_properties(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {
  113. TEMPERATURE_DPS: 22,
  114. PRESET_DPS: True,
  115. },
  116. ):
  117. await self.subject.async_set_temperature(temperature=22, preset_mode="Eco")
  118. def test_current_temperature(self):
  119. self.dps[CURRENTTEMP_DPS] = 25
  120. self.assertEqual(self.subject.current_temperature, 25)
  121. def test_current_temperature_redirects_in_f(self):
  122. self.dps[CURRENTTEMP_DPS] = 24
  123. self.dps[CURTEMPF_DPS] = 75
  124. self.dps[UNIT_DPS] = "f"
  125. self.assertEqual(self.subject.current_temperature, 75)
  126. def test_hvac_mode(self):
  127. self.dps[HVACMODE_DPS] = True
  128. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  129. self.dps[HVACMODE_DPS] = False
  130. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  131. def test_hvac_modes(self):
  132. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  133. async def test_turn_on(self):
  134. async with assert_device_properties_set(
  135. self.subject._device, {HVACMODE_DPS: True}
  136. ):
  137. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  138. async def test_turn_off(self):
  139. async with assert_device_properties_set(
  140. self.subject._device, {HVACMODE_DPS: False}
  141. ):
  142. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  143. def test_preset_mode(self):
  144. self.dps[PRESET_DPS] = False
  145. self.assertEqual(self.subject.preset_mode, "Normal")
  146. self.dps[PRESET_DPS] = True
  147. self.assertEqual(self.subject.preset_mode, "Eco")
  148. self.dps[PRESET_DPS] = None
  149. self.assertIs(self.subject.preset_mode, None)
  150. def test_preset_modes(self):
  151. self.assertCountEqual(self.subject.preset_modes, ["Normal", "Eco"])
  152. async def test_set_preset_mode_to_normal(self):
  153. async with assert_device_properties_set(
  154. self.subject._device,
  155. {PRESET_DPS: False},
  156. ):
  157. await self.subject.async_set_preset_mode("Normal")
  158. async def test_set_preset_mode_to_eco(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {PRESET_DPS: True},
  162. ):
  163. await self.subject.async_set_preset_mode("Eco")