Files
home-assistant-core/homeassistant/components/xs1/climate.py
T
Markus Ressel 542f024356 XS1 component (#19115)
* added xs1 main component
added implementations for switch, sensor, climate and binary_sensor

* updated code
fixed styling
added comments
removed binary_sensor (wasn't working)

* ran "gen_requirements_all.py" script

* fixed linting issues

* added config options for port and ssl
small fixes

* use already defined config constants instead of defining new ones

* avoid passing in hass to the entity

* use async keyword and proper asyncio calls
limit updates with a global lock to prevent overwhelming the gateway with concurrent requests
change info logger calls to debug

* update dependency

* removed unneeded constant

* fix lint issues

* updated requirements

* removed unused imports

* fixed some flake8 errors

* fixed some flake8 errors

* changed imports to absolute paths

* fixed some lint errors

* fixed some lint errors

* fix update of attached sensor

* reordered imports
added config defaults
check if platform is available
changed docstring

* lint fix

* review fixes

* isort

* import fix

* review fix

* review fix

* review fix

* removed unused imports

* lint fix

* lint fix

* climate fix
exclude sensors that will be used in climate component from default sensor category

* .coveragerc fix

* lint fix

* moved platform to it's own package
2019-02-07 23:21:41 +01:00

110 lines
3.0 KiB
Python

"""
Support for XS1 climate devices.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/climate.xs1/
"""
from functools import partial
import logging
from homeassistant.components.climate import (
ATTR_TEMPERATURE, ClimateDevice, SUPPORT_TARGET_TEMPERATURE)
from homeassistant.components.xs1 import (
ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity)
DEPENDENCIES = ['xs1']
_LOGGER = logging.getLogger(__name__)
MIN_TEMP = 8
MAX_TEMP = 25
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the XS1 thermostat platform."""
from xs1_api_client.api_constants import ActuatorType
actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
sensors = hass.data[COMPONENT_DOMAIN][SENSORS]
thermostat_entities = []
for actuator in actuators:
if actuator.type() == ActuatorType.TEMPERATURE:
# Search for a matching sensor (by name)
actuator_name = actuator.name()
matching_sensor = None
for sensor in sensors:
if actuator_name in sensor.name():
matching_sensor = sensor
break
thermostat_entities.append(
XS1ThermostatEntity(actuator, matching_sensor))
async_add_entities(thermostat_entities)
class XS1ThermostatEntity(XS1DeviceEntity, ClimateDevice):
"""Representation of a XS1 thermostat."""
def __init__(self, device, sensor):
"""Initialize the actuator."""
super().__init__(device)
self.sensor = sensor
@property
def name(self):
"""Return the name of the device if any."""
return self.device.name()
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_TARGET_TEMPERATURE
@property
def current_temperature(self):
"""Return the current temperature."""
if self.sensor is None:
return None
return self.sensor.value()
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return self.device.unit()
@property
def target_temperature(self):
"""Return the current target temperature."""
return self.device.new_value()
@property
def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMP
@property
def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMP
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temp = kwargs.get(ATTR_TEMPERATURE)
self.device.set_value(temp)
if self.sensor is not None:
self.schedule_update_ha_state()
async def async_update(self):
"""Also update the sensor when available."""
await super().async_update()
if self.sensor is not None:
await self.hass.async_add_executor_job(
partial(self.sensor.update))