test_kogan_kashmfp20ba_heater.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.components.light import (
  6. ColorMode,
  7. LightEntityFeature,
  8. )
  9. from homeassistant.const import UnitOfTemperature
  10. from ..const import KOGAN_KASHMFP20BA_HEATER_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from ..mixins.climate import TargetTemperatureTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. HVACMODE_DPS = "1"
  15. PRESET_DPS = "2"
  16. TEMPERATURE_DPS = "3"
  17. CURRENTTEMP_DPS = "4"
  18. BACKLIGHT_DPS = "5"
  19. FLAME_DPS = "6"
  20. class TestKoganKASHMF20BAHeater(TargetTemperatureTests, TuyaDeviceTestCase):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig(
  24. "kogan_kashmfp20ba_heater.yaml", KOGAN_KASHMFP20BA_HEATER_PAYLOAD
  25. )
  26. self.subject = self.entities.get("climate")
  27. self.setUpTargetTemperature(
  28. TEMPERATURE_DPS,
  29. self.subject,
  30. min=10,
  31. max=30,
  32. )
  33. self.backlight = self.entities.get("light_backlight")
  34. self.flame = self.entities.get("light_flame")
  35. def test_supported_features(self):
  36. self.assertEqual(
  37. self.subject.supported_features,
  38. ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE,
  39. )
  40. def test_icon(self):
  41. self.dps[HVACMODE_DPS] = True
  42. self.assertEqual(self.subject.icon, "mdi:radiator")
  43. self.dps[HVACMODE_DPS] = False
  44. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  45. def test_temperature_unit_returns_celsius(self):
  46. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  47. async def test_legacy_set_temperature_with_preset_mode(self):
  48. async with assert_device_properties_set(
  49. self.subject._device, {PRESET_DPS: "Low"}
  50. ):
  51. await self.subject.async_set_temperature(preset_mode="Low")
  52. async def test_legacy_set_temperature_with_both_properties(self):
  53. async with assert_device_properties_set(
  54. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "High"}
  55. ):
  56. await self.subject.async_set_temperature(temperature=26, preset_mode="High")
  57. def test_current_temperature(self):
  58. self.dps[CURRENTTEMP_DPS] = 25
  59. self.assertEqual(self.subject.current_temperature, 25)
  60. def test_hvac_mode(self):
  61. self.dps[HVACMODE_DPS] = True
  62. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  63. self.dps[HVACMODE_DPS] = False
  64. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  65. def test_hvac_modes(self):
  66. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  67. async def test_turn_on(self):
  68. async with assert_device_properties_set(
  69. self.subject._device, {HVACMODE_DPS: True}
  70. ):
  71. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  72. async def test_turn_off(self):
  73. async with assert_device_properties_set(
  74. self.subject._device, {HVACMODE_DPS: False}
  75. ):
  76. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  77. def test_preset_mode(self):
  78. self.dps[PRESET_DPS] = "low"
  79. self.assertEqual(self.subject.preset_mode, "low")
  80. self.dps[PRESET_DPS] = "high"
  81. self.assertEqual(self.subject.preset_mode, "high")
  82. self.dps[PRESET_DPS] = None
  83. self.assertIs(self.subject.preset_mode, None)
  84. def test_preset_modes(self):
  85. self.assertCountEqual(self.subject.preset_modes, ["low", "high"])
  86. async def test_set_preset_mode_to_low(self):
  87. async with assert_device_properties_set(
  88. self.subject._device,
  89. {PRESET_DPS: "low"},
  90. ):
  91. await self.subject.async_set_preset_mode("low")
  92. async def test_set_preset_mode_to_high(self):
  93. async with assert_device_properties_set(
  94. self.subject._device,
  95. {PRESET_DPS: "high"},
  96. ):
  97. await self.subject.async_set_preset_mode("high")
  98. def test_extra_state_attributes(self):
  99. self.assertEqual(self.subject.extra_state_attributes, {})
  100. self.assertEqual(self.backlight.extra_state_attributes, {})
  101. self.assertEqual(self.flame.extra_state_attributes, {})
  102. def test_lighting_supported_color_modes(self):
  103. self.assertCountEqual(self.backlight.supported_color_modes, [])
  104. self.assertCountEqual(self.flame.supported_color_modes, [])
  105. def test_lighting_supported_features(self):
  106. self.assertEqual(self.backlight.supported_features, LightEntityFeature.EFFECT)
  107. self.assertEqual(self.flame.supported_features, LightEntityFeature.EFFECT)
  108. def test_lighting_color_mode(self):
  109. self.assertEqual(self.backlight.color_mode, ColorMode.UNKNOWN)
  110. self.assertEqual(self.flame.color_mode, ColorMode.UNKNOWN)
  111. def test_lighting_is_on(self):
  112. self.assertTrue(self.backlight.is_on)
  113. self.assertTrue(self.flame.is_on)
  114. def test_lighting_brightness(self):
  115. self.assertIsNone(self.backlight.brightness)
  116. self.assertIsNone(self.flame.brightness)
  117. def test_backlight_effect_list(self):
  118. self.assertCountEqual(
  119. self.backlight.effect_list,
  120. [
  121. "white",
  122. "blue",
  123. "orange",
  124. "whiteblue",
  125. "whiteorange",
  126. "blueorange",
  127. ],
  128. )
  129. def test_flame_effect_list(self):
  130. self.assertCountEqual(
  131. self.flame.effect_list,
  132. [
  133. "orange",
  134. "red",
  135. "green",
  136. "blue",
  137. "redgreen",
  138. "redblue",
  139. "bluegreen",
  140. "redorange",
  141. "greenorange",
  142. "blueorange",
  143. ],
  144. )
  145. def test_backlight_effect(self):
  146. self.dps[BACKLIGHT_DPS] = "orange"
  147. self.assertEqual(self.backlight.effect, "orange")
  148. def test_flame_effect(self):
  149. self.dps[FLAME_DPS] = "bluegreen"
  150. self.assertEqual(self.flame.effect, "bluegreen")
  151. async def test_set_backlight_effect(self):
  152. async with assert_device_properties_set(
  153. self.backlight._device,
  154. {BACKLIGHT_DPS: "whiteblue"},
  155. ):
  156. await self.backlight.async_turn_on(effect="whiteblue")
  157. async def test_set_flame_effect(self):
  158. async with assert_device_properties_set(
  159. self.flame._device,
  160. {FLAME_DPS: "red"},
  161. ):
  162. await self.flame.async_turn_on(effect="red")