test_inkbird_itc306a_thermostat.py 6.1 KB

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