test_andersson_gsh_heater.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.const import STATE_UNAVAILABLE
  8. from ..const import GSH_HEATER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.climate import TargetTemperatureTests
  11. from .base_device_tests import TuyaDeviceTestCase
  12. HVACMODE_DPS = "1"
  13. TEMPERATURE_DPS = "2"
  14. CURRENTTEMP_DPS = "3"
  15. PRESET_DPS = "4"
  16. ERROR_DPS = "12"
  17. class TestAnderssonGSHHeater(TargetTemperatureTests, TuyaDeviceTestCase):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig("andersson_gsh_heater.yaml", GSH_HEATER_PAYLOAD)
  21. self.subject = self.entities["climate"]
  22. self.setUpTargetTemperature(
  23. TEMPERATURE_DPS,
  24. self.subject,
  25. min=5,
  26. max=35,
  27. )
  28. def test_supported_features(self):
  29. self.assertEqual(
  30. self.subject.supported_features,
  31. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  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, HVAC_MODE_HEAT)
  58. self.dps[HVACMODE_DPS] = False
  59. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  60. self.dps[HVACMODE_DPS] = None
  61. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  62. def test_hvac_modes(self):
  63. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  64. async def test_turn_on(self):
  65. async with assert_device_properties_set(
  66. self.subject._device, {HVACMODE_DPS: True}
  67. ):
  68. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  69. async def test_turn_off(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {HVACMODE_DPS: False}
  72. ):
  73. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  74. def test_preset_mode(self):
  75. self.dps[PRESET_DPS] = "low"
  76. self.assertEqual(self.subject.preset_mode, "Low")
  77. self.dps[PRESET_DPS] = "high"
  78. self.assertEqual(self.subject.preset_mode, "High")
  79. self.dps[PRESET_DPS] = "af"
  80. self.assertEqual(self.subject.preset_mode, "Anti-freeze")
  81. self.dps[PRESET_DPS] = None
  82. self.assertIs(self.subject.preset_mode, None)
  83. def test_preset_modes(self):
  84. self.assertCountEqual(self.subject.preset_modes, ["Low", "High", "Anti-freeze"])
  85. async def test_set_preset_mode_to_low(self):
  86. async with assert_device_properties_set(
  87. self.subject._device,
  88. {PRESET_DPS: "low"},
  89. ):
  90. await self.subject.async_set_preset_mode("Low")
  91. async def test_set_preset_mode_to_high(self):
  92. async with assert_device_properties_set(
  93. self.subject._device,
  94. {PRESET_DPS: "high"},
  95. ):
  96. await self.subject.async_set_preset_mode("High")
  97. async def test_set_preset_mode_to_af(self):
  98. async with assert_device_properties_set(
  99. self.subject._device,
  100. {PRESET_DPS: "af"},
  101. ):
  102. await self.subject.async_set_preset_mode("Anti-freeze")
  103. def test_error_state(self):
  104. # There are currently no known error states; update this as
  105. # they are discovered
  106. self.dps[ERROR_DPS] = "something"
  107. self.assertEqual(self.subject.extra_state_attributes, {"error": "something"})
  108. self.dps[ERROR_DPS] = "0"
  109. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})