test_kogan_kawfhtp_heater.py 4.5 KB

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