test_weau_pool_heatpumpv2.py 4.2 KB

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