Improve tracking of existing entities in deconz (#40265)

* Store all entities in dict

* Use stored unique id to select if to create entity or not

* Remove unnecessary init

* Change so same physical sensor doesnt try to create multiple battery sensors
Change so groups get created properly

* Add controls in tests that entities are logged correctly
This commit is contained in:
Robert Svensson 2020-09-25 22:49:28 +02:00 committed by GitHub
parent e30acfbfee
commit 203c556ba3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 147 additions and 58 deletions

View file

@ -1,7 +1,7 @@
"""Support for deCONZ climate devices."""
from pydeconz.sensor import Thermostat
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import DOMAIN, ClimateEntity
from homeassistant.components.climate.const import (
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
@ -29,17 +29,18 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
Thermostats are based on the same device class as sensors in deCONZ.
"""
gateway = get_gateway_from_config_entry(hass, config_entry)
gateway.entities[DOMAIN] = set()
@callback
def async_add_climate(sensors, new=True):
def async_add_climate(sensors):
"""Add climate devices from deCONZ."""
entities = []
for sensor in sensors:
if (
new
and sensor.type in Thermostat.ZHATYPE
sensor.type in Thermostat.ZHATYPE
and sensor.uniqueid not in gateway.entities[DOMAIN]
and (
gateway.option_allow_clip_sensor
or not sensor.type.startswith("CLIP")
@ -61,6 +62,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class DeconzThermostat(DeconzDevice, ClimateEntity):
"""Representation of a deCONZ thermostat."""
TYPE = DOMAIN
@property
def supported_features(self):
"""Return the list of supported features."""