test_minco_mh1823d_thermostat.py 11 KB

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