test_moes_bht002_thermostat.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_AUTO,
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. PRESET_ECO,
  6. PRESET_COMFORT,
  7. SUPPORT_PRESET_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.const import STATE_UNAVAILABLE
  11. from ..const import MOES_BHT002_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.lock import BasicLockTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. POWER_DPS = "1"
  17. TEMPERATURE_DPS = "2"
  18. CURRENTTEMP_DPS = "3"
  19. HVACMODE_DPS = "4"
  20. PRESET_DPS = "5"
  21. LOCK_DPS = "6"
  22. UNKNOWN104_DPS = "104"
  23. class TestMoesBHT002Thermostat(
  24. BasicLockTests, TargetTemperatureTests, TuyaDeviceTestCase
  25. ):
  26. __test__ = True
  27. def setUp(self):
  28. self.setUpForConfig(
  29. "moes_bht002_thermostat_c.yaml",
  30. MOES_BHT002_PAYLOAD,
  31. )
  32. self.subject = self.entities.get("climate")
  33. self.setUpTargetTemperature(
  34. TEMPERATURE_DPS,
  35. self.subject,
  36. min=5.0,
  37. max=35.0,
  38. scale=2,
  39. )
  40. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  41. self.mark_secondary(["lock_child_lock"])
  42. def test_supported_features(self):
  43. self.assertEqual(
  44. self.subject.supported_features,
  45. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  46. )
  47. def test_temperature_unit(self):
  48. self.assertEqual(
  49. self.subject.temperature_unit,
  50. self.subject._device.temperature_unit,
  51. )
  52. async def test_legacy_set_temperature_with_preset_mode(self):
  53. async with assert_device_properties_set(
  54. self.subject._device, {PRESET_DPS: True}
  55. ):
  56. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  57. async def test_legacy_set_temperature_with_both_properties(self):
  58. async with assert_device_properties_set(
  59. self.subject._device,
  60. {
  61. TEMPERATURE_DPS: 44,
  62. PRESET_DPS: False,
  63. },
  64. ):
  65. await self.subject.async_set_temperature(
  66. temperature=22, preset_mode=PRESET_COMFORT
  67. )
  68. def test_current_temperature(self):
  69. self.dps[CURRENTTEMP_DPS] = 44
  70. self.assertEqual(self.subject.current_temperature, 22)
  71. def test_hvac_mode(self):
  72. self.dps[POWER_DPS] = False
  73. self.dps[HVACMODE_DPS] = "0"
  74. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  75. self.dps[POWER_DPS] = True
  76. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  77. self.dps[HVACMODE_DPS] = "1"
  78. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  79. self.dps[HVACMODE_DPS] = None
  80. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  81. def test_hvac_modes(self):
  82. self.assertCountEqual(
  83. self.subject.hvac_modes,
  84. [
  85. HVAC_MODE_HEAT,
  86. HVAC_MODE_AUTO,
  87. HVAC_MODE_OFF,
  88. ],
  89. )
  90. def test_device_state_attribures(self):
  91. self.dps[UNKNOWN104_DPS] = False
  92. self.assertDictEqual(
  93. self.subject.device_state_attributes,
  94. {"unknown_104": False},
  95. )
  96. def test_icons(self):
  97. self.dps[LOCK_DPS] = True
  98. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  99. self.dps[LOCK_DPS] = False
  100. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")