test_electriq_airflex15w_heatpump.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  6. from ..const import ELECTRIQ_AIRFLEX15W_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.climate import TargetTemperatureTests
  9. from ..mixins.select import BasicSelectTests
  10. from .base_device_tests import TuyaDeviceTestCase
  11. POWER_DPS = "1"
  12. TEMPERATURE_DPS = "2"
  13. CURRENTTEMP_DPS = "3"
  14. HUMIDITY_DPS = "17"
  15. UNKNOWN20_DPS = "20"
  16. HVACMODE_DPS = "101"
  17. UNKNOWN103_DPS = "103"
  18. FAN_DPS = "104"
  19. UNKNOWN105_DPS = "105"
  20. UNKNOWN106_DPS = "106"
  21. UNIT_DPS = "109"
  22. TEMPF_DPS = "110"
  23. CURTEMPF_DPS = "111"
  24. CURHUMID_DPS = "112"
  25. class TestElectriqAirflex15WHeatpump(
  26. BasicSelectTests,
  27. TargetTemperatureTests,
  28. TuyaDeviceTestCase,
  29. ):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig(
  33. "electriq_airflex15w_heatpump.yaml", ELECTRIQ_AIRFLEX15W_PAYLOAD
  34. )
  35. self.subject = self.entities.get("climate")
  36. self.setUpTargetTemperature(
  37. TEMPERATURE_DPS,
  38. self.subject,
  39. min=16,
  40. max=31,
  41. )
  42. self.setUpBasicSelect(
  43. UNIT_DPS,
  44. self.entities.get("select_temperature_unit"),
  45. {
  46. False: "Celsius",
  47. True: "Fahrenheit",
  48. },
  49. )
  50. self.mark_secondary(["select_temperature_unit"])
  51. def test_supported_features(self):
  52. self.assertEqual(
  53. self.subject.supported_features,
  54. (
  55. ClimateEntityFeature.TARGET_TEMPERATURE
  56. | ClimateEntityFeature.TARGET_HUMIDITY
  57. | ClimateEntityFeature.FAN_MODE
  58. | ClimateEntityFeature.PRESET_MODE
  59. ),
  60. )
  61. def test_icon(self):
  62. self.dps[POWER_DPS] = True
  63. self.dps[HVACMODE_DPS] = "0"
  64. self.assertEqual(self.subject.icon, "mdi:hvac")
  65. self.dps[HVACMODE_DPS] = "1"
  66. self.assertEqual(self.subject.icon, "mdi:snowflake")
  67. self.dps[HVACMODE_DPS] = "2"
  68. self.assertEqual(self.subject.icon, "mdi:fire")
  69. self.dps[HVACMODE_DPS] = "3"
  70. self.assertEqual(self.subject.icon, "mdi:water")
  71. self.dps[HVACMODE_DPS] = "4"
  72. self.assertEqual(self.subject.icon, "mdi:fan")
  73. self.dps[HVACMODE_DPS] = "5"
  74. self.assertEqual(self.subject.icon, "mdi:leaf")
  75. self.dps[POWER_DPS] = False
  76. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  77. def test_temperature_unit(self):
  78. self.dps[UNIT_DPS] = False
  79. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  80. self.dps[UNIT_DPS] = True
  81. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  82. def test_current_temperature(self):
  83. self.dps[UNIT_DPS] = False
  84. self.dps[CURRENTTEMP_DPS] = 25
  85. self.assertEqual(self.subject.current_temperature, 25)
  86. self.dps[UNIT_DPS] = True
  87. self.dps[CURTEMPF_DPS] = 78
  88. self.assertEqual(self.subject.current_temperature, 78)
  89. def test_temperature_f(self):
  90. self.dps[UNIT_DPS] = True
  91. self.dps[TEMPF_DPS] = 90
  92. self.assertEqual(self.subject.target_temperature, 90)
  93. async def test_set_temperature_f(self):
  94. self.dps[UNIT_DPS] = True
  95. async with assert_device_properties_set(
  96. self.subject._device,
  97. {TEMPF_DPS: 85},
  98. ):
  99. await self.subject.async_set_temperature(temperature=85)
  100. def test_hvac_mode(self):
  101. self.dps[POWER_DPS] = True
  102. self.dps[HVACMODE_DPS] = "2"
  103. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  104. self.dps[HVACMODE_DPS] = "1"
  105. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  106. self.dps[HVACMODE_DPS] = "3"
  107. self.assertEqual(self.subject.hvac_mode, HVACMode.DRY)
  108. self.dps[HVACMODE_DPS] = "4"
  109. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  110. self.dps[HVACMODE_DPS] = "0"
  111. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  112. self.dps[HVACMODE_DPS] = "5"
  113. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  114. self.dps[POWER_DPS] = False
  115. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  116. def test_hvac_modes(self):
  117. self.assertCountEqual(
  118. self.subject.hvac_modes,
  119. [
  120. HVACMode.OFF,
  121. HVACMode.HEAT,
  122. HVACMode.HEAT_COOL,
  123. HVACMode.COOL,
  124. HVACMode.DRY,
  125. HVACMode.FAN_ONLY,
  126. ],
  127. )
  128. async def test_turn_on(self):
  129. async with assert_device_properties_set(
  130. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "2"}
  131. ):
  132. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  133. async def test_turn_off(self):
  134. async with assert_device_properties_set(
  135. self.subject._device, {POWER_DPS: False}
  136. ):
  137. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  138. def test_fan_mode(self):
  139. self.dps[FAN_DPS] = "1"
  140. self.assertEqual(self.subject.fan_mode, "low")
  141. self.dps[FAN_DPS] = "2"
  142. self.assertEqual(self.subject.fan_mode, "medium")
  143. self.dps[FAN_DPS] = "3"
  144. self.assertEqual(self.subject.fan_mode, "high")
  145. def test_fan_modes(self):
  146. self.assertCountEqual(
  147. self.subject.fan_modes,
  148. [
  149. "low",
  150. "medium",
  151. "high",
  152. ],
  153. )
  154. async def test_set_fan_mode_to_low(self):
  155. async with assert_device_properties_set(
  156. self.subject._device,
  157. {FAN_DPS: "1"},
  158. ):
  159. await self.subject.async_set_fan_mode("low")
  160. async def test_set_fan_mode_to_medium(self):
  161. async with assert_device_properties_set(
  162. self.subject._device,
  163. {FAN_DPS: "2"},
  164. ):
  165. await self.subject.async_set_fan_mode("medium")
  166. async def test_set_fan_mode_to_high(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {FAN_DPS: "3"},
  170. ):
  171. await self.subject.async_set_fan_mode("high")
  172. def test_humidity(self):
  173. self.dps[HUMIDITY_DPS] = 74
  174. self.assertEqual(self.subject.target_humidity, 74)
  175. async def test_set_humidity(self):
  176. async with assert_device_properties_set(
  177. self.subject._device,
  178. {HUMIDITY_DPS: 40},
  179. ):
  180. await self.subject.async_set_humidity(40)
  181. def test_extra_state_attribures(self):
  182. self.dps[UNKNOWN20_DPS] = 20
  183. self.dps[UNKNOWN103_DPS] = True
  184. self.dps[UNKNOWN105_DPS] = 105
  185. self.dps[UNKNOWN106_DPS] = True
  186. self.assertEqual(
  187. self.subject.extra_state_attributes,
  188. {
  189. "unknown_20": 20,
  190. "unknown_103": True,
  191. "unknown_105": 105,
  192. "unknown_106": True,
  193. },
  194. )