4
0

test_nedis_htpl20f_heater.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. PRESET_AWAY,
  5. PRESET_COMFORT,
  6. PRESET_ECO,
  7. SUPPORT_TARGET_TEMPERATURE,
  8. SUPPORT_PRESET_MODE,
  9. )
  10. from homeassistant.const import STATE_UNAVAILABLE
  11. from ..const import NEDIS_HTPL20F_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.lock import BasicLockTests
  15. from ..mixins.number import BasicNumberTests
  16. from .base_device_tests import TuyaDeviceTestCase
  17. HVACMODE_DPS = "1"
  18. TEMPERATURE_DPS = "2"
  19. CURRENTTEMP_DPS = "3"
  20. PRESET_DPS = "4"
  21. LOCK_DPS = "7"
  22. UNKNOWN11_DPS = "11"
  23. TIMER_DPS = "13"
  24. UNKNOWN101_DPS = "101"
  25. class TestNedisHtpl20fHeater(
  26. BasicLockTests, BasicNumberTests, TargetTemperatureTests, TuyaDeviceTestCase
  27. ):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("nedis_htpl20f_heater.yaml", NEDIS_HTPL20F_PAYLOAD)
  31. self.subject = self.entities.get("climate")
  32. self.setUpTargetTemperature(
  33. TEMPERATURE_DPS,
  34. self.subject,
  35. min=15,
  36. max=35,
  37. )
  38. self.setUpBasicLock(
  39. LOCK_DPS,
  40. self.entities.get("lock_child_lock"),
  41. )
  42. self.setUpBasicNumber(TIMER_DPS, self.entities.get("number_timer"), max=1440)
  43. def test_supported_features(self):
  44. self.assertEqual(
  45. self.subject.supported_features,
  46. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  47. )
  48. def test_icon(self):
  49. self.dps[HVACMODE_DPS] = True
  50. self.assertEqual(self.subject.icon, "mdi:radiator")
  51. self.dps[HVACMODE_DPS] = False
  52. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  53. def test_temperature_unit_returns_device_temperature_unit(self):
  54. self.assertEqual(
  55. self.subject.temperature_unit, self.subject._device.temperature_unit
  56. )
  57. def test_current_temperature(self):
  58. self.dps[CURRENTTEMP_DPS] = 25
  59. self.assertEqual(self.subject.current_temperature, 25)
  60. def test_hvac_mode(self):
  61. self.dps[HVACMODE_DPS] = True
  62. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  63. self.dps[HVACMODE_DPS] = False
  64. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  65. self.dps[HVACMODE_DPS] = None
  66. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  67. def test_hvac_modes(self):
  68. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_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(HVAC_MODE_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(HVAC_MODE_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_device_state_attributes(self):
  107. self.dps[UNKNOWN11_DPS] = "11"
  108. self.dps[UNKNOWN101_DPS] = True
  109. self.assertCountEqual(
  110. self.subject.device_state_attributes,
  111. {"unknown_11": "11", "unknown_101": True},
  112. )