test_goldair_geco_heater.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_problem"),
  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_problem",
  52. ]
  53. )
  54. def test_supported_features(self):
  55. self.assertEqual(
  56. self.subject.supported_features,
  57. ClimateEntityFeature.TARGET_TEMPERATURE
  58. | ClimateEntityFeature.TURN_OFF
  59. | ClimateEntityFeature.TURN_ON,
  60. )
  61. def test_temperature_unit_returns_celsius(self):
  62. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  63. def test_current_temperature(self):
  64. self.dps[CURRENTTEMP_DPS] = 25
  65. self.assertEqual(self.subject.current_temperature, 25)
  66. def test_hvac_mode(self):
  67. self.dps[HVACMODE_DPS] = True
  68. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  69. self.dps[HVACMODE_DPS] = False
  70. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  71. def test_hvac_modes(self):
  72. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  73. async def test_turn_on(self):
  74. async with assert_device_properties_set(
  75. self.subject._device, {HVACMODE_DPS: True}
  76. ):
  77. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  78. async def test_turn_off(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {HVACMODE_DPS: False}
  81. ):
  82. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  83. def test_extra_state_attributes(self):
  84. # There are currently no known error states; update this as
  85. # they are discovered
  86. self.dps[ERROR_DPS] = "something"
  87. self.dps[TIMER_DPS] = 10
  88. self.assertDictEqual(
  89. self.subject.extra_state_attributes,
  90. {"error": "something", "timer": 10},
  91. )
  92. self.dps[ERROR_DPS] = "0"
  93. self.dps[TIMER_DPS] = 0
  94. self.assertDictEqual(
  95. self.subject.extra_state_attributes, {"error": "OK", "timer": 0}
  96. )