test_minco_mh1823d_thermostat.py 11 KB

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