test_kogan_kawfpac09ya_airconditioner.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
  2. from homeassistant.const import UnitOfTemperature
  3. from ..const import KOGAN_KAWFPAC09YA_AIRCON_PAYLOAD
  4. from ..helpers import assert_device_properties_set
  5. from ..mixins.climate import TargetTemperatureTests
  6. from .base_device_tests import TuyaDeviceTestCase
  7. POWER_DPS = "1"
  8. TEMPERATURE_DPS = "2"
  9. CURRENTTEMP_DPS = "3"
  10. HVACMODE_DPS = "4"
  11. FAN_DPS = "5"
  12. UNIT_DPS = "19"
  13. COUNTDOWN_DPS = "105"
  14. UNKNOWN106_DPS = "106"
  15. UNKNOWN107_DPS = "107"
  16. class TestKoganKAWFPAC09YA(TargetTemperatureTests, TuyaDeviceTestCase):
  17. __test__ = True
  18. def setUp(self):
  19. self.setUpForConfig(
  20. "kogan_kawfpac09ya_airconditioner.yaml",
  21. KOGAN_KAWFPAC09YA_AIRCON_PAYLOAD,
  22. )
  23. self.subject = self.entities.get("climate")
  24. self.setUpTargetTemperature(
  25. TEMPERATURE_DPS,
  26. self.subject,
  27. min=16,
  28. max=30,
  29. )
  30. def test_supported_features(self):
  31. self.assertEqual(
  32. self.subject.supported_features,
  33. (ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE),
  34. )
  35. def test_icon(self):
  36. self.dps[POWER_DPS] = True
  37. self.dps[HVACMODE_DPS] = "COOL"
  38. self.assertEqual(self.subject.icon, "mdi:snowflake")
  39. self.dps[HVACMODE_DPS] = "DRY"
  40. self.assertEqual(self.subject.icon, "mdi:water")
  41. self.dps[HVACMODE_DPS] = "FAN"
  42. self.assertEqual(self.subject.icon, "mdi:fan")
  43. self.dps[POWER_DPS] = False
  44. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  45. def test_temperature_unit(self):
  46. self.dps[UNIT_DPS] = "C"
  47. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  48. self.dps[UNIT_DPS] = "F"
  49. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.FAHRENHEIT)
  50. def test_minimum_target_temperature_f(self):
  51. self.dps[UNIT_DPS] = "F"
  52. self.assertEqual(self.subject.min_temp, 60)
  53. def test_maximum_target_temperature_f(self):
  54. self.dps[UNIT_DPS] = "F"
  55. self.assertEqual(self.subject.max_temp, 86)
  56. def test_current_temperature(self):
  57. self.dps[CURRENTTEMP_DPS] = 25
  58. self.assertEqual(self.subject.current_temperature, 25)
  59. def test_hvac_mode(self):
  60. self.dps[POWER_DPS] = True
  61. self.dps[HVACMODE_DPS] = "COOL"
  62. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  63. self.dps[HVACMODE_DPS] = "DRY"
  64. self.assertEqual(self.subject.hvac_mode, HVACMode.DRY)
  65. self.dps[HVACMODE_DPS] = "FAN"
  66. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  67. self.dps[HVACMODE_DPS] = "FAN"
  68. self.dps[POWER_DPS] = False
  69. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  70. def test_hvac_modes(self):
  71. self.assertCountEqual(
  72. self.subject.hvac_modes,
  73. [
  74. HVACMode.OFF,
  75. HVACMode.COOL,
  76. HVACMode.DRY,
  77. HVACMode.FAN_ONLY,
  78. ],
  79. )
  80. async def test_turn_on(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "COOL"}
  83. ):
  84. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  85. async def test_turn_off(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {POWER_DPS: False}
  88. ):
  89. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  90. def test_fan_mode(self):
  91. self.dps[FAN_DPS] = "1"
  92. self.assertEqual(self.subject.fan_mode, "low")
  93. self.dps[FAN_DPS] = "2"
  94. self.assertEqual(self.subject.fan_mode, "high")
  95. def test_fan_modes(self):
  96. self.assertCountEqual(
  97. self.subject.fan_modes,
  98. [
  99. "low",
  100. "high",
  101. ],
  102. )
  103. async def test_set_fan_mode_to_low(self):
  104. async with assert_device_properties_set(
  105. self.subject._device,
  106. {FAN_DPS: "1"},
  107. ):
  108. await self.subject.async_set_fan_mode("low")
  109. async def test_set_fan_mode_to_high(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {FAN_DPS: "2"},
  113. ):
  114. await self.subject.async_set_fan_mode("high")
  115. def test_extra_state_attributes(self):
  116. self.dps[COUNTDOWN_DPS] = 105
  117. self.dps[UNKNOWN106_DPS] = 106
  118. self.dps[UNKNOWN107_DPS] = True
  119. self.assertDictEqual(
  120. self.subject.extra_state_attributes,
  121. {
  122. "countdown": 105,
  123. "unknown_106": 106,
  124. "unknown_107": True,
  125. },
  126. )