test_kogan_kashmfp20ba_heater.py 6.9 KB

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