test_electriq_airflex15w_heatpump.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.const import PERCENTAGE, UnitOfTemperature
  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] = "5"
  72. self.assertEqual(self.subject.icon, "mdi:fan")
  73. self.dps[POWER_DPS] = False
  74. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  75. def test_temperature_unit(self):
  76. self.dps[UNIT_DPS] = False
  77. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  78. self.dps[UNIT_DPS] = True
  79. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.FAHRENHEIT)
  80. def test_current_temperature(self):
  81. self.dps[UNIT_DPS] = False
  82. self.dps[CURRENTTEMP_DPS] = 25
  83. self.assertEqual(self.subject.current_temperature, 25)
  84. self.dps[UNIT_DPS] = True
  85. self.dps[CURTEMPF_DPS] = 78
  86. self.assertEqual(self.subject.current_temperature, 78)
  87. def test_temperature_f(self):
  88. self.dps[UNIT_DPS] = True
  89. self.dps[TEMPF_DPS] = 90
  90. self.assertEqual(self.subject.target_temperature, 90)
  91. async def test_set_temperature_f(self):
  92. self.dps[UNIT_DPS] = True
  93. async with assert_device_properties_set(
  94. self.subject._device,
  95. {TEMPF_DPS: 85},
  96. ):
  97. await self.subject.async_set_temperature(temperature=85)
  98. def test_hvac_mode(self):
  99. self.dps[POWER_DPS] = True
  100. self.dps[HVACMODE_DPS] = "2"
  101. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  102. self.dps[HVACMODE_DPS] = "1"
  103. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  104. self.dps[HVACMODE_DPS] = "3"
  105. self.assertEqual(self.subject.hvac_mode, HVACMode.DRY)
  106. self.dps[HVACMODE_DPS] = "0"
  107. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  108. self.dps[HVACMODE_DPS] = "5"
  109. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  110. self.dps[POWER_DPS] = False
  111. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  112. def test_hvac_modes(self):
  113. self.assertCountEqual(
  114. self.subject.hvac_modes,
  115. [
  116. HVACMode.OFF,
  117. HVACMode.HEAT,
  118. HVACMode.HEAT_COOL,
  119. HVACMode.COOL,
  120. HVACMode.DRY,
  121. HVACMode.FAN_ONLY,
  122. ],
  123. )
  124. async def test_turn_on(self):
  125. async with assert_device_properties_set(
  126. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "2"}
  127. ):
  128. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  129. async def test_turn_off(self):
  130. async with assert_device_properties_set(
  131. self.subject._device, {POWER_DPS: False}
  132. ):
  133. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  134. def test_fan_mode(self):
  135. self.dps[FAN_DPS] = "1"
  136. self.assertEqual(self.subject.fan_mode, "high")
  137. self.dps[FAN_DPS] = "2"
  138. self.assertEqual(self.subject.fan_mode, "medium")
  139. self.dps[FAN_DPS] = "3"
  140. self.assertEqual(self.subject.fan_mode, "low")
  141. def test_fan_modes(self):
  142. self.assertCountEqual(
  143. self.subject.fan_modes,
  144. [
  145. "high",
  146. "medium",
  147. "low",
  148. ],
  149. )
  150. async def test_set_fan_mode_to_low(self):
  151. async with assert_device_properties_set(
  152. self.subject._device,
  153. {FAN_DPS: "1"},
  154. ):
  155. await self.subject.async_set_fan_mode("high")
  156. async def test_set_fan_mode_to_medium(self):
  157. async with assert_device_properties_set(
  158. self.subject._device,
  159. {FAN_DPS: "2"},
  160. ):
  161. await self.subject.async_set_fan_mode("medium")
  162. async def test_set_fan_mode_to_high(self):
  163. async with assert_device_properties_set(
  164. self.subject._device,
  165. {FAN_DPS: "3"},
  166. ):
  167. await self.subject.async_set_fan_mode("low")
  168. def test_humidity(self):
  169. self.dps[HUMIDITY_DPS] = 74
  170. self.assertEqual(self.subject.target_humidity, 74)
  171. async def test_set_humidity(self):
  172. async with assert_device_properties_set(
  173. self.subject._device,
  174. {HUMIDITY_DPS: 40},
  175. ):
  176. await self.subject.async_set_humidity(40)
  177. def test_extra_state_attribures(self):
  178. self.dps[UNKNOWN20_DPS] = 20
  179. self.dps[UNKNOWN103_DPS] = True
  180. self.dps[UNKNOWN105_DPS] = 105
  181. self.dps[UNKNOWN106_DPS] = True
  182. self.assertEqual(
  183. self.subject.extra_state_attributes,
  184. {
  185. "unknown_20": 20,
  186. "unknown_103": True,
  187. "unknown_105": 105,
  188. "unknown_106": True,
  189. },
  190. )