test_weau_pool_heatpumpv2.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
  3. from ..const import WEAU_POOL_HEATPUMPV2_PAYLOAD
  4. from ..helpers import assert_device_properties_set
  5. from ..mixins.binary_sensor import BasicBinarySensorTests
  6. from ..mixins.climate import TargetTemperatureTests
  7. from .base_device_tests import TuyaDeviceTestCase
  8. POWER_DPS = "1"
  9. MODE_DPS = "2"
  10. TEMPERATURE_DPS = "9"
  11. CURRENTTEMP_DPS = "10"
  12. FAULT_DPS = "20"
  13. UNKNOWN101_DPS = "101"
  14. UNKNOWN102_DPS = "102"
  15. UNKNOWN103_DPS = "103"
  16. UNKNOWN104_DPS = "104"
  17. class TestWeauPoolHeatpumpV2(
  18. BasicBinarySensorTests,
  19. TargetTemperatureTests,
  20. TuyaDeviceTestCase,
  21. ):
  22. def setUp(self):
  23. self.setUpForConfig("weau_pool_heatpump_v2.yaml", WEAU_POOL_HEATPUMPV2_PAYLOAD)
  24. self.subject = self.entities.get("climate")
  25. self.setUpTargetTemperature(
  26. TEMPERATURE_DPS,
  27. self.subject,
  28. min=7.0,
  29. max=60.0,
  30. )
  31. self.setUpBasicBinarySensor(
  32. FAULT_DPS,
  33. self.entities.get("binary_sensor_problem"),
  34. device_class=BinarySensorDeviceClass.PROBLEM,
  35. testdata=(4, 0),
  36. )
  37. self.mark_secondary(["binary_sensor_problem"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. ClimateEntityFeature.TARGET_TEMPERATURE
  42. | ClimateEntityFeature.PRESET_MODE
  43. | ClimateEntityFeature.TURN_OFF
  44. | ClimateEntityFeature.TURN_ON,
  45. )
  46. def test_current_temperature(self):
  47. self.dps[CURRENTTEMP_DPS] = 194
  48. self.assertEqual(self.subject.current_temperature, 19.4)
  49. def test_hvac_mode(self):
  50. self.dps[POWER_DPS] = True
  51. self.dps[MODE_DPS] = "eheat"
  52. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  53. self.dps[MODE_DPS] = "ecool"
  54. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  55. self.dps[MODE_DPS] = "sheat"
  56. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  57. self.dps[MODE_DPS] = "scool"
  58. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  59. self.dps[MODE_DPS] = "bheat"
  60. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  61. self.dps[MODE_DPS] = "bcool"
  62. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  63. self.dps[MODE_DPS] = "auto"
  64. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  65. self.dps[POWER_DPS] = False
  66. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  67. def test_hvac_modes(self):
  68. self.assertCountEqual(
  69. self.subject.hvac_modes,
  70. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  71. )
  72. async def test_turn_off(self):
  73. async with assert_device_properties_set(
  74. self.subject._device,
  75. {POWER_DPS: False},
  76. ):
  77. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  78. async def test_set_cool(self):
  79. async with assert_device_properties_set(
  80. self.subject._device,
  81. {POWER_DPS: True, MODE_DPS: "ecool"},
  82. ):
  83. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  84. async def test_set_heat(self):
  85. async with assert_device_properties_set(
  86. self.subject._device,
  87. {POWER_DPS: True, MODE_DPS: "eheat"},
  88. ):
  89. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  90. def test_extra_state_attributes(self):
  91. self.dps[UNKNOWN101_DPS] = 101
  92. self.dps[UNKNOWN102_DPS] = 102
  93. self.dps[UNKNOWN103_DPS] = 103
  94. self.dps[UNKNOWN104_DPS] = True
  95. self.assertDictEqual(
  96. self.subject.extra_state_attributes,
  97. {
  98. "unknown_101": 101,
  99. "unknown_102": 102,
  100. "unknown_103": 103,
  101. "unknown_104": True,
  102. },
  103. )
  104. def test_basic_bsensor_extra_state_attributes(self):
  105. self.dps[FAULT_DPS] = 4
  106. self.assertDictEqual(
  107. self.basicBSensor.extra_state_attributes,
  108. {"fault_code": 4, "description": "flow_fault"},
  109. )