test_andersson_gsh_heater.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from ..const import GSH_HEATER_PAYLOAD
  6. from ..helpers import assert_device_properties_set
  7. from ..mixins.climate import TargetTemperatureTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. HVACMODE_DPS = "1"
  10. TEMPERATURE_DPS = "2"
  11. CURRENTTEMP_DPS = "3"
  12. PRESET_DPS = "4"
  13. ERROR_DPS = "12"
  14. class TestAnderssonGSHHeater(TargetTemperatureTests, TuyaDeviceTestCase):
  15. __test__ = True
  16. def setUp(self):
  17. self.setUpForConfig("andersson_gsh_heater.yaml", GSH_HEATER_PAYLOAD)
  18. self.subject = self.entities["climate"]
  19. self.setUpTargetTemperature(
  20. TEMPERATURE_DPS,
  21. self.subject,
  22. min=5,
  23. max=35,
  24. )
  25. def test_supported_features(self):
  26. self.assertEqual(
  27. self.subject.supported_features,
  28. (
  29. ClimateEntityFeature.TARGET_TEMPERATURE
  30. | ClimateEntityFeature.PRESET_MODE
  31. ),
  32. )
  33. def test_icon(self):
  34. self.dps[HVACMODE_DPS] = True
  35. self.assertEqual(self.subject.icon, "mdi:radiator")
  36. self.dps[HVACMODE_DPS] = False
  37. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  38. def test_temperature_unit_returns_device_temperature_unit(self):
  39. self.assertEqual(
  40. self.subject.temperature_unit, self.subject._device.temperature_unit
  41. )
  42. async def test_legacy_set_temperature_with_preset_mode(self):
  43. async with assert_device_properties_set(
  44. self.subject._device, {PRESET_DPS: "low"}
  45. ):
  46. await self.subject.async_set_temperature(preset_mode="Low")
  47. async def test_legacy_set_temperature_with_both_properties(self):
  48. async with assert_device_properties_set(
  49. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "high"}
  50. ):
  51. await self.subject.async_set_temperature(temperature=26, preset_mode="High")
  52. def test_current_temperature(self):
  53. self.dps[CURRENTTEMP_DPS] = 25
  54. self.assertEqual(self.subject.current_temperature, 25)
  55. def test_hvac_mode(self):
  56. self.dps[HVACMODE_DPS] = True
  57. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  58. self.dps[HVACMODE_DPS] = False
  59. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  60. def test_hvac_modes(self):
  61. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  62. async def test_turn_on(self):
  63. async with assert_device_properties_set(
  64. self.subject._device, {HVACMODE_DPS: True}
  65. ):
  66. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  67. async def test_turn_off(self):
  68. async with assert_device_properties_set(
  69. self.subject._device, {HVACMODE_DPS: False}
  70. ):
  71. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  72. def test_preset_mode(self):
  73. self.dps[PRESET_DPS] = "low"
  74. self.assertEqual(self.subject.preset_mode, "Low")
  75. self.dps[PRESET_DPS] = "high"
  76. self.assertEqual(self.subject.preset_mode, "High")
  77. self.dps[PRESET_DPS] = "af"
  78. self.assertEqual(self.subject.preset_mode, "Anti-freeze")
  79. self.dps[PRESET_DPS] = None
  80. self.assertIs(self.subject.preset_mode, None)
  81. def test_preset_modes(self):
  82. self.assertCountEqual(self.subject.preset_modes, ["Low", "High", "Anti-freeze"])
  83. async def test_set_preset_mode_to_low(self):
  84. async with assert_device_properties_set(
  85. self.subject._device,
  86. {PRESET_DPS: "low"},
  87. ):
  88. await self.subject.async_set_preset_mode("Low")
  89. async def test_set_preset_mode_to_high(self):
  90. async with assert_device_properties_set(
  91. self.subject._device,
  92. {PRESET_DPS: "high"},
  93. ):
  94. await self.subject.async_set_preset_mode("High")
  95. async def test_set_preset_mode_to_af(self):
  96. async with assert_device_properties_set(
  97. self.subject._device,
  98. {PRESET_DPS: "af"},
  99. ):
  100. await self.subject.async_set_preset_mode("Anti-freeze")
  101. def test_error_state(self):
  102. # There are currently no known error states; update this as
  103. # they are discovered
  104. self.dps[ERROR_DPS] = "something"
  105. self.assertEqual(self.subject.extra_state_attributes, {"error": "something"})
  106. self.dps[ERROR_DPS] = "0"
  107. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})