test_goldair_gpph_heater.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
  2. from homeassistant.components.climate.const import (
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. SUPPORT_PRESET_MODE,
  6. SUPPORT_SWING_MODE,
  7. SUPPORT_TARGET_TEMPERATURE,
  8. )
  9. from homeassistant.const import DEVICE_CLASS_POWER_FACTOR, PERCENTAGE, STATE_UNAVAILABLE
  10. from ..const import GPPH_HEATER_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from ..mixins.binary_sensor import BasicBinarySensorTests
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.light import BasicLightTests
  15. from ..mixins.lock import BasicLockTests
  16. from ..mixins.number import BasicNumberTests
  17. from ..mixins.sensor import BasicSensorTests
  18. from .base_device_tests import TuyaDeviceTestCase
  19. HVACMODE_DPS = "1"
  20. TEMPERATURE_DPS = "2"
  21. CURRENTTEMP_DPS = "3"
  22. PRESET_DPS = "4"
  23. LOCK_DPS = "6"
  24. ERROR_DPS = "12"
  25. POWERLEVEL_DPS = "101"
  26. TIMER_DPS = "102"
  27. TIMERACT_DPS = "103"
  28. LIGHT_DPS = "104"
  29. SWING_DPS = "105"
  30. ECOTEMP_DPS = "106"
  31. class TestGoldairHeater(
  32. BasicBinarySensorTests,
  33. BasicLightTests,
  34. BasicLockTests,
  35. BasicNumberTests,
  36. BasicSensorTests,
  37. TargetTemperatureTests,
  38. TuyaDeviceTestCase,
  39. ):
  40. __test__ = True
  41. def setUp(self):
  42. self.setUpForConfig("goldair_gpph_heater.yaml", GPPH_HEATER_PAYLOAD)
  43. self.subject = self.entities.get("climate")
  44. self.setUpTargetTemperature(
  45. TEMPERATURE_DPS,
  46. self.subject,
  47. min=5,
  48. max=35,
  49. )
  50. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  51. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  52. self.setUpBasicNumber(
  53. TIMER_DPS, self.entities.get("number_timer"), min=0, max=1440, step=60
  54. )
  55. self.setUpBasicSensor(
  56. POWERLEVEL_DPS,
  57. self.entities.get("sensor_power_level"),
  58. unit=PERCENTAGE,
  59. device_class=DEVICE_CLASS_POWER_FACTOR,
  60. testdata=("2", 40),
  61. )
  62. self.setUpBasicBinarySensor(
  63. ERROR_DPS,
  64. self.entities.get("binary_sensor_error"),
  65. device_class=DEVICE_CLASS_PROBLEM,
  66. testdata=(1, 0),
  67. )
  68. def test_supported_features(self):
  69. self.assertEqual(
  70. self.subject.supported_features,
  71. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE | SUPPORT_SWING_MODE,
  72. )
  73. def test_icon(self):
  74. self.dps[HVACMODE_DPS] = True
  75. self.assertEqual(self.subject.icon, "mdi:radiator")
  76. self.dps[HVACMODE_DPS] = False
  77. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  78. self.dps[HVACMODE_DPS] = True
  79. self.dps[POWERLEVEL_DPS] = "stop"
  80. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  81. def test_temperature_unit_returns_device_temperature_unit(self):
  82. self.assertEqual(
  83. self.subject.temperature_unit, self.subject._device.temperature_unit
  84. )
  85. def test_target_temperature_in_eco_and_af_modes(self):
  86. self.dps[TEMPERATURE_DPS] = 25
  87. self.dps[ECOTEMP_DPS] = 15
  88. self.dps[PRESET_DPS] = "ECO"
  89. self.assertEqual(self.subject.target_temperature, 15)
  90. self.dps[PRESET_DPS] = "AF"
  91. self.assertIs(self.subject.target_temperature, None)
  92. def test_minimum_temperature(self):
  93. self.dps[PRESET_DPS] = "C"
  94. self.assertEqual(self.subject.min_temp, 5)
  95. self.dps[PRESET_DPS] = "ECO"
  96. self.assertEqual(self.subject.min_temp, 5)
  97. self.dps[PRESET_DPS] = "AF"
  98. self.assertIs(self.subject.min_temp, 5)
  99. def test_maximum_target_temperature(self):
  100. self.dps[PRESET_DPS] = "C"
  101. self.assertEqual(self.subject.max_temp, 35)
  102. self.dps[PRESET_DPS] = "ECO"
  103. self.assertEqual(self.subject.max_temp, 21)
  104. self.dps[PRESET_DPS] = "AF"
  105. self.assertIs(self.subject.max_temp, 5)
  106. async def test_legacy_set_temperature_with_preset_mode(self):
  107. async with assert_device_properties_set(
  108. self.subject._device, {PRESET_DPS: "C"}
  109. ):
  110. await self.subject.async_set_temperature(preset_mode="comfort")
  111. async def test_legacy_set_temperature_with_both_properties(self):
  112. async with assert_device_properties_set(
  113. self.subject._device,
  114. {
  115. TEMPERATURE_DPS: 25,
  116. PRESET_DPS: "C",
  117. },
  118. ):
  119. await self.subject.async_set_temperature(
  120. temperature=25, preset_mode="comfort"
  121. )
  122. async def test_set_target_temperature_in_eco_mode(self):
  123. self.dps[PRESET_DPS] = "ECO"
  124. async with assert_device_properties_set(
  125. self.subject._device, {ECOTEMP_DPS: 15}
  126. ):
  127. await self.subject.async_set_target_temperature(15)
  128. async def test_set_target_temperature_fails_outside_valid_range_in_eco(self):
  129. self.dps[PRESET_DPS] = "ECO"
  130. with self.assertRaisesRegex(
  131. ValueError, "eco_temperature \\(4\\) must be between 5 and 21"
  132. ):
  133. await self.subject.async_set_target_temperature(4)
  134. with self.assertRaisesRegex(
  135. ValueError, "eco_temperature \\(22\\) must be between 5 and 21"
  136. ):
  137. await self.subject.async_set_target_temperature(22)
  138. async def test_set_target_temperature_fails_in_anti_freeze(self):
  139. self.dps[PRESET_DPS] = "AF"
  140. with self.assertRaisesRegex(
  141. AttributeError, "temperature cannot be set at this time"
  142. ):
  143. await self.subject.async_set_target_temperature(25)
  144. def test_current_temperature(self):
  145. self.dps[CURRENTTEMP_DPS] = 25
  146. self.assertEqual(self.subject.current_temperature, 25)
  147. def test_humidity_unsupported(self):
  148. self.assertIsNone(self.subject.min_humidity)
  149. self.assertIsNone(self.subject.max_humidity)
  150. self.assertIsNone(self.subject.current_humidity)
  151. with self.assertRaises(NotImplementedError):
  152. self.subject.target_humidity
  153. async def test_set_humidity_unsupported(self):
  154. with self.assertRaises(NotImplementedError):
  155. await self.subject.async_set_humidity(50)
  156. def test_hvac_mode(self):
  157. self.dps[HVACMODE_DPS] = True
  158. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  159. self.dps[HVACMODE_DPS] = False
  160. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  161. self.dps[HVACMODE_DPS] = None
  162. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  163. def test_hvac_modes(self):
  164. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  165. async def test_turn_on(self):
  166. async with assert_device_properties_set(
  167. self.subject._device, {HVACMODE_DPS: True}
  168. ):
  169. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  170. async def test_turn_off(self):
  171. async with assert_device_properties_set(
  172. self.subject._device, {HVACMODE_DPS: False}
  173. ):
  174. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  175. def test_preset_mode(self):
  176. self.dps[PRESET_DPS] = "C"
  177. self.assertEqual(self.subject.preset_mode, "comfort")
  178. self.dps[PRESET_DPS] = "ECO"
  179. self.assertEqual(self.subject.preset_mode, "eco")
  180. self.dps[PRESET_DPS] = "AF"
  181. self.assertEqual(self.subject.preset_mode, "away")
  182. self.dps[PRESET_DPS] = None
  183. self.assertIs(self.subject.preset_mode, None)
  184. def test_preset_modes(self):
  185. self.assertCountEqual(self.subject.preset_modes, ["comfort", "eco", "away"])
  186. async def test_set_preset_mode_to_comfort(self):
  187. async with assert_device_properties_set(
  188. self.subject._device,
  189. {PRESET_DPS: "C"},
  190. ):
  191. await self.subject.async_set_preset_mode("comfort")
  192. async def test_set_preset_mode_to_eco(self):
  193. async with assert_device_properties_set(
  194. self.subject._device,
  195. {PRESET_DPS: "ECO"},
  196. ):
  197. await self.subject.async_set_preset_mode("eco")
  198. async def test_set_preset_mode_to_anti_freeze(self):
  199. async with assert_device_properties_set(
  200. self.subject._device,
  201. {PRESET_DPS: "AF"},
  202. ):
  203. await self.subject.async_set_preset_mode("away")
  204. def test_power_level_returns_user_power_level(self):
  205. self.dps[SWING_DPS] = "user"
  206. self.dps[POWERLEVEL_DPS] = "stop"
  207. self.assertEqual(self.subject.swing_mode, "Stop")
  208. self.dps[POWERLEVEL_DPS] = "3"
  209. self.assertEqual(self.subject.swing_mode, "3")
  210. def test_non_user_swing_mode(self):
  211. self.dps[SWING_DPS] = "stop"
  212. self.assertEqual(self.subject.swing_mode, "Stop")
  213. self.dps[SWING_DPS] = "auto"
  214. self.assertEqual(self.subject.swing_mode, "Auto")
  215. self.dps[SWING_DPS] = None
  216. self.assertIs(self.subject.swing_mode, None)
  217. def test_swing_modes(self):
  218. self.assertCountEqual(
  219. self.subject.swing_modes,
  220. ["Stop", "1", "2", "3", "4", "5", "Auto"],
  221. )
  222. async def test_set_power_level_to_stop(self):
  223. async with assert_device_properties_set(
  224. self.subject._device,
  225. {POWERLEVEL_DPS: "stop", SWING_DPS: "stop"},
  226. ):
  227. await self.subject.async_set_swing_mode("Stop")
  228. async def test_set_swing_mode_to_auto(self):
  229. async with assert_device_properties_set(
  230. self.subject._device,
  231. {SWING_DPS: "auto"},
  232. ):
  233. await self.subject.async_set_swing_mode("Auto")
  234. async def test_set_power_level_to_numeric_value(self):
  235. async with assert_device_properties_set(
  236. self.subject._device,
  237. {SWING_DPS: "user", POWERLEVEL_DPS: "3"},
  238. ):
  239. await self.subject.async_set_swing_mode("3")
  240. def test_device_state_attributes(self):
  241. self.dps[ERROR_DPS] = "something"
  242. self.dps[TIMER_DPS] = 5
  243. self.dps[TIMERACT_DPS] = True
  244. self.dps[POWERLEVEL_DPS] = 4
  245. self.assertDictEqual(
  246. self.subject.device_state_attributes,
  247. {
  248. "error": "something",
  249. "timer": 5,
  250. "timer_mode": True,
  251. "power_level": "4",
  252. },
  253. )
  254. def test_light_icon(self):
  255. self.dps[LIGHT_DPS] = True
  256. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  257. self.dps[LIGHT_DPS] = False
  258. self.assertEqual(self.basicLight.icon, "mdi:led-off")