test_inkbird_thermostat.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. from homeassistant.components.climate.const import (
  2. SUPPORT_PRESET_MODE,
  3. SUPPORT_TARGET_TEMPERATURE_RANGE,
  4. )
  5. from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
  6. from ..const import INKBIRD_THERMOSTAT_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from .base_device_tests import TuyaDeviceTestCase
  9. ERROR_DPS = "12"
  10. UNIT_DPS = "101"
  11. CALIBRATE_DPS = "102"
  12. PRESET_DPS = "103"
  13. CURRENTTEMP_DPS = "104"
  14. TEMPLOW_DPS = "106"
  15. TIME_THRES_DPS = "108"
  16. HIGH_THRES_DPS = "109"
  17. LOW_THRES_DPS = "110"
  18. ALARM_HIGH_DPS = "111"
  19. ALARM_LOW_DPS = "112"
  20. ALARM_TIME_DPS = "113"
  21. TEMPHIGH_DPS = "114"
  22. SWITCH_DPS = "115"
  23. TEMPF_DPS = "116"
  24. UNKNOWN117_DPS = "117"
  25. UNKNOWN118_DPS = "118"
  26. UNKNOWN119_DPS = "119"
  27. UNKNOWN120_DPS = "120"
  28. class TestInkbirdThermostat(TuyaDeviceTestCase):
  29. __test__ = True
  30. def setUp(self):
  31. self.setUpForConfig("inkbird_thermostat.yaml", INKBIRD_THERMOSTAT_PAYLOAD)
  32. self.subject = self.entities.get("climate")
  33. def test_supported_features(self):
  34. self.assertEqual(
  35. self.subject.supported_features,
  36. SUPPORT_TARGET_TEMPERATURE_RANGE | SUPPORT_PRESET_MODE,
  37. )
  38. def test_icon(self):
  39. """Test that the icon is as expected."""
  40. self.dps[ALARM_HIGH_DPS] = False
  41. self.dps[ALARM_LOW_DPS] = False
  42. self.dps[ALARM_TIME_DPS] = False
  43. self.dps[SWITCH_DPS] = True
  44. self.assertEqual(self.subject.icon, "mdi:thermometer")
  45. self.dps[SWITCH_DPS] = False
  46. self.assertEqual(self.subject.icon, "mdi:thermometer-off")
  47. self.dps[ALARM_HIGH_DPS] = True
  48. self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
  49. self.dps[SWITCH_DPS] = True
  50. self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
  51. self.dps[ALARM_HIGH_DPS] = False
  52. self.dps[ALARM_LOW_DPS] = True
  53. self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
  54. self.dps[ALARM_LOW_DPS] = False
  55. self.dps[ALARM_TIME_DPS] = True
  56. self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
  57. def test_climate_hvac_modes(self):
  58. self.assertEqual(self.subject.hvac_modes, [])
  59. def test_preset_mode(self):
  60. self.dps[PRESET_DPS] = "on"
  61. self.assertEqual(self.subject.preset_mode, "On")
  62. self.dps[PRESET_DPS] = "pause"
  63. self.assertEqual(self.subject.preset_mode, "Pause")
  64. self.dps[PRESET_DPS] = "off"
  65. self.assertEqual(self.subject.preset_mode, "Off")
  66. self.dps[PRESET_DPS] = None
  67. self.assertEqual(self.subject.preset_mode, None)
  68. def test_preset_modes(self):
  69. self.assertCountEqual(
  70. self.subject.preset_modes,
  71. {"On", "Pause", "Off"},
  72. )
  73. async def test_set_preset_to_on(self):
  74. async with assert_device_properties_set(
  75. self.subject._device,
  76. {
  77. PRESET_DPS: "on",
  78. },
  79. ):
  80. await self.subject.async_set_preset_mode("On")
  81. self.subject._device.anticipate_property_value.assert_not_called()
  82. async def test_set_preset_to_pause(self):
  83. async with assert_device_properties_set(
  84. self.subject._device,
  85. {
  86. PRESET_DPS: "pause",
  87. },
  88. ):
  89. await self.subject.async_set_preset_mode("Pause")
  90. self.subject._device.anticipate_property_value.assert_not_called()
  91. async def test_set_preset_to_off(self):
  92. async with assert_device_properties_set(
  93. self.subject._device,
  94. {
  95. PRESET_DPS: "off",
  96. },
  97. ):
  98. await self.subject.async_set_preset_mode("Off")
  99. self.subject._device.anticipate_property_value.assert_not_called()
  100. def test_current_temperature(self):
  101. self.dps[CURRENTTEMP_DPS] = 289
  102. self.assertEqual(self.subject.current_temperature, 28.9)
  103. def test_temperature_unit(self):
  104. self.dps[UNIT_DPS] = "F"
  105. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  106. self.dps[UNIT_DPS] = "C"
  107. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  108. def test_temperature_range(self):
  109. self.dps[TEMPHIGH_DPS] = 301
  110. self.dps[TEMPLOW_DPS] = 255
  111. self.assertEqual(self.subject.target_temperature_high, 30.1)
  112. self.assertEqual(self.subject.target_temperature_low, 25.5)
  113. async def test_set_temperature_range(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {
  117. TEMPHIGH_DPS: 322,
  118. TEMPLOW_DPS: 266,
  119. },
  120. ):
  121. await self.subject.async_set_temperature(
  122. target_temp_high=32.2, target_temp_low=26.6
  123. )
  124. def test_device_state_attributes(self):
  125. self.dps[ERROR_DPS] = 1
  126. self.dps[CALIBRATE_DPS] = 1
  127. self.dps[TIME_THRES_DPS] = 5
  128. self.dps[HIGH_THRES_DPS] = 400
  129. self.dps[LOW_THRES_DPS] = 300
  130. self.dps[ALARM_HIGH_DPS] = True
  131. self.dps[ALARM_LOW_DPS] = False
  132. self.dps[ALARM_TIME_DPS] = True
  133. self.dps[SWITCH_DPS] = False
  134. self.dps[TEMPF_DPS] = 999
  135. self.dps[UNKNOWN117_DPS] = True
  136. self.dps[UNKNOWN118_DPS] = False
  137. self.dps[UNKNOWN119_DPS] = True
  138. self.dps[UNKNOWN120_DPS] = False
  139. self.assertCountEqual(
  140. self.subject.device_state_attributes,
  141. {
  142. "error": 1,
  143. "temperature_calibration_offset": 0.1,
  144. "heat_time_alarm_threshold_hours": 5,
  145. "high_temp_alarm_threshold": 40.0,
  146. "low_temp_alarm_threshold": 30.0,
  147. "high_temp_alarm": True,
  148. "low_temp_alarm": False,
  149. "heat_time_alarm": True,
  150. "switch_state": False,
  151. "current_temperature_f": 99.9,
  152. "unknown_117": True,
  153. "unknown_118": False,
  154. "unknown_119": True,
  155. "unknown_120": False,
  156. },
  157. )