test_goldair_geco_heater.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
  2. from homeassistant.components.climate.const import (
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. SUPPORT_TARGET_TEMPERATURE,
  6. )
  7. from homeassistant.const import STATE_UNAVAILABLE
  8. from ..const import GECO_HEATER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.binary_sensor import BasicBinarySensorTests
  11. from ..mixins.climate import TargetTemperatureTests
  12. from ..mixins.lock import BasicLockTests
  13. from ..mixins.number import BasicNumberTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. HVACMODE_DPS = "1"
  16. LOCK_DPS = "2"
  17. TEMPERATURE_DPS = "3"
  18. CURRENTTEMP_DPS = "4"
  19. TIMER_DPS = "5"
  20. ERROR_DPS = "6"
  21. class TestGoldairGECOHeater(
  22. BasicBinarySensorTests,
  23. BasicLockTests,
  24. BasicNumberTests,
  25. TargetTemperatureTests,
  26. TuyaDeviceTestCase,
  27. ):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("goldair_geco_heater.yaml", GECO_HEATER_PAYLOAD)
  31. self.subject = self.entities.get("climate")
  32. self.setUpTargetTemperature(
  33. TEMPERATURE_DPS,
  34. self.subject,
  35. min=15,
  36. max=35,
  37. )
  38. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  39. self.setUpBasicNumber(TIMER_DPS, self.entities.get("number_timer"), max=24)
  40. self.setUpBasicBinarySensor(
  41. ERROR_DPS,
  42. self.entities.get("binary_sensor_error"),
  43. device_class=DEVICE_CLASS_PROBLEM,
  44. testdata=(1, 0),
  45. )
  46. def test_supported_features(self):
  47. self.assertEqual(
  48. self.subject.supported_features,
  49. SUPPORT_TARGET_TEMPERATURE,
  50. )
  51. def test_icon(self):
  52. self.dps[HVACMODE_DPS] = True
  53. self.assertEqual(self.subject.icon, "mdi:radiator")
  54. self.dps[HVACMODE_DPS] = False
  55. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  56. def test_temperature_unit_returns_device_temperature_unit(self):
  57. self.assertEqual(
  58. self.subject.temperature_unit, self.subject._device.temperature_unit
  59. )
  60. def test_current_temperature(self):
  61. self.dps[CURRENTTEMP_DPS] = 25
  62. self.assertEqual(self.subject.current_temperature, 25)
  63. def test_hvac_mode(self):
  64. self.dps[HVACMODE_DPS] = True
  65. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  66. self.dps[HVACMODE_DPS] = False
  67. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  68. self.dps[HVACMODE_DPS] = None
  69. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  70. def test_hvac_modes(self):
  71. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  72. async def test_turn_on(self):
  73. async with assert_device_properties_set(
  74. self.subject._device, {HVACMODE_DPS: True}
  75. ):
  76. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  77. async def test_turn_off(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {HVACMODE_DPS: False}
  80. ):
  81. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  82. def test_state_attributes(self):
  83. # There are currently no known error states; update this as
  84. # they are discovered
  85. self.dps[ERROR_DPS] = "something"
  86. self.dps[TIMER_DPS] = 10
  87. self.assertDictEqual(
  88. self.subject.device_state_attributes,
  89. {"error": "something", "timer": 10},
  90. )
  91. self.dps[ERROR_DPS] = "0"
  92. self.dps[TIMER_DPS] = 0
  93. self.assertDictEqual(
  94. self.subject.device_state_attributes, {"error": "OK", "timer": 0}
  95. )