test_goldair_gpcv_heater.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
  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
  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(TIMER_DPS, self.entities.get("number_timer"), max=24)
  42. self.setUpBasicBinarySensor(
  43. ERROR_DPS,
  44. self.entities.get("binary_sensor_error"),
  45. device_class=DEVICE_CLASS_PROBLEM,
  46. testdata=(1, 0),
  47. )
  48. self.mark_secondary(
  49. ["lock_child_lock", "number_timer", "binary_sensor_error"],
  50. )
  51. def test_supported_features(self):
  52. self.assertEqual(
  53. self.subject.supported_features,
  54. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  55. )
  56. def test_icon(self):
  57. self.dps[HVACMODE_DPS] = True
  58. self.assertEqual(self.subject.icon, "mdi:radiator")
  59. self.dps[HVACMODE_DPS] = False
  60. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  61. def test_temperature_unit_returns_device_temperature_unit(self):
  62. self.assertEqual(
  63. self.subject.temperature_unit, self.subject._device.temperature_unit
  64. )
  65. async def test_legacy_set_temperature_with_preset_mode(self):
  66. async with assert_device_properties_set(
  67. self.subject._device, {PRESET_DPS: "Low"}
  68. ):
  69. await self.subject.async_set_temperature(preset_mode="Low")
  70. async def test_legacy_set_temperature_with_both_properties(self):
  71. async with assert_device_properties_set(
  72. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "High"}
  73. ):
  74. await self.subject.async_set_temperature(temperature=26, preset_mode="High")
  75. def test_current_temperature(self):
  76. self.dps[CURRENTTEMP_DPS] = 25
  77. self.assertEqual(self.subject.current_temperature, 25)
  78. def test_hvac_mode(self):
  79. self.dps[HVACMODE_DPS] = True
  80. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  81. self.dps[HVACMODE_DPS] = False
  82. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  83. self.dps[HVACMODE_DPS] = None
  84. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  85. def test_hvac_modes(self):
  86. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  87. async def test_turn_on(self):
  88. async with assert_device_properties_set(
  89. self.subject._device, {HVACMODE_DPS: True}
  90. ):
  91. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  92. async def test_turn_off(self):
  93. async with assert_device_properties_set(
  94. self.subject._device, {HVACMODE_DPS: False}
  95. ):
  96. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  97. def test_preset_mode(self):
  98. self.dps[PRESET_DPS] = "Low"
  99. self.assertEqual(self.subject.preset_mode, "Low")
  100. self.dps[PRESET_DPS] = "High"
  101. self.assertEqual(self.subject.preset_mode, "High")
  102. self.dps[PRESET_DPS] = None
  103. self.assertIs(self.subject.preset_mode, None)
  104. def test_preset_modes(self):
  105. self.assertCountEqual(self.subject.preset_modes, ["Low", "High"])
  106. async def test_set_preset_mode_to_low(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {PRESET_DPS: "Low"},
  110. ):
  111. await self.subject.async_set_preset_mode("Low")
  112. async def test_set_preset_mode_to_high(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {PRESET_DPS: "High"},
  116. ):
  117. await self.subject.async_set_preset_mode("High")
  118. def test_extra_state_attributes(self):
  119. # There are currently no known error states; update this as
  120. # they are discovered
  121. self.dps[ERROR_DPS] = "something"
  122. self.dps[TIMER_DPS] = 10
  123. self.assertDictEqual(
  124. self.subject.extra_state_attributes,
  125. {"error": "something", "timer": 10},
  126. )
  127. self.dps[ERROR_DPS] = "0"
  128. self.dps[TIMER_DPS] = 0
  129. self.assertDictEqual(
  130. self.subject.extra_state_attributes, {"error": "OK", "timer": 0}
  131. )