test_goldair_gpcv_heater.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 UnitOfTime, UnitOfTemperature
  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=UnitOfTime.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_celsius(self):
  68. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  69. async def test_legacy_set_temperature_with_preset_mode(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {PRESET_DPS: "Low"}
  72. ):
  73. await self.subject.async_set_temperature(preset_mode="Low")
  74. async def test_legacy_set_temperature_with_both_properties(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "High"}
  77. ):
  78. await self.subject.async_set_temperature(temperature=26, preset_mode="High")
  79. def test_current_temperature(self):
  80. self.dps[CURRENTTEMP_DPS] = 25
  81. self.assertEqual(self.subject.current_temperature, 25)
  82. def test_hvac_mode(self):
  83. self.dps[HVACMODE_DPS] = True
  84. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  85. self.dps[HVACMODE_DPS] = False
  86. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  87. def test_hvac_modes(self):
  88. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  89. async def test_turn_on(self):
  90. async with assert_device_properties_set(
  91. self.subject._device, {HVACMODE_DPS: True}
  92. ):
  93. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  94. async def test_turn_off(self):
  95. async with assert_device_properties_set(
  96. self.subject._device, {HVACMODE_DPS: False}
  97. ):
  98. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  99. def test_preset_mode(self):
  100. self.dps[PRESET_DPS] = "Low"
  101. self.assertEqual(self.subject.preset_mode, "Low")
  102. self.dps[PRESET_DPS] = "High"
  103. self.assertEqual(self.subject.preset_mode, "High")
  104. self.dps[PRESET_DPS] = None
  105. self.assertIs(self.subject.preset_mode, None)
  106. def test_preset_modes(self):
  107. self.assertCountEqual(self.subject.preset_modes, ["Low", "High"])
  108. async def test_set_preset_mode_to_low(self):
  109. async with assert_device_properties_set(
  110. self.subject._device,
  111. {PRESET_DPS: "Low"},
  112. ):
  113. await self.subject.async_set_preset_mode("Low")
  114. async def test_set_preset_mode_to_high(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {PRESET_DPS: "High"},
  118. ):
  119. await self.subject.async_set_preset_mode("High")
  120. def test_extra_state_attributes(self):
  121. # There are currently no known error states; update this as
  122. # they are discovered
  123. self.dps[ERROR_DPS] = "something"
  124. self.dps[TIMER_DPS] = 10
  125. self.assertDictEqual(
  126. self.subject.extra_state_attributes,
  127. {"error": "something", "timer": 10},
  128. )
  129. self.dps[ERROR_DPS] = "0"
  130. self.dps[TIMER_DPS] = 0
  131. self.assertDictEqual(
  132. self.subject.extra_state_attributes, {"error": "OK", "timer": 0}
  133. )