test_inkbird_itc306a_thermostat.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_minimum_target_temperature(self):
  111. self.dps[UNIT_DPS] = "C"
  112. self.assertEqual(self.subject.min_temp, 20.0)
  113. self.dps[UNIT_DPS] = "F"
  114. self.assertEqual(self.subject.min_temp, 68.0)
  115. def test_maximum_target_temperature(self):
  116. self.dps[UNIT_DPS] = "C"
  117. self.assertEqual(self.subject.max_temp, 35.0)
  118. self.dps[UNIT_DPS] = "F"
  119. self.assertEqual(self.subject.max_temp, 95.0)
  120. def test_temperature_range(self):
  121. self.dps[TEMPHIGH_DPS] = 301
  122. self.dps[TEMPLOW_DPS] = 255
  123. self.assertEqual(self.subject.target_temperature_high, 30.1)
  124. self.assertEqual(self.subject.target_temperature_low, 25.5)
  125. async def test_set_temperature_range(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {
  129. TEMPHIGH_DPS: 322,
  130. TEMPLOW_DPS: 266,
  131. },
  132. ):
  133. await self.subject.async_set_temperature(
  134. target_temp_high=32.2, target_temp_low=26.6
  135. )
  136. async def test_set_target_temperature_fails_outside_valid_range(self):
  137. self.dps[UNIT_DPS] = "C"
  138. with self.assertRaisesRegex(
  139. ValueError, "target_temp_low \\(19.9\\) must be between 20.0 and 35.0"
  140. ):
  141. await self.subject.async_set_temperature(
  142. target_temp_high=32.2, target_temp_low=19.9
  143. )
  144. self.dps[UNIT_DPS] = "F"
  145. with self.assertRaisesRegex(
  146. ValueError, "target_temp_high \\(95.1\\) must be between 68.0 and 95.0"
  147. ):
  148. await self.subject.async_set_temperature(
  149. target_temp_low=70.0, target_temp_high=95.1
  150. )
  151. def test_device_state_attributes(self):
  152. self.dps[ERROR_DPS] = 1
  153. self.dps[CALIBRATE_DPS] = 1
  154. self.dps[TIME_THRES_DPS] = 5
  155. self.dps[HIGH_THRES_DPS] = 400
  156. self.dps[LOW_THRES_DPS] = 300
  157. self.dps[ALARM_HIGH_DPS] = True
  158. self.dps[ALARM_LOW_DPS] = False
  159. self.dps[ALARM_TIME_DPS] = True
  160. self.dps[SWITCH_DPS] = False
  161. self.dps[TEMPF_DPS] = 999
  162. self.dps[UNKNOWN117_DPS] = True
  163. self.dps[UNKNOWN118_DPS] = False
  164. self.dps[UNKNOWN119_DPS] = True
  165. self.dps[UNKNOWN120_DPS] = False
  166. self.assertDictEqual(
  167. self.subject.device_state_attributes,
  168. {
  169. "error": 1,
  170. "temperature_calibration_offset": 0.1,
  171. "heat_time_alarm_threshold_hours": 5,
  172. "high_temp_alarm_threshold": 40.0,
  173. "low_temp_alarm_threshold": 30.0,
  174. "high_temp_alarm": True,
  175. "low_temp_alarm": False,
  176. "heat_time_alarm": True,
  177. "switch_state": False,
  178. "current_temperature_f": 99.9,
  179. "unknown_117": True,
  180. "unknown_118": False,
  181. "unknown_119": True,
  182. "unknown_120": False,
  183. },
  184. )