test_minco_mh1823d_thermostat.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. from homeassistant.components.climate.const import (
  2. CURRENT_HVAC_HEAT,
  3. CURRENT_HVAC_IDLE,
  4. CURRENT_HVAC_OFF,
  5. HVAC_MODE_AUTO,
  6. HVAC_MODE_HEAT,
  7. HVAC_MODE_OFF,
  8. SUPPORT_PRESET_MODE,
  9. SUPPORT_TARGET_TEMPERATURE,
  10. )
  11. from homeassistant.const import (
  12. DEVICE_CLASS_TEMPERATURE,
  13. STATE_UNAVAILABLE,
  14. TEMP_CELSIUS,
  15. TEMP_FAHRENHEIT,
  16. )
  17. from ..const import MINCO_MH1823D_THERMOSTAT_PAYLOAD
  18. from ..helpers import assert_device_properties_set
  19. from ..mixins.climate import TargetTemperatureTests
  20. from ..mixins.lock import BasicLockTests
  21. from ..mixins.number import MultiNumberTests
  22. from ..mixins.select import MultiSelectTests
  23. from ..mixins.sensor import BasicSensorTests
  24. from ..mixins.switch import BasicSwitchTests
  25. from .base_device_tests import TuyaDeviceTestCase
  26. HVACMODE_DPS = "1"
  27. PRESET_DPS = "2"
  28. HVACACTION_DPS = "3"
  29. LOCK_DPS = "5"
  30. ANTIFROST_DPS = "9"
  31. UNKNOWN12_DPS = "12"
  32. SELECT_DPS = "18"
  33. UNIT_DPS = "19"
  34. TEMPERATURE_DPS = "22"
  35. TEMPF_DPS = "23"
  36. UNKNOWN32_DPS = "32"
  37. CURRENTTEMP_DPS = "33"
  38. CALIBINT_DPS = "35"
  39. CURTEMPF_DPS = "37"
  40. SCHEDULE_DPS = "39"
  41. UNKNOWN45_DPS = "45"
  42. EXTERNTEMP_DPS = "101"
  43. EXTTEMPF_DPS = "102"
  44. CALIBEXT_DPS = "103"
  45. CALIBSWING_DPS = "104"
  46. UNKNOWN105_DPS = "105"
  47. TEMPLIMIT_DPS = "106"
  48. TEMPLIMITF_DPS = "107"
  49. class TestMincoMH1823DThermostat(
  50. BasicLockTests,
  51. BasicSensorTests,
  52. BasicSwitchTests,
  53. MultiNumberTests,
  54. MultiSelectTests,
  55. TargetTemperatureTests,
  56. TuyaDeviceTestCase,
  57. ):
  58. __test__ = True
  59. def setUp(self):
  60. self.setUpForConfig(
  61. "minco_mh1823d_thermostat.yaml",
  62. MINCO_MH1823D_THERMOSTAT_PAYLOAD,
  63. )
  64. self.subject = self.entities.get("climate")
  65. self.setUpTargetTemperature(
  66. TEMPERATURE_DPS,
  67. self.subject,
  68. min=5,
  69. max=50,
  70. )
  71. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  72. self.setUpBasicSensor(
  73. EXTERNTEMP_DPS,
  74. self.entities.get("sensor_external_temperature"),
  75. unit=TEMP_CELSIUS,
  76. device_class=DEVICE_CLASS_TEMPERATURE,
  77. state_class="measurement",
  78. testdata=(300, 30.0),
  79. )
  80. self.setUpBasicSwitch(ANTIFROST_DPS, self.entities.get("switch_anti_frost"))
  81. self.setUpMultiNumber(
  82. [
  83. {
  84. "name": "number_calibration_offset_internal",
  85. "dps": CALIBINT_DPS,
  86. "min": -9,
  87. "max": 9,
  88. },
  89. {
  90. "name": "number_calibration_offset_external",
  91. "dps": CALIBEXT_DPS,
  92. "min": -9,
  93. "max": 9,
  94. },
  95. {
  96. "name": "number_calibration_swing",
  97. "dps": CALIBSWING_DPS,
  98. "min": 1,
  99. "max": 9,
  100. },
  101. {
  102. "name": "number_high_temperature_limit",
  103. "dps": TEMPLIMIT_DPS,
  104. "min": 5,
  105. "max": 65,
  106. },
  107. ]
  108. )
  109. self.setUpMultiSelect(
  110. [
  111. {
  112. "name": "select_temperature_sensor",
  113. "dps": SELECT_DPS,
  114. "options": {
  115. "in": "Internal",
  116. "out": "External",
  117. },
  118. },
  119. {
  120. "name": "select_temperature_unit",
  121. "dps": UNIT_DPS,
  122. "options": {
  123. "c": "Celsius",
  124. "f": "Fahrenheit",
  125. },
  126. },
  127. {
  128. "name": "select_schedule",
  129. "dps": SCHEDULE_DPS,
  130. "options": {
  131. "7": "7 day",
  132. "5_2": "5+2 day",
  133. "6_1": "6+1 day",
  134. },
  135. },
  136. ]
  137. )
  138. def test_supported_features(self):
  139. self.assertEqual(
  140. self.subject.supported_features,
  141. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  142. )
  143. def test_icon(self):
  144. self.dps[HVACMODE_DPS] = True
  145. self.dps[HVACACTION_DPS] = "start"
  146. self.assertEqual(self.subject.icon, "mdi:thermometer")
  147. self.dps[HVACACTION_DPS] = "stop"
  148. self.assertEqual(self.subject.icon, "mdi:thermometer-off")
  149. self.assertEqual(self.basicSwitch.icon, "mdi:snowflake")
  150. def test_temperature_unit(self):
  151. self.dps[UNIT_DPS] = "c"
  152. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  153. self.dps[UNIT_DPS] = "f"
  154. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  155. def test_target_temperature_f(self):
  156. self.dps[TEMPF_DPS] = 70
  157. self.dps[UNIT_DPS] = "f"
  158. self.assertEqual(self.subject.target_temperature, 70)
  159. def test_minimum_target_temperature_f(self):
  160. self.dps[UNIT_DPS] = "f"
  161. self.assertEqual(self.subject.min_temp, 41)
  162. def test_maximum_target_temperature_f(self):
  163. self.dps[UNIT_DPS] = "f"
  164. self.assertEqual(self.subject.max_temp, 99)
  165. async def test_legacy_set_temperature_with_preset_mode(self):
  166. async with assert_device_properties_set(
  167. self.subject._device, {PRESET_DPS: "holiday"}
  168. ):
  169. await self.subject.async_set_temperature(preset_mode="holiday")
  170. async def test_legacy_set_temperature_with_both_properties(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {
  174. TEMPERATURE_DPS: 25,
  175. PRESET_DPS: "program",
  176. },
  177. ):
  178. await self.subject.async_set_temperature(
  179. temperature=25, preset_mode="program"
  180. )
  181. async def test_set_target_temperature_fails_outside_valid_range_f(self):
  182. self.dps[UNIT_DPS] = "f"
  183. with self.assertRaisesRegex(
  184. ValueError, "temp_f \\(40\\) must be between 41 and 99"
  185. ):
  186. await self.subject.async_set_target_temperature(40)
  187. with self.assertRaisesRegex(
  188. ValueError, "temp_f \\(100\\) must be between 41 and 99"
  189. ):
  190. await self.subject.async_set_target_temperature(100)
  191. def test_current_temperature(self):
  192. self.dps[CURRENTTEMP_DPS] = 251
  193. self.dps[CURTEMPF_DPS] = 783
  194. self.dps[UNIT_DPS] = "c"
  195. self.assertEqual(self.subject.current_temperature, 25.1)
  196. self.dps[UNIT_DPS] = "f"
  197. self.assertEqual(self.subject.current_temperature, 78.3)
  198. def test_hvac_mode(self):
  199. self.dps[HVACMODE_DPS] = True
  200. self.dps[PRESET_DPS] = "manual"
  201. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  202. self.dps[PRESET_DPS] = "program"
  203. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  204. self.dps[PRESET_DPS] = "holiday"
  205. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  206. self.dps[HVACMODE_DPS] = False
  207. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  208. self.dps[HVACMODE_DPS] = None
  209. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  210. def test_hvac_modes(self):
  211. self.assertCountEqual(
  212. self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_AUTO]
  213. )
  214. async def test_set_hvac_heat(self):
  215. async with assert_device_properties_set(
  216. self.subject._device, {HVACMODE_DPS: True, PRESET_DPS: "manual"}
  217. ):
  218. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  219. async def test_set_hvac_auto(self):
  220. async with assert_device_properties_set(
  221. self.subject._device, {HVACMODE_DPS: True, PRESET_DPS: "program"}
  222. ):
  223. await self.subject.async_set_hvac_mode(HVAC_MODE_AUTO)
  224. async def test_turn_off(self):
  225. async with assert_device_properties_set(
  226. self.subject._device, {HVACMODE_DPS: False}
  227. ):
  228. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  229. def test_preset_mode(self):
  230. self.dps[PRESET_DPS] = "manual"
  231. self.assertEqual(self.subject.preset_mode, "manual")
  232. self.dps[PRESET_DPS] = "program"
  233. self.assertEqual(self.subject.preset_mode, "program")
  234. self.dps[PRESET_DPS] = "holiday"
  235. self.assertEqual(self.subject.preset_mode, "holiday")
  236. self.dps[PRESET_DPS] = None
  237. self.assertEqual(self.subject.preset_mode, None)
  238. def test_preset_modes(self):
  239. self.assertCountEqual(
  240. self.subject.preset_modes,
  241. ["manual", "program", "holiday"],
  242. )
  243. async def test_set_preset_mode_to_program(self):
  244. async with assert_device_properties_set(
  245. self.subject._device,
  246. {PRESET_DPS: "program"},
  247. ):
  248. await self.subject.async_set_preset_mode("program")
  249. async def test_set_preset_mode_to_manual(self):
  250. async with assert_device_properties_set(
  251. self.subject._device,
  252. {PRESET_DPS: "manual"},
  253. ):
  254. await self.subject.async_set_preset_mode("manual")
  255. async def test_set_preset_mode_to_holiday(self):
  256. async with assert_device_properties_set(
  257. self.subject._device,
  258. {PRESET_DPS: "holiday"},
  259. ):
  260. await self.subject.async_set_preset_mode("holiday")
  261. def test_hvac_action(self):
  262. self.dps[HVACMODE_DPS] = True
  263. self.dps[HVACACTION_DPS] = "start"
  264. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  265. self.dps[HVACACTION_DPS] = "stop"
  266. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  267. self.dps[HVACMODE_DPS] = False
  268. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  269. def test_device_state_attributes(self):
  270. self.dps[UNKNOWN12_DPS] = False
  271. self.dps[UNKNOWN32_DPS] = 32
  272. self.dps[UNKNOWN45_DPS] = 45
  273. self.dps[UNKNOWN105_DPS] = "unknown 105"
  274. self.assertDictEqual(
  275. self.subject.device_state_attributes,
  276. {
  277. "unknown_12": False,
  278. "unknown_32": 32,
  279. "unknown_45": 45,
  280. "unknown_105": "unknown 105",
  281. },
  282. )