Add support of multiple Tado accounts (#31527)

* Added support of multiple Tado accounts
Changed geberation of sensor unique id (breaking change)

* Fixed lints

* Fixed error detecting opened window

* Changed gereration of unique id of climate

* Removed commented code and added comments
This commit is contained in:
Victor Vostrikov authored and GitHub committed 2020-02-11 08:46:02 -08:00
1 parent 8a6158116a
commit 3df2cb6b78
4 files changed
+93 -83

No files matched your search

+31 -35
View File
@@ -6,7 +6,7 @@ from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
from . import DOMAIN, SIGNAL_TADO_UPDATE_RECEIVED
from . import DATA, DOMAIN, SIGNAL_TADO_UPDATE_RECEIVED
from .const import TYPE_AIR_CONDITIONING, TYPE_HEATING, TYPE_HOT_WATER
_LOGGER = logging.getLogger(__name__)
@@ -40,26 +40,29 @@ DEVICE_SENSORS = ["tado bridge status"]
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the sensor platform."""
tado = hass.data[DOMAIN]
api_list = hass.data[DOMAIN][DATA]
# Create zone sensors
entities = []
for zone in tado.zones:
entities.extend(
[
create_zone_sensor(tado, zone["name"], zone["id"], variable)
for variable in ZONE_SENSORS.get(zone["type"])
]
)
# Create device sensors
for home in tado.devices:
entities.extend(
[
create_device_sensor(tado, home["name"], home["id"], variable)
for variable in DEVICE_SENSORS
]
)
for tado in api_list:
# Create zone sensors
for zone in tado.zones:
entities.extend(
[
create_zone_sensor(tado, zone["name"], zone["id"], variable)
for variable in ZONE_SENSORS.get(zone["type"])
]
)
# Create device sensors
for home in tado.devices:
entities.extend(
[
create_device_sensor(tado, home["name"], home["id"], variable)
for variable in DEVICE_SENSORS
]
)
add_entities(entities, True)
@@ -86,7 +89,7 @@ class TadoSensor(Entity):
self.zone_variable = zone_variable
self.sensor_type = sensor_type
self._unique_id = f"{zone_variable} {zone_id}"
self._unique_id = f"{zone_variable} {zone_id} {tado.device_id}"
self._state = None
self._state_attributes = None
@@ -227,23 +230,16 @@ class TadoSensor(Entity):
self._state = data["tadoMode"]
elif self.zone_variable == "overlay":
if "overlay" in data and data["overlay"] is not None:
self._state = True
self._state_attributes = {
"termination": data["overlay"]["termination"]["type"]
}
else:
self._state = False
self._state_attributes = {}
self._state = "overlay" in data and data["overlay"] is not None
self._state_attributes = (
{"termination": data["overlay"]["termination"]["type"]}
if self._state
else {}
)
elif self.zone_variable == "early start":
if "preparation" in data and data["preparation"] is not None:
self._state = True
else:
self._state = False
self._state = "preparation" in data and data["preparation"] is not None
elif self.zone_variable == "open window":
if "openWindowDetected" in data:
self._state = data["openWindowDetected"]
else:
self._state = False
self._state = "openWindow" in data and data["openWindow"] is not None
self._state_attributes = data["openWindow"] if self._state else {}