test_goldair_geco_heater.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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, TIME_HOURS
  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(
  40. TIMER_DPS,
  41. self.entities.get("number_timer"),
  42. max=24,
  43. unit=TIME_HOURS,
  44. )
  45. self.setUpBasicBinarySensor(
  46. ERROR_DPS,
  47. self.entities.get("binary_sensor_error"),
  48. device_class=DEVICE_CLASS_PROBLEM,
  49. testdata=(1, 0),
  50. )
  51. self.mark_secondary(
  52. [
  53. "lock_child_lock",
  54. "number_timer",
  55. "binary_sensor_error",
  56. ]
  57. )
  58. def test_supported_features(self):
  59. self.assertEqual(
  60. self.subject.supported_features,
  61. SUPPORT_TARGET_TEMPERATURE,
  62. )
  63. def test_icon(self):
  64. self.dps[HVACMODE_DPS] = True
  65. self.assertEqual(self.subject.icon, "mdi:radiator")
  66. self.dps[HVACMODE_DPS] = False
  67. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  68. def test_temperature_unit_returns_device_temperature_unit(self):
  69. self.assertEqual(
  70. self.subject.temperature_unit, self.subject._device.temperature_unit
  71. )
  72. def test_current_temperature(self):
  73. self.dps[CURRENTTEMP_DPS] = 25
  74. self.assertEqual(self.subject.current_temperature, 25)
  75. def test_hvac_mode(self):
  76. self.dps[HVACMODE_DPS] = True
  77. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  78. self.dps[HVACMODE_DPS] = False
  79. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  80. self.dps[HVACMODE_DPS] = None
  81. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  82. def test_hvac_modes(self):
  83. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  84. async def test_turn_on(self):
  85. async with assert_device_properties_set(
  86. self.subject._device, {HVACMODE_DPS: True}
  87. ):
  88. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  89. async def test_turn_off(self):
  90. async with assert_device_properties_set(
  91. self.subject._device, {HVACMODE_DPS: False}
  92. ):
  93. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  94. def test_extra_state_attributes(self):
  95. # There are currently no known error states; update this as
  96. # they are discovered
  97. self.dps[ERROR_DPS] = "something"
  98. self.dps[TIMER_DPS] = 10
  99. self.assertDictEqual(
  100. self.subject.extra_state_attributes,
  101. {"error": "something", "timer": 10},
  102. )
  103. self.dps[ERROR_DPS] = "0"
  104. self.dps[TIMER_DPS] = 0
  105. self.assertDictEqual(
  106. self.subject.extra_state_attributes, {"error": "OK", "timer": 0}
  107. )