Fix homekit_controller climate supported operation_list being blank (#23095)

* Fix tado supported operation modes when used with homekit_controller

* Replace with list comp as requested in review

* More list comps
pull/23040/head
Jc2k 2019-04-15 16:09:21 +01:00 committed by Martin Hjelmare
parent 2f89f88d23
commit e97b2b7015
2 changed files with 48 additions and 5 deletions

View File

@ -36,12 +36,12 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
def __init__(self, *args):
"""Initialise the device."""
super().__init__(*args)
self._state = None
self._current_mode = None
self._valid_modes = []
self._current_temp = None
self._target_temp = None
super().__init__(*args)
def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""
@ -57,10 +57,26 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
def _setup_heating_cooling_target(self, characteristic):
self._features |= SUPPORT_OPERATION_MODE
valid_values = characteristic.get(
'valid-values', DEFAULT_VALID_MODES)
if 'valid-values' in characteristic:
valid_values = [
val for val in DEFAULT_VALID_MODES
if val in characteristic['valid-values']
]
else:
valid_values = DEFAULT_VALID_MODES
if 'minValue' in characteristic:
valid_values = [
val for val in valid_values
if val >= characteristic['minValue']
]
if 'maxValue' in characteristic:
valid_values = [
val for val in valid_values
if val <= characteristic['maxValue']
]
self._valid_modes = [
MODE_HOMEKIT_TO_HASS.get(mode) for mode in valid_values
MODE_HOMEKIT_TO_HASS[mode] for mode in valid_values
]
def _setup_temperature_target(self, characteristic):

View File

@ -2,7 +2,7 @@
from homeassistant.components.climate.const import (
DOMAIN, SERVICE_SET_OPERATION_MODE, SERVICE_SET_TEMPERATURE)
from tests.components.homekit_controller.common import (
setup_test_component)
FakeService, setup_test_component)
HEATING_COOLING_TARGET = ('thermostat', 'heating-cooling.target')
@ -11,6 +11,33 @@ TEMPERATURE_TARGET = ('thermostat', 'temperature.target')
TEMPERATURE_CURRENT = ('thermostat', 'temperature.current')
async def test_climate_respect_supported_op_modes_1(hass, utcnow):
"""Test that climate respects minValue/maxValue hints."""
service = FakeService('public.hap.service.thermostat')
char = service.add_characteristic('heating-cooling.target')
char.value = 0
char.minValue = 0
char.maxValue = 1
helper = await setup_test_component(hass, [service])
state = await helper.poll_and_get_state()
assert state.attributes['operation_list'] == ['off', 'heat']
async def test_climate_respect_supported_op_modes_2(hass, utcnow):
"""Test that climate respects validValue hints."""
service = FakeService('public.hap.service.thermostat')
char = service.add_characteristic('heating-cooling.target')
char.value = 0
char.validValues = [0, 1, 2]
helper = await setup_test_component(hass, [service])
state = await helper.poll_and_get_state()
assert state.attributes['operation_list'] == ['off', 'heat', 'cool']
async def test_climate_change_thermostat_state(hass, utcnow):
"""Test that we can turn a HomeKit thermostat on and off again."""
from homekit.model.services import ThermostatService