test_kogan_kashmfp20ba_heater.py 6.7 KB

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