test_eurom_601_heater.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import (
  3. ClimateEntityFeature,
  4. HVACMode,
  5. PRESET_COMFORT,
  6. PRESET_ECO,
  7. )
  8. from ..const import EUROM_601_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 = "3"
  16. PRESET_DPS = "6"
  17. ERROR_DPS = "13"
  18. class TestEurom601Heater(
  19. BasicBinarySensorTests, TargetTemperatureTests, TuyaDeviceTestCase
  20. ):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig("eurom_601_heater.yaml", EUROM_601_HEATER_PAYLOAD)
  24. self.subject = self.entities.get("climate")
  25. self.setUpTargetTemperature(
  26. TEMPERATURE_DPS,
  27. self.subject,
  28. min=0,
  29. max=37,
  30. )
  31. self.setUpBasicBinarySensor(
  32. ERROR_DPS,
  33. self.entities.get("binary_sensor_error"),
  34. device_class=BinarySensorDeviceClass.PROBLEM,
  35. testdata=(1, 0),
  36. )
  37. self.mark_secondary(["binary_sensor_error"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. (
  42. ClimateEntityFeature.TARGET_TEMPERATURE
  43. | ClimateEntityFeature.PRESET_MODE
  44. ),
  45. )
  46. def test_icon(self):
  47. self.dps[HVACMODE_DPS] = True
  48. self.assertEqual(self.subject.icon, "mdi:radiator")
  49. self.dps[HVACMODE_DPS] = False
  50. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  51. def test_temperature_unit_returns_device_temperature_unit(self):
  52. self.assertEqual(
  53. self.subject.temperature_unit, self.subject._device.temperature_unit
  54. )
  55. def test_current_temperature(self):
  56. self.dps[CURRENTTEMP_DPS] = 25
  57. self.assertEqual(self.subject.current_temperature, 25)
  58. def test_hvac_mode(self):
  59. self.dps[HVACMODE_DPS] = True
  60. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  61. self.dps[HVACMODE_DPS] = False
  62. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  63. def test_hvac_modes(self):
  64. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  65. async def test_turn_on(self):
  66. async with assert_device_properties_set(
  67. self.subject._device, {HVACMODE_DPS: True}
  68. ):
  69. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  70. async def test_turn_off(self):
  71. async with assert_device_properties_set(
  72. self.subject._device, {HVACMODE_DPS: False}
  73. ):
  74. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  75. def test_preset_modes(self):
  76. self.assertCountEqual(
  77. self.subject.preset_modes,
  78. [PRESET_COMFORT, PRESET_ECO],
  79. )
  80. def test_preset_mode(self):
  81. self.dps[PRESET_DPS] = True
  82. self.assertEqual(self.subject.preset_mode, PRESET_ECO)
  83. self.dps[PRESET_DPS] = False
  84. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  85. async def test_set_preset_more_to_eco(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {PRESET_DPS: True}
  88. ):
  89. await self.subject.async_set_preset_mode(PRESET_ECO)
  90. async def test_set_preset_more_to_comfort(self):
  91. async with assert_device_properties_set(
  92. self.subject._device, {PRESET_DPS: False}
  93. ):
  94. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  95. def test_extra_state_attributes(self):
  96. self.dps[ERROR_DPS] = 13
  97. self.assertCountEqual(
  98. self.subject.extra_state_attributes,
  99. {"error": 13},
  100. )