test_owon_pct513_thermostat.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACAction,
  4. HVACMode,
  5. )
  6. from homeassistant.const import PRECISION_TENTHS, UnitOfTemperature
  7. from ..const import OWON_PCT513_THERMOSTAT_PAYLOAD
  8. from ..helpers import assert_device_properties_set
  9. from ..mixins.climate import TargetTemperatureTests
  10. from ..mixins.number import BasicNumberTests
  11. from .base_device_tests import TuyaDeviceTestCase
  12. HVACMODE_DPS = "2"
  13. TEMPERATURE_DPS = "16"
  14. TEMPF_DPS = "17"
  15. UNIT_DPS = "23"
  16. CURRENTTEMP_DPS = "24"
  17. CURRTEMPF_DPS = "29"
  18. CURRENTHUMID_DPS = "34"
  19. UNKNOWN45_DPS = "45"
  20. INSTALL_DPS = "107"
  21. TEMPC_DPS = "108"
  22. UNKNOWN109_DPS = "109"
  23. TEMPF2_DPS = "110"
  24. UNKNOWN111_DPS = "111"
  25. FAN_DPS = "115"
  26. UNKNOWN116_DPS = "116"
  27. SCHED_DPS = "119"
  28. PRESET_DPS = "120"
  29. DUTYCYCLE_DPS = "123"
  30. HVACACTION_DPS = "129"
  31. class TestOwonPCT513Thermostat(
  32. BasicNumberTests,
  33. TargetTemperatureTests,
  34. TuyaDeviceTestCase,
  35. ):
  36. __test__ = True
  37. def setUp(self):
  38. self.setUpForConfig(
  39. "owon_pct513_thermostat.yaml", OWON_PCT513_THERMOSTAT_PAYLOAD
  40. )
  41. self.subject = self.entities.get("climate")
  42. self.setUpTargetTemperature(
  43. TEMPERATURE_DPS,
  44. self.subject,
  45. min=15.0,
  46. max=45.0,
  47. scale=100,
  48. step=50,
  49. )
  50. self.setUpBasicNumber(
  51. DUTYCYCLE_DPS,
  52. self.entities.get("number_fan_runtime"),
  53. max=55,
  54. step=5,
  55. unit="min",
  56. )
  57. self.mark_secondary(["number_fan_runtime"])
  58. def test_supported_features(self):
  59. self.assertEqual(
  60. self.subject.supported_features,
  61. (
  62. ClimateEntityFeature.FAN_MODE
  63. | ClimateEntityFeature.PRESET_MODE
  64. | ClimateEntityFeature.TARGET_TEMPERATURE
  65. ),
  66. )
  67. def test_temperature_unit(self):
  68. self.dps[UNIT_DPS] = "c"
  69. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  70. self.dps[UNIT_DPS] = "f"
  71. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.FAHRENHEIT)
  72. def test_precision(self):
  73. self.assertEqual(self.subject.precision, PRECISION_TENTHS)
  74. def test_current_temperature(self):
  75. self.dps[UNIT_DPS] = "c"
  76. self.dps[CURRENTTEMP_DPS] = 2100
  77. self.assertEqual(self.subject.current_temperature, 21.00)
  78. self.dps[UNIT_DPS] = "f"
  79. self.dps[CURRTEMPF_DPS] = 82
  80. self.assertEqual(self.subject.current_temperature, 82)
  81. def test_current_humidity(self):
  82. self.dps[CURRENTHUMID_DPS] = 50
  83. self.assertEqual(self.subject.current_humidity, 50)
  84. def test_hvac_modes(self):
  85. self.assertCountEqual(
  86. self.subject.hvac_modes,
  87. [
  88. HVACMode.COOL,
  89. HVACMode.HEAT,
  90. HVACMode.HEAT_COOL,
  91. HVACMode.OFF,
  92. ],
  93. )
  94. def test_hvac_mode(self):
  95. self.dps[HVACMODE_DPS] = "off"
  96. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  97. self.dps[HVACMODE_DPS] = "cool"
  98. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  99. self.dps[HVACMODE_DPS] = "heat"
  100. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  101. self.dps[HVACMODE_DPS] = "auto"
  102. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  103. self.dps[HVACMODE_DPS] = "emergencyheat"
  104. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  105. async def test_set_hvac_mode_off(self):
  106. async with assert_device_properties_set(
  107. self.subject._device, {HVACMODE_DPS: "off"}
  108. ):
  109. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  110. async def test_set_hvac_mode_cool(self):
  111. async with assert_device_properties_set(
  112. self.subject._device, {HVACMODE_DPS: "cool"}
  113. ):
  114. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  115. async def test_set_hvac_mode_heat(self):
  116. async with assert_device_properties_set(
  117. self.subject._device, {HVACMODE_DPS: "heat"}
  118. ):
  119. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  120. async def test_set_hvac_mode_heatcool(self):
  121. async with assert_device_properties_set(
  122. self.subject._device, {HVACMODE_DPS: "auto"}
  123. ):
  124. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  125. async def test_turn_off(self):
  126. async with assert_device_properties_set(
  127. self.subject._device, {HVACMODE_DPS: "off"}
  128. ):
  129. await self.subject.async_turn_off()
  130. async def test_turn_on(self):
  131. async with assert_device_properties_set(
  132. self.subject._device, {HVACMODE_DPS: "auto"}
  133. ):
  134. await self.subject.async_turn_on()
  135. def test_hvac_action(self):
  136. self.dps[HVACACTION_DPS] = "coolfanon"
  137. self.assertEqual(self.subject.hvac_action, HVACAction.COOLING)
  138. self.dps[HVACACTION_DPS] = "alloff"
  139. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  140. self.dps[HVACACTION_DPS] = "fanon"
  141. self.assertEqual(self.subject.hvac_action, HVACAction.FAN)
  142. self.dps[HVACACTION_DPS] = "heatfanon"
  143. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  144. def test_preset_modes(self):
  145. self.assertCountEqual(
  146. self.subject.preset_modes,
  147. ["Manual", "Follow Schedule", "Temporary Hold", "Permanent Hold"],
  148. )
  149. def test_preset_mode(self):
  150. self.dps[SCHED_DPS] = True
  151. self.dps[PRESET_DPS] = "followschedule"
  152. self.assertEqual(self.subject.preset_mode, "Follow Schedule")
  153. self.dps[PRESET_DPS] = "temphold"
  154. self.assertEqual(self.subject.preset_mode, "Temporary Hold")
  155. self.dps[PRESET_DPS] = "permhold"
  156. self.assertEqual(self.subject.preset_mode, "Permanent Hold")
  157. self.dps[SCHED_DPS] = False
  158. self.assertEqual(self.subject.preset_mode, "Manual")
  159. async def test_set_preset_to_schedule(self):
  160. async with assert_device_properties_set(
  161. self.subject._device,
  162. {
  163. SCHED_DPS: True,
  164. PRESET_DPS: "followschedule",
  165. },
  166. ):
  167. await self.subject.async_set_preset_mode("Follow Schedule")
  168. async def test_set_preset_to_temp_hold(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {
  172. SCHED_DPS: True,
  173. PRESET_DPS: "temphold",
  174. },
  175. ):
  176. await self.subject.async_set_preset_mode("Temporary Hold")
  177. async def test_set_preset_to_perm_hold(self):
  178. async with assert_device_properties_set(
  179. self.subject._device,
  180. {
  181. SCHED_DPS: True,
  182. PRESET_DPS: "permhold",
  183. },
  184. ):
  185. await self.subject.async_set_preset_mode("Permanent Hold")
  186. async def test_set_preset_to_manual(self):
  187. async with assert_device_properties_set(
  188. self.subject._device,
  189. {
  190. SCHED_DPS: False,
  191. },
  192. ):
  193. await self.subject.async_set_preset_mode("Manual")
  194. def test_fan_modes(self):
  195. self.assertCountEqual(
  196. self.subject.fan_modes,
  197. ["on", "auto", "cycle"],
  198. )
  199. def test_fan_mode(self):
  200. self.dps[FAN_DPS] = "on"
  201. self.assertEqual(self.subject.fan_mode, "on")
  202. self.dps[FAN_DPS] = "auto"
  203. self.assertEqual(self.subject.fan_mode, "auto")
  204. self.dps[FAN_DPS] = "cycle"
  205. self.assertEqual(self.subject.fan_mode, "cycle")
  206. async def test_set_fan_on(self):
  207. async with assert_device_properties_set(
  208. self.subject._device,
  209. {FAN_DPS: "on"},
  210. ):
  211. await self.subject.async_set_fan_mode("on")
  212. async def test_set_fan_auto(self):
  213. async with assert_device_properties_set(
  214. self.subject._device,
  215. {FAN_DPS: "auto"},
  216. ):
  217. await self.subject.async_set_fan_mode("auto")
  218. async def test_set_fan_cycle(self):
  219. async with assert_device_properties_set(
  220. self.subject._device,
  221. {FAN_DPS: "cycle"},
  222. ):
  223. await self.subject.async_set_fan_mode("cycle")
  224. def test_extra_state_attributes(self):
  225. self.dps[UNKNOWN45_DPS] = 45
  226. self.dps[INSTALL_DPS] = "107"
  227. self.dps[TEMPC_DPS] = 1080
  228. self.dps[UNKNOWN109_DPS] = 109
  229. self.dps[TEMPF2_DPS] = 110
  230. self.dps[UNKNOWN111_DPS] = 111
  231. self.dps[UNKNOWN116_DPS] = "116"
  232. self.assertDictEqual(
  233. self.subject.extra_state_attributes,
  234. {
  235. "unknown_45": 45,
  236. "installation": "107",
  237. "temp_c": 10.8,
  238. "unknown_109": 109,
  239. "temp_f2": 110,
  240. "unknown_111": 111,
  241. "unknown_116": "116",
  242. },
  243. )