test_madimack_elitev3_heatpump.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.components.sensor import SensorDeviceClass
  6. from homeassistant.const import (
  7. PERCENTAGE,
  8. TEMP_CELSIUS,
  9. TEMP_FAHRENHEIT,
  10. )
  11. from ..const import MADIMACK_ELITEV3_HEATPUMP_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.sensor import MultiSensorTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. POWER_DPS = "1"
  17. HVACMODE_DPS = "2"
  18. TEMPERATURE_DPS = "4"
  19. PRESET_DPS = "5"
  20. UNIT_DPS = "6"
  21. UNKNOWN15_DPS = "15"
  22. PWRLEVEL_DPS = "20"
  23. TEMPMAX_DPS = "21"
  24. TEMPMIN_DPS = "22"
  25. COILTEMP_DPS = "23"
  26. EXHAUSTTEMP_DPS = "24"
  27. OUTLETTEMP_DPS = "25"
  28. AMBIENTTEMP_DPS = "26"
  29. UNKNOWN101_DPS = "101"
  30. CURRENTTEMP_DPS = "102"
  31. RETURNGASTEMP_DPS = "103"
  32. COOLCOILTEMP_DPS = "104"
  33. COOLPLATETEMP_DPS = "105"
  34. EEVOPENING_DPS = "106"
  35. UNKNOWN107_DPS = "107"
  36. class TestMadimackEliteV3Heatpump(
  37. MultiSensorTests,
  38. TargetTemperatureTests,
  39. TuyaDeviceTestCase,
  40. ):
  41. __test__ = True
  42. def setUp(self):
  43. self.setUpForConfig(
  44. "madimack_elite_v3_heatpump.yaml",
  45. MADIMACK_ELITEV3_HEATPUMP_PAYLOAD,
  46. )
  47. self.subject = self.entities.get("climate")
  48. self.setUpTargetTemperature(
  49. TEMPERATURE_DPS,
  50. self.subject,
  51. min=18,
  52. max=40,
  53. )
  54. self.setUpMultiSensors(
  55. [
  56. {
  57. "name": "sensor_power_level",
  58. "dps": PWRLEVEL_DPS,
  59. "device_class": SensorDeviceClass.POWER_FACTOR,
  60. "unit": PERCENTAGE,
  61. },
  62. {
  63. "name": "sensor_evaporator_coil_pipe_temperature",
  64. "dps": COILTEMP_DPS,
  65. "device_class": SensorDeviceClass.TEMPERATURE,
  66. "unit": TEMP_CELSIUS,
  67. },
  68. {
  69. "name": "sensor_exhaust_gas_temperature",
  70. "dps": EXHAUSTTEMP_DPS,
  71. "device_class": SensorDeviceClass.TEMPERATURE,
  72. "unit": TEMP_CELSIUS,
  73. },
  74. {
  75. "name": "sensor_outlet_water_temperature",
  76. "dps": OUTLETTEMP_DPS,
  77. "device_class": SensorDeviceClass.TEMPERATURE,
  78. "unit": TEMP_CELSIUS,
  79. },
  80. {
  81. "name": "sensor_ambient_temperature",
  82. "dps": AMBIENTTEMP_DPS,
  83. "device_class": SensorDeviceClass.TEMPERATURE,
  84. "unit": TEMP_CELSIUS,
  85. },
  86. {
  87. "name": "sensor_return_gas_temperature",
  88. "dps": RETURNGASTEMP_DPS,
  89. "device_class": SensorDeviceClass.TEMPERATURE,
  90. "unit": TEMP_CELSIUS,
  91. },
  92. {
  93. "name": "sensor_cooling_coil_pipe_temperature",
  94. "dps": COOLCOILTEMP_DPS,
  95. "device_class": SensorDeviceClass.TEMPERATURE,
  96. "unit": TEMP_CELSIUS,
  97. },
  98. {
  99. "name": "sensor_cooling_plate_temperature",
  100. "dps": COOLPLATETEMP_DPS,
  101. "device_class": SensorDeviceClass.TEMPERATURE,
  102. "unit": TEMP_CELSIUS,
  103. },
  104. {
  105. "name": "sensor_eev_opening",
  106. "dps": EEVOPENING_DPS,
  107. },
  108. ]
  109. )
  110. self.mark_secondary(
  111. [
  112. "sensor_power_level",
  113. "sensor_evaporator_coil_pipe_temperature",
  114. "sensor_exhaust_gas_temperature",
  115. "sensor_outlet_water_temperature",
  116. "sensor_ambient_temperature",
  117. "sensor_return_gas_temperature",
  118. "sensor_cooling_coil_pipe_temperature",
  119. "sensor_cooling_plate_temperature",
  120. "sensor_eev_opening",
  121. ]
  122. )
  123. def test_supported_features(self):
  124. self.assertEqual(
  125. self.subject.supported_features,
  126. (
  127. ClimateEntityFeature.PRESET_MODE
  128. | ClimateEntityFeature.TARGET_TEMPERATURE
  129. ),
  130. )
  131. def test_icon(self):
  132. self.dps[POWER_DPS] = True
  133. self.dps[HVACMODE_DPS] = "auto"
  134. self.assertEqual(self.subject.icon, "mdi:refresh-auto")
  135. self.dps[HVACMODE_DPS] = "cold"
  136. self.assertEqual(self.subject.icon, "mdi:snowflake")
  137. self.dps[HVACMODE_DPS] = "heating"
  138. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  139. self.dps[POWER_DPS] = False
  140. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  141. def test_temperature_unit(self):
  142. self.dps[UNIT_DPS] = "c"
  143. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  144. self.dps[UNIT_DPS] = "f"
  145. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  146. def test_minimum_target_temperature(self):
  147. self.dps[TEMPMIN_DPS] = 60
  148. self.assertEqual(self.subject.min_temp, 60)
  149. def test_maximum_target_temperature(self):
  150. self.dps[TEMPMAX_DPS] = 104
  151. self.assertEqual(self.subject.max_temp, 104)
  152. def test_current_temperature(self):
  153. self.dps[CURRENTTEMP_DPS] = 25
  154. self.assertEqual(self.subject.current_temperature, 25)
  155. def test_hvac_mode(self):
  156. self.dps[POWER_DPS] = True
  157. self.dps[HVACMODE_DPS] = "auto"
  158. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  159. self.dps[HVACMODE_DPS] = "cold"
  160. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  161. self.dps[HVACMODE_DPS] = "heating"
  162. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  163. self.dps[POWER_DPS] = False
  164. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  165. def test_hvac_modes(self):
  166. self.assertCountEqual(
  167. self.subject.hvac_modes,
  168. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  169. )
  170. async def test_set_hvac_mode_to_cool(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {POWER_DPS: True, HVACMODE_DPS: "cold"},
  174. ):
  175. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  176. async def test_set_hvac_mode_to_heat(self):
  177. async with assert_device_properties_set(
  178. self.subject._device,
  179. {POWER_DPS: True, HVACMODE_DPS: "heating"},
  180. ):
  181. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  182. async def test_set_hvac_mode_to_auto(self):
  183. async with assert_device_properties_set(
  184. self.subject._device,
  185. {POWER_DPS: True, HVACMODE_DPS: "auto"},
  186. ):
  187. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  188. async def test_set_hvac_mode_to_off(self):
  189. async with assert_device_properties_set(
  190. self.subject._device,
  191. {POWER_DPS: False},
  192. ):
  193. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  194. def test_preset_mode(self):
  195. self.dps[PRESET_DPS] = "silence"
  196. self.assertEqual(self.subject.preset_mode, "Silence")
  197. self.dps[PRESET_DPS] = "power"
  198. self.assertEqual(self.subject.preset_mode, "Perfect")
  199. self.dps[PRESET_DPS] = "boost"
  200. self.assertEqual(self.subject.preset_mode, "Power")
  201. def test_preset_modes(self):
  202. self.assertCountEqual(
  203. self.subject.preset_modes,
  204. ["Silence", "Perfect", "Power"],
  205. )
  206. async def test_set_preset_to_silence(self):
  207. async with assert_device_properties_set(
  208. self.subject._device,
  209. {PRESET_DPS: "silence"},
  210. ):
  211. await self.subject.async_set_preset_mode("Silence")
  212. async def test_set_preset_to_perfect(self):
  213. async with assert_device_properties_set(
  214. self.subject._device,
  215. {PRESET_DPS: "power"},
  216. ):
  217. await self.subject.async_set_preset_mode("Perfect")
  218. async def test_set_preset_to_boost(self):
  219. async with assert_device_properties_set(
  220. self.subject._device,
  221. {PRESET_DPS: "boost"},
  222. ):
  223. await self.subject.async_set_preset_mode("Power")
  224. def test_extra_state_attributes(self):
  225. self.dps[UNKNOWN15_DPS] = 15
  226. self.dps[UNKNOWN101_DPS] = 101
  227. self.dps[UNKNOWN107_DPS] = True
  228. self.assertDictEqual(
  229. self.subject.extra_state_attributes,
  230. {
  231. "unknown_15": 15,
  232. "unknown_101": 101,
  233. "unknown_107": True,
  234. },
  235. )