4
0

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