test_goldair_gpcv_heater.py 5.3 KB

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