4
0

test_goldair_dehumidifier.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. from unittest.mock import ANY
  2. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  3. from homeassistant.components.light import ColorMode
  4. from homeassistant.components.sensor import SensorDeviceClass
  5. from homeassistant.const import TIME_HOURS, UnitOfTemperature
  6. from ..const import DEHUMIDIFIER_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.binary_sensor import MultiBinarySensorTests
  9. from ..mixins.lock import BasicLockTests
  10. from ..mixins.number import BasicNumberTests
  11. from ..mixins.sensor import MultiSensorTests
  12. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. HVACMODE_DPS = "1"
  15. PRESET_DPS = "2"
  16. HUMIDITY_DPS = "4"
  17. AIRCLEAN_DPS = "5"
  18. FANMODE_DPS = "6"
  19. LOCK_DPS = "7"
  20. ERROR_DPS = "11"
  21. TIMER_DPS = "12"
  22. UNKNOWN101_DPS = "101"
  23. LIGHTOFF_DPS = "102"
  24. CURRENTTEMP_DPS = "103"
  25. CURRENTHUMID_DPS = "104"
  26. DEFROST_DPS = "105"
  27. PRESET_NORMAL = "0"
  28. PRESET_LOW = "1"
  29. PRESET_HIGH = "2"
  30. PRESET_DRY_CLOTHES = "3"
  31. ERROR_TANK = "Tank full or missing"
  32. class TestGoldairDehumidifier(
  33. BasicLockTests,
  34. BasicNumberTests,
  35. BasicSwitchTests,
  36. MultiBinarySensorTests,
  37. MultiSensorTests,
  38. SwitchableTests,
  39. TuyaDeviceTestCase,
  40. ):
  41. __test__ = True
  42. def setUp(self):
  43. self.setUpForConfig("goldair_dehumidifier.yaml", DEHUMIDIFIER_PAYLOAD)
  44. self.subject = self.entities.get("humidifier")
  45. self.setUpSwitchable(HVACMODE_DPS, self.subject)
  46. self.fan = self.entities.get("fan")
  47. # BasicLightTests mixin is not used here because the switch is inverted
  48. self.light = self.entities.get("light_display")
  49. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  50. self.setUpBasicSwitch(AIRCLEAN_DPS, self.entities.get("switch_air_clean"))
  51. self.setUpBasicNumber(
  52. TIMER_DPS,
  53. self.entities.get("number_timer"),
  54. max=24,
  55. unit=TIME_HOURS,
  56. )
  57. self.setUpMultiSensors(
  58. [
  59. {
  60. "name": "sensor_current_temperature",
  61. "dps": CURRENTTEMP_DPS,
  62. "unit": UnitOfTemperature.CELSIUS,
  63. "device_class": SensorDeviceClass.TEMPERATURE,
  64. "state_class": "measurement",
  65. },
  66. {
  67. "name": "sensor_current_humidity",
  68. "dps": CURRENTHUMID_DPS,
  69. "unit": "%",
  70. "device_class": SensorDeviceClass.HUMIDITY,
  71. "state_class": "measurement",
  72. },
  73. ]
  74. )
  75. self.setUpMultiBinarySensors(
  76. [
  77. {
  78. "name": "binary_sensor_tank",
  79. "dps": ERROR_DPS,
  80. "device_class": BinarySensorDeviceClass.PROBLEM,
  81. "testdata": (8, 0),
  82. },
  83. {
  84. "name": "binary_sensor_defrost",
  85. "dps": DEFROST_DPS,
  86. "device_class": BinarySensorDeviceClass.COLD,
  87. },
  88. ]
  89. )
  90. self.mark_secondary(
  91. [
  92. "light_display",
  93. "lock_child_lock",
  94. "number_timer",
  95. "binary_sensor_tank",
  96. "binary_sensor_defrost",
  97. ],
  98. )
  99. def test_min_target_humidity(self):
  100. self.assertEqual(self.subject.min_humidity, 30)
  101. def test_max_target_humidity(self):
  102. self.assertEqual(self.subject.max_humidity, 80)
  103. def test_target_humidity_in_humidifier(self):
  104. self.dps[PRESET_DPS] = PRESET_NORMAL
  105. self.dps[HUMIDITY_DPS] = 45
  106. self.assertEqual(self.subject.target_humidity, 45)
  107. async def test_set_humidity_in_humidifier_rounds_up_to_5_percent(self):
  108. self.dps[PRESET_DPS] = PRESET_NORMAL
  109. async with assert_device_properties_set(
  110. self.subject._device,
  111. {HUMIDITY_DPS: 45},
  112. ):
  113. await self.subject.async_set_humidity(43)
  114. async def test_set_humidity_in_humidifier_rounds_down_to_5_percent(self):
  115. self.dps[PRESET_DPS] = PRESET_NORMAL
  116. async with assert_device_properties_set(
  117. self.subject._device,
  118. {HUMIDITY_DPS: 40},
  119. ):
  120. await self.subject.async_set_humidity(42)
  121. def test_preset_mode(self):
  122. self.dps[PRESET_DPS] = PRESET_NORMAL
  123. self.assertEqual(self.subject.mode, "Normal")
  124. self.dps[PRESET_DPS] = PRESET_LOW
  125. self.assertEqual(self.subject.mode, "Low")
  126. self.dps[PRESET_DPS] = PRESET_HIGH
  127. self.assertEqual(self.subject.mode, "High")
  128. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  129. self.assertEqual(self.subject.mode, "Dry clothes")
  130. self.dps[PRESET_DPS] = None
  131. self.assertEqual(self.subject.mode, None)
  132. def test_fan_mode_reflects_dps_mode_in_normal_preset(self):
  133. self.dps[PRESET_DPS] = PRESET_NORMAL
  134. self.dps[FANMODE_DPS] = "1"
  135. self.assertEqual(self.fan.percentage, 50)
  136. self.dps[FANMODE_DPS] = "3"
  137. self.assertEqual(self.fan.percentage, 100)
  138. self.dps[FANMODE_DPS] = None
  139. self.assertEqual(self.fan.percentage, None)
  140. async def test_set_fan_50_succeeds_in_normal_preset(self):
  141. self.dps[PRESET_DPS] = PRESET_NORMAL
  142. async with assert_device_properties_set(
  143. self.fan._device,
  144. {FANMODE_DPS: "1"},
  145. ):
  146. await self.fan.async_set_percentage(50)
  147. async def test_set_fan_100_succeeds_in_normal_preset(self):
  148. self.dps[PRESET_DPS] = PRESET_NORMAL
  149. async with assert_device_properties_set(
  150. self.fan._device,
  151. {FANMODE_DPS: "3"},
  152. ):
  153. await self.fan.async_set_percentage(100)
  154. async def test_set_fan_30_snaps_to_50_in_normal_preset(self):
  155. self.dps[PRESET_DPS] = PRESET_NORMAL
  156. async with assert_device_properties_set(
  157. self.fan._device,
  158. {FANMODE_DPS: "1"},
  159. ):
  160. await self.fan.async_set_percentage(30)
  161. def test_light_supported_color_modes(self):
  162. self.assertCountEqual(
  163. self.light.supported_color_modes,
  164. [ColorMode.ONOFF],
  165. )
  166. def test_light_color_mode(self):
  167. self.assertEqual(self.light.color_mode, ColorMode.ONOFF)
  168. def test_light_icon(self):
  169. self.dps[LIGHTOFF_DPS] = False
  170. self.assertEqual(self.light.icon, "mdi:led-on")
  171. self.dps[LIGHTOFF_DPS] = True
  172. self.assertEqual(self.light.icon, "mdi:led-off")
  173. def test_light_is_on(self):
  174. self.dps[LIGHTOFF_DPS] = False
  175. self.assertEqual(self.light.is_on, True)
  176. self.dps[LIGHTOFF_DPS] = True
  177. self.assertEqual(self.light.is_on, False)
  178. def test_light_state_attributes(self):
  179. self.assertEqual(self.light.extra_state_attributes, {})
  180. async def test_light_turn_on(self):
  181. self.dps[LIGHTOFF_DPS] = True
  182. async with assert_device_properties_set(
  183. self.light._device, {LIGHTOFF_DPS: False}
  184. ):
  185. await self.light.async_turn_on()
  186. async def test_light_turn_off(self):
  187. async with assert_device_properties_set(
  188. self.light._device, {LIGHTOFF_DPS: True}
  189. ):
  190. await self.light.async_turn_off()
  191. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  192. self.dps[LIGHTOFF_DPS] = True
  193. async with assert_device_properties_set(
  194. self.light._device, {LIGHTOFF_DPS: False}
  195. ):
  196. await self.light.async_toggle()
  197. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  198. self.dps[LIGHTOFF_DPS] = False
  199. async with assert_device_properties_set(
  200. self.light._device, {LIGHTOFF_DPS: True}
  201. ):
  202. await self.light.async_toggle()
  203. def test_switch_icon(self):
  204. self.assertEqual(self.basicSwitch.icon, "mdi:air-purifier")