test_owon_pct513_thermostat.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACAction,
  4. HVACMode,
  5. )
  6. from homeassistant.const import 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_current_temperature(self):
  73. self.dps[UNIT_DPS] = "c"
  74. self.dps[CURRENTTEMP_DPS] = 2100
  75. self.assertEqual(self.subject.current_temperature, 21.00)
  76. self.dps[UNIT_DPS] = "f"
  77. self.dps[CURRTEMPF_DPS] = 82
  78. self.assertEqual(self.subject.current_temperature, 82)
  79. def test_current_humidity(self):
  80. self.dps[CURRENTHUMID_DPS] = 50
  81. self.assertEqual(self.subject.current_humidity, 50)
  82. def test_hvac_modes(self):
  83. self.assertCountEqual(
  84. self.subject.hvac_modes,
  85. [
  86. HVACMode.COOL,
  87. HVACMode.HEAT,
  88. HVACMode.HEAT_COOL,
  89. HVACMode.OFF,
  90. ],
  91. )
  92. def test_hvac_mode(self):
  93. self.dps[HVACMODE_DPS] = "off"
  94. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  95. self.dps[HVACMODE_DPS] = "cool"
  96. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  97. self.dps[HVACMODE_DPS] = "heat"
  98. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  99. self.dps[HVACMODE_DPS] = "auto"
  100. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  101. self.dps[HVACMODE_DPS] = "emergencyheat"
  102. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  103. async def test_set_hvac_mode_off(self):
  104. async with assert_device_properties_set(
  105. self.subject._device, {HVACMODE_DPS: "off"}
  106. ):
  107. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  108. async def test_set_hvac_mode_cool(self):
  109. async with assert_device_properties_set(
  110. self.subject._device, {HVACMODE_DPS: "cool"}
  111. ):
  112. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  113. async def test_set_hvac_mode_heat(self):
  114. async with assert_device_properties_set(
  115. self.subject._device, {HVACMODE_DPS: "heat"}
  116. ):
  117. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  118. async def test_set_hvac_mode_heatcool(self):
  119. async with assert_device_properties_set(
  120. self.subject._device, {HVACMODE_DPS: "auto"}
  121. ):
  122. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  123. async def test_turn_off(self):
  124. async with assert_device_properties_set(
  125. self.subject._device, {HVACMODE_DPS: "off"}
  126. ):
  127. await self.subject.async_turn_off()
  128. async def test_turn_on(self):
  129. async with assert_device_properties_set(
  130. self.subject._device, {HVACMODE_DPS: "auto"}
  131. ):
  132. await self.subject.async_turn_on()
  133. def test_hvac_action(self):
  134. self.dps[HVACACTION_DPS] = "coolfanon"
  135. self.assertEqual(self.subject.hvac_action, HVACAction.COOLING)
  136. self.dps[HVACACTION_DPS] = "alloff"
  137. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  138. self.dps[HVACACTION_DPS] = "fanon"
  139. self.assertEqual(self.subject.hvac_action, HVACAction.FAN)
  140. self.dps[HVACACTION_DPS] = "heatfanon"
  141. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  142. def test_preset_modes(self):
  143. self.assertCountEqual(
  144. self.subject.preset_modes,
  145. ["Manual", "Follow Schedule", "Temporary Hold", "Permanent Hold"],
  146. )
  147. def test_preset_mode(self):
  148. self.dps[SCHED_DPS] = True
  149. self.dps[PRESET_DPS] = "followschedule"
  150. self.assertEqual(self.subject.preset_mode, "Follow Schedule")
  151. self.dps[PRESET_DPS] = "temphold"
  152. self.assertEqual(self.subject.preset_mode, "Temporary Hold")
  153. self.dps[PRESET_DPS] = "permhold"
  154. self.assertEqual(self.subject.preset_mode, "Permanent Hold")
  155. self.dps[SCHED_DPS] = False
  156. self.assertEqual(self.subject.preset_mode, "Manual")
  157. async def test_set_preset_to_schedule(self):
  158. async with assert_device_properties_set(
  159. self.subject._device,
  160. {
  161. SCHED_DPS: True,
  162. PRESET_DPS: "followschedule",
  163. },
  164. ):
  165. await self.subject.async_set_preset_mode("Follow Schedule")
  166. async def test_set_preset_to_temp_hold(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {
  170. SCHED_DPS: True,
  171. PRESET_DPS: "temphold",
  172. },
  173. ):
  174. await self.subject.async_set_preset_mode("Temporary Hold")
  175. async def test_set_preset_to_perm_hold(self):
  176. async with assert_device_properties_set(
  177. self.subject._device,
  178. {
  179. SCHED_DPS: True,
  180. PRESET_DPS: "permhold",
  181. },
  182. ):
  183. await self.subject.async_set_preset_mode("Permanent Hold")
  184. async def test_set_preset_to_manual(self):
  185. async with assert_device_properties_set(
  186. self.subject._device,
  187. {
  188. SCHED_DPS: False,
  189. },
  190. ):
  191. await self.subject.async_set_preset_mode("Manual")
  192. def test_fan_modes(self):
  193. self.assertCountEqual(
  194. self.subject.fan_modes,
  195. ["on", "auto", "cycle"],
  196. )
  197. def test_fan_mode(self):
  198. self.dps[FAN_DPS] = "on"
  199. self.assertEqual(self.subject.fan_mode, "on")
  200. self.dps[FAN_DPS] = "auto"
  201. self.assertEqual(self.subject.fan_mode, "auto")
  202. self.dps[FAN_DPS] = "cycle"
  203. self.assertEqual(self.subject.fan_mode, "cycle")
  204. async def test_set_fan_on(self):
  205. async with assert_device_properties_set(
  206. self.subject._device,
  207. {FAN_DPS: "on"},
  208. ):
  209. await self.subject.async_set_fan_mode("on")
  210. async def test_set_fan_auto(self):
  211. async with assert_device_properties_set(
  212. self.subject._device,
  213. {FAN_DPS: "auto"},
  214. ):
  215. await self.subject.async_set_fan_mode("auto")
  216. async def test_set_fan_cycle(self):
  217. async with assert_device_properties_set(
  218. self.subject._device,
  219. {FAN_DPS: "cycle"},
  220. ):
  221. await self.subject.async_set_fan_mode("cycle")
  222. def test_extra_state_attributes(self):
  223. self.dps[UNKNOWN45_DPS] = 45
  224. self.dps[INSTALL_DPS] = "107"
  225. self.dps[TEMPC_DPS] = 1080
  226. self.dps[UNKNOWN109_DPS] = 109
  227. self.dps[TEMPF2_DPS] = 110
  228. self.dps[UNKNOWN111_DPS] = 111
  229. self.dps[UNKNOWN116_DPS] = "116"
  230. self.assertDictEqual(
  231. self.subject.extra_state_attributes,
  232. {
  233. "unknown_45": 45,
  234. "installation": "107",
  235. "temp_c": 10.8,
  236. "unknown_109": 109,
  237. "temp_f2": 110,
  238. "unknown_111": 111,
  239. "unknown_116": "116",
  240. },
  241. )