HomeKit - Climate: power state on/off support (#14082)
* add power state support on off * Added check for current operation mode * Extended 'set_heat_cool' * Added tests
This commit is contained in:
1 parent
ef4498ec27
commit
c9de2f015b
2 files changed
+79
-6
No files matched your search
@@ -7,7 +7,7 @@ from homeassistant.components.climate import (
|
||||
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH, ATTR_OPERATION_MODE,
|
||||
ATTR_OPERATION_LIST, STATE_COOL, STATE_HEAT, STATE_AUTO)
|
||||
from homeassistant.const import (
|
||||
ATTR_SERVICE, ATTR_SERVICE_DATA, ATTR_SUPPORTED_FEATURES,
|
||||
ATTR_ENTITY_ID, ATTR_SERVICE, ATTR_SERVICE_DATA, ATTR_SUPPORTED_FEATURES,
|
||||
ATTR_UNIT_OF_MEASUREMENT, EVENT_CALL_SERVICE,
|
||||
STATE_OFF, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
|
||||
@@ -261,6 +261,65 @@ class TestHomekitThermostats(unittest.TestCase):
|
||||
25.0)
|
||||
self.assertEqual(acc.char_cooling_thresh_temp.value, 25.0)
|
||||
|
||||
def test_power_state(self):
|
||||
"""Test if accessory and HA are updated accordingly."""
|
||||
climate = 'climate.test'
|
||||
|
||||
# SUPPORT_ON_OFF = True
|
||||
self.hass.states.set(climate, STATE_HEAT,
|
||||
{ATTR_SUPPORTED_FEATURES: 4096,
|
||||
ATTR_OPERATION_MODE: STATE_HEAT,
|
||||
ATTR_TEMPERATURE: 23.0,
|
||||
ATTR_CURRENT_TEMPERATURE: 18.0})
|
||||
self.hass.block_till_done()
|
||||
acc = self.thermostat_cls(self.hass, 'Climate', climate,
|
||||
2, config=None)
|
||||
acc.run()
|
||||
self.assertTrue(acc.support_power_state)
|
||||
|
||||
self.assertEqual(acc.char_current_heat_cool.value, 1)
|
||||
self.assertEqual(acc.char_target_heat_cool.value, 1)
|
||||
|
||||
self.hass.states.set(climate, STATE_OFF,
|
||||
{ATTR_OPERATION_MODE: STATE_HEAT,
|
||||
ATTR_TEMPERATURE: 23.0,
|
||||
ATTR_CURRENT_TEMPERATURE: 18.0})
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(acc.char_current_heat_cool.value, 0)
|
||||
self.assertEqual(acc.char_target_heat_cool.value, 0)
|
||||
|
||||
self.hass.states.set(climate, STATE_OFF,
|
||||
{ATTR_OPERATION_MODE: STATE_OFF,
|
||||
ATTR_TEMPERATURE: 23.0,
|
||||
ATTR_CURRENT_TEMPERATURE: 18.0})
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(acc.char_current_heat_cool.value, 0)
|
||||
self.assertEqual(acc.char_target_heat_cool.value, 0)
|
||||
|
||||
# Set from HomeKit
|
||||
acc.char_target_heat_cool.client_update_value(1)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(
|
||||
self.events[0].data[ATTR_SERVICE], 'turn_on')
|
||||
self.assertEqual(
|
||||
self.events[0].data[ATTR_SERVICE_DATA][ATTR_ENTITY_ID],
|
||||
climate)
|
||||
self.assertEqual(
|
||||
self.events[1].data[ATTR_SERVICE], 'set_operation_mode')
|
||||
self.assertEqual(
|
||||
self.events[1].data[ATTR_SERVICE_DATA][ATTR_OPERATION_MODE],
|
||||
STATE_HEAT)
|
||||
self.assertEqual(acc.char_target_heat_cool.value, 1)
|
||||
|
||||
acc.char_target_heat_cool.client_update_value(0)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(
|
||||
self.events[2].data[ATTR_SERVICE], 'turn_off')
|
||||
self.assertEqual(
|
||||
self.events[2].data[ATTR_SERVICE_DATA][ATTR_ENTITY_ID],
|
||||
climate)
|
||||
self.assertEqual(acc.char_target_heat_cool.value, 0)
|
||||
|
||||
def test_thermostat_fahrenheit(self):
|
||||
"""Test if accessory and HA are updated accordingly."""
|
||||
climate = 'climate.test'
|
||||
|
||||
Reference in new issue
Block a user