test_eurom_600_heater.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  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 EUROM_600_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 .base_device_tests import TuyaDeviceTestCase
  13. HVACMODE_DPS = "1"
  14. TEMPERATURE_DPS = "2"
  15. CURRENTTEMP_DPS = "5"
  16. ERROR_DPS = "6"
  17. class TestEurom600Heater(
  18. BasicBinarySensorTests, TargetTemperatureTests, TuyaDeviceTestCase
  19. ):
  20. __test__ = True
  21. def setUp(self):
  22. self.setUpForConfig("eurom_600_heater.yaml", EUROM_600_HEATER_PAYLOAD)
  23. self.subject = self.entities.get("climate")
  24. self.setUpTargetTemperature(
  25. TEMPERATURE_DPS,
  26. self.subject,
  27. min=0,
  28. max=37,
  29. )
  30. self.setUpBasicBinarySensor(
  31. ERROR_DPS,
  32. self.entities.get("binary_sensor_error"),
  33. device_class=BinarySensorDeviceClass.PROBLEM,
  34. testdata=(1, 0),
  35. )
  36. self.mark_secondary(["binary_sensor_error"])
  37. def test_supported_features(self):
  38. self.assertEqual(
  39. self.subject.supported_features,
  40. SUPPORT_TARGET_TEMPERATURE,
  41. )
  42. def test_icon(self):
  43. self.dps[HVACMODE_DPS] = True
  44. self.assertEqual(self.subject.icon, "mdi:radiator")
  45. self.dps[HVACMODE_DPS] = False
  46. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  47. def test_temperature_unit_returns_device_temperature_unit(self):
  48. self.assertEqual(
  49. self.subject.temperature_unit, self.subject._device.temperature_unit
  50. )
  51. def test_current_temperature(self):
  52. self.dps[CURRENTTEMP_DPS] = 25
  53. self.assertEqual(self.subject.current_temperature, 25)
  54. def test_hvac_mode(self):
  55. self.dps[HVACMODE_DPS] = True
  56. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  57. self.dps[HVACMODE_DPS] = False
  58. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  59. self.dps[HVACMODE_DPS] = None
  60. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  61. def test_hvac_modes(self):
  62. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  63. async def test_turn_on(self):
  64. async with assert_device_properties_set(
  65. self.subject._device, {HVACMODE_DPS: True}
  66. ):
  67. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  68. async def test_turn_off(self):
  69. async with assert_device_properties_set(
  70. self.subject._device, {HVACMODE_DPS: False}
  71. ):
  72. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  73. def test_error_state(self):
  74. # There are currently no known error states; update this as
  75. # they are discovered
  76. self.dps[ERROR_DPS] = "something"
  77. self.assertEqual(self.subject.extra_state_attributes, {"error": "something"})
  78. self.dps[ERROR_DPS] = "0"
  79. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})