test_owon_pct513_thermostat.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. def test_hvac_action(self):
  124. self.dps[HVACACTION_DPS] = "coolfanon"
  125. self.assertEqual(self.subject.hvac_action, HVACAction.COOLING)
  126. self.dps[HVACACTION_DPS] = "alloff"
  127. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  128. self.dps[HVACACTION_DPS] = "fanon"
  129. self.assertEqual(self.subject.hvac_action, HVACAction.FAN)
  130. self.dps[HVACACTION_DPS] = "heatfanon"
  131. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  132. def test_preset_modes(self):
  133. self.assertCountEqual(
  134. self.subject.preset_modes,
  135. ["Manual", "Follow Schedule", "Temporary Hold", "Permanent Hold"],
  136. )
  137. def test_preset_mode(self):
  138. self.dps[SCHED_DPS] = True
  139. self.dps[PRESET_DPS] = "followschedule"
  140. self.assertEqual(self.subject.preset_mode, "Follow Schedule")
  141. self.dps[PRESET_DPS] = "temphold"
  142. self.assertEqual(self.subject.preset_mode, "Temporary Hold")
  143. self.dps[PRESET_DPS] = "permhold"
  144. self.assertEqual(self.subject.preset_mode, "Permanent Hold")
  145. self.dps[SCHED_DPS] = False
  146. self.assertEqual(self.subject.preset_mode, "Manual")
  147. async def test_set_preset_to_schedule(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {
  151. SCHED_DPS: True,
  152. PRESET_DPS: "followschedule",
  153. },
  154. ):
  155. await self.subject.async_set_preset_mode("Follow Schedule")
  156. async def test_set_preset_to_temp_hold(self):
  157. async with assert_device_properties_set(
  158. self.subject._device,
  159. {
  160. SCHED_DPS: True,
  161. PRESET_DPS: "temphold",
  162. },
  163. ):
  164. await self.subject.async_set_preset_mode("Temporary Hold")
  165. async def test_set_preset_to_perm_hold(self):
  166. async with assert_device_properties_set(
  167. self.subject._device,
  168. {
  169. SCHED_DPS: True,
  170. PRESET_DPS: "permhold",
  171. },
  172. ):
  173. await self.subject.async_set_preset_mode("Permanent Hold")
  174. async def test_set_preset_to_manual(self):
  175. async with assert_device_properties_set(
  176. self.subject._device,
  177. {
  178. SCHED_DPS: False,
  179. },
  180. ):
  181. await self.subject.async_set_preset_mode("Manual")
  182. def test_fan_modes(self):
  183. self.assertCountEqual(
  184. self.subject.fan_modes,
  185. ["on", "auto", "cycle"],
  186. )
  187. def test_fan_mode(self):
  188. self.dps[FAN_DPS] = "on"
  189. self.assertEqual(self.subject.fan_mode, "on")
  190. self.dps[FAN_DPS] = "auto"
  191. self.assertEqual(self.subject.fan_mode, "auto")
  192. self.dps[FAN_DPS] = "cycle"
  193. self.assertEqual(self.subject.fan_mode, "cycle")
  194. async def test_set_fan_on(self):
  195. async with assert_device_properties_set(
  196. self.subject._device,
  197. {FAN_DPS: "on"},
  198. ):
  199. await self.subject.async_set_fan_mode("on")
  200. async def test_set_fan_auto(self):
  201. async with assert_device_properties_set(
  202. self.subject._device,
  203. {FAN_DPS: "auto"},
  204. ):
  205. await self.subject.async_set_fan_mode("auto")
  206. async def test_set_fan_cycle(self):
  207. async with assert_device_properties_set(
  208. self.subject._device,
  209. {FAN_DPS: "cycle"},
  210. ):
  211. await self.subject.async_set_fan_mode("cycle")
  212. def test_extra_state_attributes(self):
  213. self.dps[UNKNOWN45_DPS] = 45
  214. self.dps[INSTALL_DPS] = "107"
  215. self.dps[TEMPC_DPS] = 1080
  216. self.dps[UNKNOWN109_DPS] = 109
  217. self.dps[TEMPF2_DPS] = 110
  218. self.dps[UNKNOWN111_DPS] = 111
  219. self.dps[UNKNOWN116_DPS] = "116"
  220. self.assertDictEqual(
  221. self.subject.extra_state_attributes,
  222. {
  223. "unknown_45": 45,
  224. "installation": "107",
  225. "temp_c": 10.8,
  226. "unknown_109": 109,
  227. "temp_f2": 110,
  228. "unknown_111": 111,
  229. "unknown_116": "116",
  230. },
  231. )