deCONZ thermostat support (#20586)
* Add support for thermostats in deCONZ by adding Climate platform
This commit is contained in:
1 parent
3f9e6a7064
commit
9ce8f4737d
16 files changed
+347
-35
No files matched your search
@@ -12,10 +12,7 @@ from .config_flow import configured_hosts
|
||||
from .const import DEFAULT_PORT, DOMAIN, _LOGGER
|
||||
from .gateway import DeconzGateway
|
||||
|
||||
REQUIREMENTS = ['pydeconz==47']
|
||||
|
||||
SUPPORTED_PLATFORMS = ['binary_sensor', 'cover',
|
||||
'light', 'scene', 'sensor', 'switch']
|
||||
REQUIREMENTS = ['pydeconz==52']
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
|
||||
@@ -5,7 +5,8 @@ from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import (
|
||||
ATTR_DARK, ATTR_ON, CONF_ALLOW_CLIP_SENSOR, DOMAIN as DECONZ_DOMAIN)
|
||||
ATTR_DARK, ATTR_ON, CONF_ALLOW_CLIP_SENSOR, DOMAIN as DECONZ_DOMAIN,
|
||||
NEW_SENSOR)
|
||||
from .deconz_device import DeconzDevice
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
@@ -34,7 +35,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_sensor', async_add_sensor))
|
||||
async_dispatcher_connect(hass, NEW_SENSOR, async_add_sensor))
|
||||
|
||||
async_add_sensor(gateway.api.sensors.values())
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
"""Support for deCONZ climate devices."""
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
SUPPORT_ON_OFF, SUPPORT_TARGET_TEMPERATURE)
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL, ATTR_TEMPERATURE, TEMP_CELSIUS)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import (
|
||||
ATTR_OFFSET, ATTR_VALVE, CONF_ALLOW_CLIP_SENSOR,
|
||||
DOMAIN as DECONZ_DOMAIN, NEW_SENSOR)
|
||||
from .deconz_device import DeconzDevice
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the deCONZ climate devices.
|
||||
|
||||
Thermostats are based on the same device class as sensors in deCONZ.
|
||||
"""
|
||||
gateway = hass.data[DECONZ_DOMAIN]
|
||||
|
||||
@callback
|
||||
def async_add_climate(sensors):
|
||||
"""Add climate devices from deCONZ."""
|
||||
from pydeconz.sensor import THERMOSTAT
|
||||
entities = []
|
||||
allow_clip_sensor = config_entry.data.get(CONF_ALLOW_CLIP_SENSOR, True)
|
||||
for sensor in sensors:
|
||||
if sensor.type in THERMOSTAT and \
|
||||
not (not allow_clip_sensor and sensor.type.startswith('CLIP')):
|
||||
entities.append(DeconzThermostat(sensor, gateway))
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, NEW_SENSOR, async_add_climate))
|
||||
|
||||
async_add_climate(gateway.api.sensors.values())
|
||||
|
||||
|
||||
class DeconzThermostat(DeconzDevice, ClimateDevice):
|
||||
"""Representation of a deCONZ thermostat."""
|
||||
|
||||
def __init__(self, device, gateway):
|
||||
"""Set up thermostat device."""
|
||||
super().__init__(device, gateway)
|
||||
|
||||
self._features = SUPPORT_ON_OFF
|
||||
self._features |= SUPPORT_TARGET_TEMPERATURE
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
return self._features
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if on."""
|
||||
return self._device.on
|
||||
|
||||
async def async_turn_on(self):
|
||||
"""Turn on switch."""
|
||||
data = {'mode': 'auto'}
|
||||
await self._device.async_set_config(data)
|
||||
|
||||
async def async_turn_off(self):
|
||||
"""Turn off switch."""
|
||||
data = {'mode': 'off'}
|
||||
await self._device.async_set_config(data)
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
"""Return the current temperature."""
|
||||
return self._device.temperature
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
"""Return the target temperature."""
|
||||
return self._device.heatsetpoint
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
"""Set new target temperature."""
|
||||
data = {}
|
||||
|
||||
if ATTR_TEMPERATURE in kwargs:
|
||||
data['heatsetpoint'] = kwargs[ATTR_TEMPERATURE] * 100
|
||||
|
||||
await self._device.async_set_config(data)
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_CELSIUS
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the thermostat."""
|
||||
attr = {}
|
||||
|
||||
if self._device.battery:
|
||||
attr[ATTR_BATTERY_LEVEL] = self._device.battery
|
||||
|
||||
if self._device.offset:
|
||||
attr[ATTR_OFFSET] = self._device.offset
|
||||
|
||||
if self._device.valve is not None:
|
||||
attr[ATTR_VALVE] = self._device.valve
|
||||
|
||||
return attr
|
||||
@@ -10,13 +10,27 @@ DEFAULT_PORT = 80
|
||||
CONF_ALLOW_CLIP_SENSOR = 'allow_clip_sensor'
|
||||
CONF_ALLOW_DECONZ_GROUPS = 'allow_deconz_groups'
|
||||
|
||||
SUPPORTED_PLATFORMS = ['binary_sensor', 'cover',
|
||||
SUPPORTED_PLATFORMS = ['binary_sensor', 'climate', 'cover',
|
||||
'light', 'scene', 'sensor', 'switch']
|
||||
|
||||
DECONZ_REACHABLE = 'deconz_reachable'
|
||||
|
||||
NEW_GROUP = 'deconz_new_group'
|
||||
NEW_LIGHT = 'deconz_new_light'
|
||||
NEW_SCENE = 'deconz_new_scene'
|
||||
NEW_SENSOR = 'deconz_new_sensor'
|
||||
|
||||
NEW_DEVICE = {
|
||||
'group': NEW_GROUP,
|
||||
'light': NEW_LIGHT,
|
||||
'scene': NEW_SCENE,
|
||||
'sensor': NEW_SENSOR
|
||||
}
|
||||
|
||||
ATTR_DARK = 'dark'
|
||||
ATTR_OFFSET = 'offset'
|
||||
ATTR_ON = 'on'
|
||||
ATTR_VALVE = 'valve'
|
||||
|
||||
DAMPERS = ["Level controllable output"]
|
||||
WINDOW_COVERS = ["Window covering device"]
|
||||
|
||||
@@ -5,7 +5,8 @@ from homeassistant.components.cover import (
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import COVER_TYPES, DAMPERS, DOMAIN as DECONZ_DOMAIN, WINDOW_COVERS
|
||||
from .const import (
|
||||
COVER_TYPES, DAMPERS, DOMAIN as DECONZ_DOMAIN, NEW_LIGHT, WINDOW_COVERS)
|
||||
from .deconz_device import DeconzDevice
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
@@ -39,7 +40,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_light', async_add_cover))
|
||||
async_dispatcher_connect(hass, NEW_LIGHT, async_add_cover))
|
||||
|
||||
async_add_cover(gateway.api.lights.values())
|
||||
|
||||
@@ -48,7 +49,7 @@ class DeconzCover(DeconzDevice, CoverDevice):
|
||||
"""Representation of a deCONZ cover."""
|
||||
|
||||
def __init__(self, device, gateway):
|
||||
"""Set up cover and add update callback to get data from websocket."""
|
||||
"""Set up cover device."""
|
||||
super().__init__(device, gateway)
|
||||
|
||||
self._features = SUPPORT_OPEN
|
||||
|
||||
@@ -8,7 +8,8 @@ from homeassistant.helpers.dispatcher import (
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import (
|
||||
_LOGGER, DECONZ_REACHABLE, CONF_ALLOW_CLIP_SENSOR, SUPPORTED_PLATFORMS)
|
||||
_LOGGER, DECONZ_REACHABLE, CONF_ALLOW_CLIP_SENSOR, NEW_DEVICE, NEW_SENSOR,
|
||||
SUPPORTED_PLATFORMS)
|
||||
|
||||
|
||||
class DeconzGateway:
|
||||
@@ -44,7 +45,7 @@ class DeconzGateway:
|
||||
|
||||
self.listeners.append(
|
||||
async_dispatcher_connect(
|
||||
hass, 'deconz_new_sensor', self.async_add_remote))
|
||||
hass, NEW_SENSOR, self.async_add_remote))
|
||||
|
||||
self.async_add_remote(self.api.sensors.values())
|
||||
|
||||
@@ -64,8 +65,7 @@ class DeconzGateway:
|
||||
"""Handle event of new device creation in deCONZ."""
|
||||
if not isinstance(device, list):
|
||||
device = [device]
|
||||
async_dispatcher_send(
|
||||
self.hass, 'deconz_new_{}'.format(device_type), device)
|
||||
async_dispatcher_send(self.hass, NEW_DEVICE[device_type], device)
|
||||
|
||||
@callback
|
||||
def async_add_remote(self, sensors):
|
||||
|
||||
@@ -9,8 +9,8 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
from .const import (
|
||||
CONF_ALLOW_DECONZ_GROUPS, DOMAIN as DECONZ_DOMAIN, COVER_TYPES,
|
||||
SWITCH_TYPES)
|
||||
CONF_ALLOW_DECONZ_GROUPS, DOMAIN as DECONZ_DOMAIN, COVER_TYPES, NEW_GROUP,
|
||||
NEW_LIGHT, SWITCH_TYPES)
|
||||
from .deconz_device import DeconzDevice
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
@@ -36,7 +36,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_light', async_add_light))
|
||||
async_dispatcher_connect(hass, NEW_LIGHT, async_add_light))
|
||||
|
||||
@callback
|
||||
def async_add_group(groups):
|
||||
@@ -49,7 +49,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_group', async_add_group))
|
||||
async_dispatcher_connect(hass, NEW_GROUP, async_add_group))
|
||||
|
||||
async_add_light(gateway.api.lights.values())
|
||||
async_add_group(gateway.api.groups.values())
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"""Support for deCONZ scenes."""
|
||||
from homeassistant.components.deconz import DOMAIN as DECONZ_DOMAIN
|
||||
from homeassistant.components.scene import Scene
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import DOMAIN as DECONZ_DOMAIN, NEW_SCENE
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
|
||||
|
||||
@@ -25,7 +26,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
entities.append(DeconzScene(scene, gateway))
|
||||
async_add_entities(entities)
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_scene', async_add_scene))
|
||||
async_dispatcher_connect(hass, NEW_SCENE, async_add_scene))
|
||||
|
||||
async_add_scene(gateway.api.scenes.values())
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import (
|
||||
ATTR_DARK, ATTR_ON, CONF_ALLOW_CLIP_SENSOR, DOMAIN as DECONZ_DOMAIN)
|
||||
ATTR_DARK, ATTR_ON, CONF_ALLOW_CLIP_SENSOR, DOMAIN as DECONZ_DOMAIN,
|
||||
NEW_SENSOR)
|
||||
from .deconz_device import DeconzDevice
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
@@ -29,7 +30,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
@callback
|
||||
def async_add_sensor(sensors):
|
||||
"""Add sensors from deCONZ."""
|
||||
from pydeconz.sensor import DECONZ_SENSOR, SWITCH as DECONZ_REMOTE
|
||||
from pydeconz.sensor import (
|
||||
DECONZ_SENSOR, SWITCH as DECONZ_REMOTE)
|
||||
entities = []
|
||||
allow_clip_sensor = config_entry.data.get(CONF_ALLOW_CLIP_SENSOR, True)
|
||||
for sensor in sensors:
|
||||
@@ -43,7 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_sensor', async_add_sensor))
|
||||
async_dispatcher_connect(hass, NEW_SENSOR, async_add_sensor))
|
||||
|
||||
async_add_sensor(gateway.api.sensors.values())
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS, SIRENS
|
||||
from .const import DOMAIN as DECONZ_DOMAIN, NEW_LIGHT, POWER_PLUGS, SIRENS
|
||||
from .deconz_device import DeconzDevice
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
@@ -34,7 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_light', async_add_switch))
|
||||
async_dispatcher_connect(hass, NEW_LIGHT, async_add_switch))
|
||||
|
||||
async_add_switch(gateway.api.lights.values())
|
||||
|
||||
|
||||
Reference in new issue
Block a user