test_nedis_htpl20f_heater.py 4.1 KB

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