test_nedis_htpl20f_heater.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. 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.mark_secondary(["lock_child_lock", "time_timer"])
  41. def test_supported_features(self):
  42. self.assertEqual(
  43. self.subject.supported_features,
  44. (
  45. ClimateEntityFeature.TARGET_TEMPERATURE
  46. | ClimateEntityFeature.PRESET_MODE
  47. | ClimateEntityFeature.TURN_OFF
  48. | ClimateEntityFeature.TURN_ON
  49. ),
  50. )
  51. def test_temperature_unit_returns_celsius(self):
  52. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  53. def test_current_temperature(self):
  54. self.dps[CURRENTTEMP_DPS] = 25
  55. self.assertEqual(self.subject.current_temperature, 25)
  56. def test_hvac_mode(self):
  57. self.dps[HVACMODE_DPS] = True
  58. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  59. self.dps[HVACMODE_DPS] = False
  60. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  61. def test_hvac_modes(self):
  62. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.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(HVACMode.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(HVACMode.OFF)
  73. def test_preset_modes(self):
  74. self.assertCountEqual(
  75. self.subject.preset_modes,
  76. [PRESET_COMFORT, PRESET_ECO, PRESET_AWAY],
  77. )
  78. def test_preset_mode(self):
  79. self.dps[PRESET_DPS] = "1"
  80. self.assertEqual(self.subject.preset_mode, PRESET_ECO)
  81. self.dps[PRESET_DPS] = "2"
  82. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  83. self.dps[PRESET_DPS] = "3"
  84. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  85. async def test_set_preset_more_to_eco(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {PRESET_DPS: "1"}
  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: "2"}
  93. ):
  94. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  95. async def test_set_preset_more_to_away(self):
  96. async with assert_device_properties_set(
  97. self.subject._device, {PRESET_DPS: "3"}
  98. ):
  99. await self.subject.async_set_preset_mode(PRESET_AWAY)
  100. def test_extra_state_attributes(self):
  101. self.dps[UNKNOWN11_DPS] = "11"
  102. self.dps[UNKNOWN101_DPS] = True
  103. self.assertCountEqual(
  104. self.subject.extra_state_attributes,
  105. {"unknown_11": "11", "unknown_101": True},
  106. )