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