test_goldair_gpcv_heater.py 5.2 KB

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