test_nedis_htpl20f_heater.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from homeassistant.components.climate.const import (
  2. PRESET_AWAY,
  3. PRESET_COMFORT,
  4. PRESET_ECO,
  5. ClimateEntityFeature,
  6. HVACMode,
  7. )
  8. from homeassistant.const import UnitOfTemperature, UnitOfTime
  9. from ..const import NEDIS_HTPL20F_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.climate import TargetTemperatureTests
  12. from ..mixins.lock import BasicLockTests
  13. from ..mixins.number import BasicNumberTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. HVACMODE_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. CURRENTTEMP_DPS = "3"
  18. PRESET_DPS = "4"
  19. LOCK_DPS = "7"
  20. UNKNOWN11_DPS = "11"
  21. TIMER_DPS = "13"
  22. UNKNOWN101_DPS = "101"
  23. class TestNedisHtpl20fHeater(
  24. BasicLockTests, BasicNumberTests, TargetTemperatureTests, TuyaDeviceTestCase
  25. ):
  26. __test__ = True
  27. def setUp(self):
  28. self.setUpForConfig("nedis_htpl20f_heater.yaml", NEDIS_HTPL20F_PAYLOAD)
  29. self.subject = self.entities.get("climate")
  30. self.setUpTargetTemperature(
  31. TEMPERATURE_DPS,
  32. self.subject,
  33. min=15.0,
  34. max=35.0,
  35. )
  36. self.setUpBasicLock(
  37. LOCK_DPS,
  38. self.entities.get("lock_child_lock"),
  39. )
  40. self.setUpBasicNumber(
  41. TIMER_DPS,
  42. self.entities.get("number_timer"),
  43. max=1440,
  44. unit=UnitOfTime.MINUTES,
  45. )
  46. self.mark_secondary(["lock_child_lock", "number_timer"])
  47. def test_supported_features(self):
  48. self.assertEqual(
  49. self.subject.supported_features,
  50. (
  51. ClimateEntityFeature.TARGET_TEMPERATURE
  52. | ClimateEntityFeature.PRESET_MODE
  53. | ClimateEntityFeature.TURN_OFF
  54. | ClimateEntityFeature.TURN_ON
  55. ),
  56. )
  57. def test_temperature_unit_returns_celsius(self):
  58. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  59. def test_current_temperature(self):
  60. self.dps[CURRENTTEMP_DPS] = 25
  61. self.assertEqual(self.subject.current_temperature, 25)
  62. def test_hvac_mode(self):
  63. self.dps[HVACMODE_DPS] = True
  64. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  65. self.dps[HVACMODE_DPS] = False
  66. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  67. def test_hvac_modes(self):
  68. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  69. async def test_turn_on(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {HVACMODE_DPS: True}
  72. ):
  73. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  74. async def test_turn_off(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {HVACMODE_DPS: False}
  77. ):
  78. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  79. def test_preset_modes(self):
  80. self.assertCountEqual(
  81. self.subject.preset_modes,
  82. [PRESET_COMFORT, PRESET_ECO, PRESET_AWAY],
  83. )
  84. def test_preset_mode(self):
  85. self.dps[PRESET_DPS] = "1"
  86. self.assertEqual(self.subject.preset_mode, PRESET_ECO)
  87. self.dps[PRESET_DPS] = "2"
  88. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  89. self.dps[PRESET_DPS] = "3"
  90. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  91. async def test_set_preset_more_to_eco(self):
  92. async with assert_device_properties_set(
  93. self.subject._device, {PRESET_DPS: "1"}
  94. ):
  95. await self.subject.async_set_preset_mode(PRESET_ECO)
  96. async def test_set_preset_more_to_comfort(self):
  97. async with assert_device_properties_set(
  98. self.subject._device, {PRESET_DPS: "2"}
  99. ):
  100. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  101. async def test_set_preset_more_to_away(self):
  102. async with assert_device_properties_set(
  103. self.subject._device, {PRESET_DPS: "3"}
  104. ):
  105. await self.subject.async_set_preset_mode(PRESET_AWAY)
  106. def test_extra_state_attributes(self):
  107. self.dps[UNKNOWN11_DPS] = "11"
  108. self.dps[UNKNOWN101_DPS] = True
  109. self.assertCountEqual(
  110. self.subject.extra_state_attributes,
  111. {"unknown_11": "11", "unknown_101": True},
  112. )