test_goldair_geco_heater.py 3.8 KB

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