test_goldair_geco_heater.py 3.8 KB

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