test_goldair_gpcv_heater.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import (
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. SUPPORT_PRESET_MODE,
  6. SUPPORT_TARGET_TEMPERATURE,
  7. )
  8. from homeassistant.const import STATE_UNAVAILABLE, TIME_HOURS
  9. from ..const import GPCV_HEATER_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.binary_sensor import BasicBinarySensorTests
  12. from ..mixins.climate import TargetTemperatureTests
  13. from ..mixins.lock import BasicLockTests
  14. from ..mixins.number import BasicNumberTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. HVACMODE_DPS = "1"
  17. LOCK_DPS = "2"
  18. TEMPERATURE_DPS = "3"
  19. CURRENTTEMP_DPS = "4"
  20. TIMER_DPS = "5"
  21. ERROR_DPS = "6"
  22. PRESET_DPS = "7"
  23. class TestGoldairGPCVHeater(
  24. BasicBinarySensorTests,
  25. BasicLockTests,
  26. BasicNumberTests,
  27. TargetTemperatureTests,
  28. TuyaDeviceTestCase,
  29. ):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("goldair_gpcv_heater.yaml", GPCV_HEATER_PAYLOAD)
  33. self.subject = self.entities.get("climate")
  34. self.setUpTargetTemperature(
  35. TEMPERATURE_DPS,
  36. self.subject,
  37. min=15,
  38. max=35,
  39. )
  40. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  41. self.setUpBasicNumber(
  42. TIMER_DPS,
  43. self.entities.get("number_timer"),
  44. max=24,
  45. unit=TIME_HOURS,
  46. )
  47. self.setUpBasicBinarySensor(
  48. ERROR_DPS,
  49. self.entities.get("binary_sensor_error"),
  50. device_class=BinarySensorDeviceClass.PROBLEM,
  51. testdata=(1, 0),
  52. )
  53. self.mark_secondary(
  54. ["lock_child_lock", "number_timer", "binary_sensor_error"],
  55. )
  56. def test_supported_features(self):
  57. self.assertEqual(
  58. self.subject.supported_features,
  59. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  60. )
  61. def test_icon(self):
  62. self.dps[HVACMODE_DPS] = True
  63. self.assertEqual(self.subject.icon, "mdi:radiator")
  64. self.dps[HVACMODE_DPS] = False
  65. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  66. def test_temperature_unit_returns_device_temperature_unit(self):
  67. self.assertEqual(
  68. self.subject.temperature_unit, self.subject._device.temperature_unit
  69. )
  70. async def test_legacy_set_temperature_with_preset_mode(self):
  71. async with assert_device_properties_set(
  72. self.subject._device, {PRESET_DPS: "Low"}
  73. ):
  74. await self.subject.async_set_temperature(preset_mode="Low")
  75. async def test_legacy_set_temperature_with_both_properties(self):
  76. async with assert_device_properties_set(
  77. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "High"}
  78. ):
  79. await self.subject.async_set_temperature(temperature=26, preset_mode="High")
  80. def test_current_temperature(self):
  81. self.dps[CURRENTTEMP_DPS] = 25
  82. self.assertEqual(self.subject.current_temperature, 25)
  83. def test_hvac_mode(self):
  84. self.dps[HVACMODE_DPS] = True
  85. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  86. self.dps[HVACMODE_DPS] = False
  87. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  88. self.dps[HVACMODE_DPS] = None
  89. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  90. def test_hvac_modes(self):
  91. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  92. async def test_turn_on(self):
  93. async with assert_device_properties_set(
  94. self.subject._device, {HVACMODE_DPS: True}
  95. ):
  96. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  97. async def test_turn_off(self):
  98. async with assert_device_properties_set(
  99. self.subject._device, {HVACMODE_DPS: False}
  100. ):
  101. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  102. def test_preset_mode(self):
  103. self.dps[PRESET_DPS] = "Low"
  104. self.assertEqual(self.subject.preset_mode, "Low")
  105. self.dps[PRESET_DPS] = "High"
  106. self.assertEqual(self.subject.preset_mode, "High")
  107. self.dps[PRESET_DPS] = None
  108. self.assertIs(self.subject.preset_mode, None)
  109. def test_preset_modes(self):
  110. self.assertCountEqual(self.subject.preset_modes, ["Low", "High"])
  111. async def test_set_preset_mode_to_low(self):
  112. async with assert_device_properties_set(
  113. self.subject._device,
  114. {PRESET_DPS: "Low"},
  115. ):
  116. await self.subject.async_set_preset_mode("Low")
  117. async def test_set_preset_mode_to_high(self):
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {PRESET_DPS: "High"},
  121. ):
  122. await self.subject.async_set_preset_mode("High")
  123. def test_extra_state_attributes(self):
  124. # There are currently no known error states; update this as
  125. # they are discovered
  126. self.dps[ERROR_DPS] = "something"
  127. self.dps[TIMER_DPS] = 10
  128. self.assertDictEqual(
  129. self.subject.extra_state_attributes,
  130. {"error": "something", "timer": 10},
  131. )
  132. self.dps[ERROR_DPS] = "0"
  133. self.dps[TIMER_DPS] = 0
  134. self.assertDictEqual(
  135. self.subject.extra_state_attributes, {"error": "OK", "timer": 0}
  136. )