Fix min/max temp and humidity for homekit_controller climate (#23421)

* Fix min/max temp and humidity for homekit_controller climate.

* Fix typo
This commit is contained in:
Jc2k 2019-04-30 23:08:31 +01:00 committed by Martin Hjelmare
parent b0843f4a38
commit 1c4367e5a9
4 changed files with 59 additions and 1 deletions

View file

@ -4,7 +4,8 @@ import logging
from homeassistant.components.climate import ClimateDevice from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
STATE_COOL, STATE_HEAT, STATE_IDLE, SUPPORT_OPERATION_MODE, STATE_COOL, STATE_HEAT, STATE_IDLE, SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY) SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY,
SUPPORT_TARGET_HUMIDITY_HIGH, SUPPORT_TARGET_HUMIDITY_LOW)
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, TEMP_CELSIUS
from . import KNOWN_DEVICES, HomeKitEntity from . import KNOWN_DEVICES, HomeKitEntity
@ -43,6 +44,10 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
self._target_temp = None self._target_temp = None
self._current_humidity = None self._current_humidity = None
self._target_humidity = None self._target_humidity = None
self._min_target_temp = None
self._max_target_temp = None
self._min_target_humidity = None
self._max_target_humidity = None
super().__init__(*args) super().__init__(*args)
def get_characteristic_types(self): def get_characteristic_types(self):
@ -86,9 +91,23 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
def _setup_temperature_target(self, characteristic): def _setup_temperature_target(self, characteristic):
self._features |= SUPPORT_TARGET_TEMPERATURE self._features |= SUPPORT_TARGET_TEMPERATURE
if 'minValue' in characteristic:
self._min_target_temp = characteristic['minValue']
if 'maxValue' in characteristic:
self._max_target_temp = characteristic['maxValue']
def _setup_relative_humidity_target(self, characteristic): def _setup_relative_humidity_target(self, characteristic):
self._features |= SUPPORT_TARGET_HUMIDITY self._features |= SUPPORT_TARGET_HUMIDITY
if 'minValue' in characteristic:
self._min_target_humidity = characteristic['minValue']
self._features |= SUPPORT_TARGET_HUMIDITY_LOW
if 'maxValue' in characteristic:
self._max_target_humidity = characteristic['maxValue']
self._features |= SUPPORT_TARGET_HUMIDITY_HIGH
def _update_heating_cooling_current(self, value): def _update_heating_cooling_current(self, value):
self._state = MODE_HOMEKIT_TO_HASS.get(value) self._state = MODE_HOMEKIT_TO_HASS.get(value)
@ -152,6 +171,20 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
return self._target_temp return self._target_temp
@property
def min_temp(self):
"""Return the minimum target temp."""
if self._max_target_temp:
return self._min_target_temp
return super().min_temp
@property
def max_temp(self):
"""Return the maximum target temp."""
if self._max_target_temp:
return self._max_target_temp
return super().max_temp
@property @property
def current_humidity(self): def current_humidity(self):
"""Return the current humidity.""" """Return the current humidity."""
@ -162,6 +195,16 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
"""Return the humidity we try to reach.""" """Return the humidity we try to reach."""
return self._target_humidity return self._target_humidity
@property
def min_humidity(self):
"""Return the minimum humidity."""
return self._min_target_humidity
@property
def max_humidity(self):
"""Return the maximum humidity."""
return self._max_target_humidity
@property @property
def current_operation(self): def current_operation(self):
"""Return current operation ie. heat, cool, idle.""" """Return current operation ie. heat, cool, idle."""

View file

@ -180,6 +180,12 @@ async def setup_accessories_from_file(hass, path):
char.description = char_data['description'] char.description = char_data['description']
if 'value' in char_data: if 'value' in char_data:
char.value = char_data['value'] char.value = char_data['value']
if 'minValue' in char_data:
char.minValue = char_data['minValue']
if 'maxValue' in char_data:
char.maxValue = char_data['maxValue']
if 'valid-values' in char_data:
char.valid_values = char_data['valid-values']
service.characteristics.append(char) service.characteristics.append(char)
accessory.services.append(service) accessory.services.append(service)

View file

@ -10,6 +10,7 @@ from homekit import AccessoryDisconnectedError
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY, SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY,
SUPPORT_TARGET_HUMIDITY_HIGH, SUPPORT_TARGET_HUMIDITY_LOW,
SUPPORT_OPERATION_MODE) SUPPORT_OPERATION_MODE)
from tests.components.homekit_controller.common import ( from tests.components.homekit_controller.common import (
FakePairing, device_config_changed, setup_accessories_from_file, FakePairing, device_config_changed, setup_accessories_from_file,
@ -32,9 +33,15 @@ async def test_ecobee3_setup(hass):
assert climate_state.attributes['friendly_name'] == 'HomeW' assert climate_state.attributes['friendly_name'] == 'HomeW'
assert climate_state.attributes['supported_features'] == ( assert climate_state.attributes['supported_features'] == (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY | SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY |
SUPPORT_TARGET_HUMIDITY_HIGH | SUPPORT_TARGET_HUMIDITY_LOW |
SUPPORT_OPERATION_MODE SUPPORT_OPERATION_MODE
) )
assert climate_state.attributes['min_temp'] == 7.2
assert climate_state.attributes['max_temp'] == 33.3
assert climate_state.attributes['min_humidity'] == 20
assert climate_state.attributes['max_humidity'] == 50
occ1 = entity_registry.async_get('binary_sensor.kitchen') occ1 = entity_registry.async_get('binary_sensor.kitchen')
assert occ1.unique_id == 'homekit-AB1C-56' assert occ1.unique_id == 'homekit-AB1C-56'

View file

@ -138,6 +138,8 @@ async def test_climate_read_thermostat_state(hass, utcnow):
assert state.state == 'heat' assert state.state == 'heat'
assert state.attributes['current_temperature'] == 19 assert state.attributes['current_temperature'] == 19
assert state.attributes['current_humidity'] == 50 assert state.attributes['current_humidity'] == 50
assert state.attributes['min_temp'] == 7
assert state.attributes['max_temp'] == 35
# Simulate that cooling is on # Simulate that cooling is on
helper.characteristics[TEMPERATURE_CURRENT].value = 21 helper.characteristics[TEMPERATURE_CURRENT].value = 21