test_moes_bht002_thermostat.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. def test_supported_features(self):
  42. self.assertEqual(
  43. self.subject.supported_features,
  44. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  45. )
  46. def test_temperature_unit(self):
  47. self.assertEqual(
  48. self.subject.temperature_unit,
  49. self.subject._device.temperature_unit,
  50. )
  51. async def test_legacy_set_temperature_with_preset_mode(self):
  52. async with assert_device_properties_set(
  53. self.subject._device, {PRESET_DPS: True}
  54. ):
  55. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  56. async def test_legacy_set_temperature_with_both_properties(self):
  57. async with assert_device_properties_set(
  58. self.subject._device,
  59. {
  60. TEMPERATURE_DPS: 44,
  61. PRESET_DPS: False,
  62. },
  63. ):
  64. await self.subject.async_set_temperature(
  65. temperature=22, preset_mode=PRESET_COMFORT
  66. )
  67. def test_current_temperature(self):
  68. self.dps[CURRENTTEMP_DPS] = 44
  69. self.assertEqual(self.subject.current_temperature, 22)
  70. def test_hvac_mode(self):
  71. self.dps[POWER_DPS] = False
  72. self.dps[HVACMODE_DPS] = "0"
  73. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  74. self.dps[POWER_DPS] = True
  75. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  76. self.dps[HVACMODE_DPS] = "1"
  77. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  78. self.dps[HVACMODE_DPS] = None
  79. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  80. def test_hvac_modes(self):
  81. self.assertCountEqual(
  82. self.subject.hvac_modes,
  83. [
  84. HVAC_MODE_HEAT,
  85. HVAC_MODE_AUTO,
  86. HVAC_MODE_OFF,
  87. ],
  88. )
  89. def test_device_state_attribures(self):
  90. self.dps[UNKNOWN104_DPS] = False
  91. self.assertDictEqual(
  92. self.subject.device_state_attributes,
  93. {"unknown_104": False},
  94. )
  95. def test_icons(self):
  96. self.dps[LOCK_DPS] = True
  97. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  98. self.dps[LOCK_DPS] = False
  99. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")