test_kogan_kawfhtp_heater.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. SUPPORT_PRESET_MODE,
  5. SUPPORT_TARGET_TEMPERATURE,
  6. )
  7. from homeassistant.const import STATE_UNAVAILABLE, TIME_MINUTES
  8. from ..const import KOGAN_KAWFHTP_HEATER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  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. TEMPERATURE_DPS = "3"
  16. CURRENTTEMP_DPS = "4"
  17. TIMER_DPS = "5"
  18. PRESET_DPS = "7"
  19. LOCK_DPS = "2"
  20. class TestGoldairKoganKAHTPHeater(
  21. BasicLockTests,
  22. BasicNumberTests,
  23. TargetTemperatureTests,
  24. TuyaDeviceTestCase,
  25. ):
  26. __test__ = True
  27. def setUp(self):
  28. self.setUpForConfig("kogan_kawfhtp_heater.yaml", KOGAN_KAWFHTP_HEATER_PAYLOAD)
  29. self.subject = self.entities.get("climate")
  30. self.setUpTargetTemperature(
  31. TEMPERATURE_DPS,
  32. self.subject,
  33. min=5,
  34. max=40,
  35. )
  36. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  37. self.setUpBasicNumber(
  38. TIMER_DPS,
  39. self.entities.get("number_timer"),
  40. max=1440,
  41. unit=TIME_MINUTES,
  42. )
  43. self.mark_secondary(["lock_child_lock", "number_timer"])
  44. def test_supported_features(self):
  45. self.assertEqual(
  46. self.subject.supported_features,
  47. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  48. )
  49. def test_icon(self):
  50. self.dps[HVACMODE_DPS] = True
  51. self.assertEqual(self.subject.icon, "mdi:radiator")
  52. self.dps[HVACMODE_DPS] = False
  53. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  54. def test_temperature_unit_returns_device_temperature_unit(self):
  55. self.assertEqual(
  56. self.subject.temperature_unit, self.subject._device.temperature_unit
  57. )
  58. async def test_legacy_set_temperature_with_preset_mode(self):
  59. async with assert_device_properties_set(
  60. self.subject._device, {PRESET_DPS: "Low"}
  61. ):
  62. await self.subject.async_set_temperature(preset_mode="Low")
  63. async def test_legacy_set_temperature_with_both_properties(self):
  64. async with assert_device_properties_set(
  65. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "High"}
  66. ):
  67. await self.subject.async_set_temperature(temperature=26, preset_mode="High")
  68. def test_current_temperature(self):
  69. self.dps[CURRENTTEMP_DPS] = 25
  70. self.assertEqual(self.subject.current_temperature, 25)
  71. def test_hvac_mode(self):
  72. self.dps[HVACMODE_DPS] = True
  73. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  74. self.dps[HVACMODE_DPS] = False
  75. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  76. self.dps[HVACMODE_DPS] = None
  77. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  78. def test_hvac_modes(self):
  79. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  80. async def test_turn_on(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {HVACMODE_DPS: True}
  83. ):
  84. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  85. async def test_turn_off(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {HVACMODE_DPS: False}
  88. ):
  89. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  90. def test_preset_mode(self):
  91. self.dps[PRESET_DPS] = "Low"
  92. self.assertEqual(self.subject.preset_mode, "Low")
  93. self.dps[PRESET_DPS] = "High"
  94. self.assertEqual(self.subject.preset_mode, "High")
  95. self.dps[PRESET_DPS] = None
  96. self.assertIs(self.subject.preset_mode, None)
  97. def test_preset_modes(self):
  98. self.assertCountEqual(self.subject.preset_modes, ["Low", "High"])
  99. async def test_set_preset_mode_to_low(self):
  100. async with assert_device_properties_set(
  101. self.subject._device,
  102. {PRESET_DPS: "Low"},
  103. ):
  104. await self.subject.async_set_preset_mode("Low")
  105. async def test_set_preset_mode_to_high(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {PRESET_DPS: "High"},
  109. ):
  110. await self.subject.async_set_preset_mode("High")
  111. def test_extra_state_attributes(self):
  112. self.dps[TIMER_DPS] = 10
  113. self.assertDictEqual(self.subject.extra_state_attributes, {"timer": 10})