Update plugwise 0.16.2 (#65933)

This commit is contained in:
Franck Nijhof 2022-02-08 11:13:05 +01:00 committed by GitHub
parent 0ea82bdbfb
commit d12a392767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 837 additions and 317 deletions

View file

@ -50,35 +50,33 @@ async def async_setup_entry(
config_entry.entry_id
][COORDINATOR]
entities: list[BinarySensorEntity] = []
is_thermostat = api.single_master_thermostat()
all_devices = api.get_all_devices()
for dev_id, device_properties in all_devices.items():
entities: list[PlugwiseBinarySensorEntity] = []
for device_id, device_properties in coordinator.data.devices.items():
if device_properties["class"] == "heater_central":
data = api.get_device_data(dev_id)
for description in BINARY_SENSORS:
if description.key not in data:
if (
"binary_sensors" not in device_properties
or description.key not in device_properties["binary_sensors"]
):
continue
entities.append(
PwBinarySensor(
PlugwiseBinarySensorEntity(
api,
coordinator,
device_properties["name"],
dev_id,
device_id,
description,
)
)
if device_properties["class"] == "gateway" and is_thermostat is not None:
if device_properties["class"] == "gateway":
entities.append(
PwNotifySensor(
PlugwiseNotifyBinarySensorEntity(
api,
coordinator,
device_properties["name"],
dev_id,
device_id,
BinarySensorEntityDescription(
key="plugwise_notification",
name="Plugwise Notification",
@ -89,7 +87,7 @@ async def async_setup_entry(
async_add_entities(entities, True)
class SmileBinarySensor(PlugwiseEntity, BinarySensorEntity):
class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity):
"""Represent Smile Binary Sensors."""
def __init__(
@ -106,36 +104,23 @@ class SmileBinarySensor(PlugwiseEntity, BinarySensorEntity):
self._attr_is_on = False
self._attr_unique_id = f"{dev_id}-{description.key}"
if dev_id == self._api.heater_id:
if dev_id == coordinator.data.gateway["heater_id"]:
self._entity_name = "Auxiliary"
self._name = f"{self._entity_name} {description.name}"
if dev_id == self._api.gateway_id:
if dev_id == coordinator.data.gateway["gateway_id"]:
self._entity_name = f"Smile {self._entity_name}"
@callback
def _async_process_data(self) -> None:
"""Update the entity."""
raise NotImplementedError
class PwBinarySensor(SmileBinarySensor):
"""Representation of a Plugwise binary_sensor."""
@callback
def _async_process_data(self) -> None:
"""Update the entity."""
if not (data := self._api.get_device_data(self._dev_id)):
if not (data := self.coordinator.data.devices.get(self._dev_id)):
LOGGER.error("Received no data for device %s", self._dev_id)
self.async_write_ha_state()
return
if self.entity_description.key not in data:
self.async_write_ha_state()
return
self._attr_is_on = data[self.entity_description.key]
self._attr_is_on = data["binary_sensors"].get(self.entity_description.key)
if self.entity_description.key == "dhw_state":
self._attr_icon = FLOW_ON_ICON if self._attr_is_on else FLOW_OFF_ICON
@ -145,27 +130,15 @@ class PwBinarySensor(SmileBinarySensor):
self.async_write_ha_state()
class PwNotifySensor(SmileBinarySensor):
class PlugwiseNotifyBinarySensorEntity(PlugwiseBinarySensorEntity):
"""Representation of a Plugwise Notification binary_sensor."""
def __init__(
self,
api: Smile,
coordinator: PlugwiseDataUpdateCoordinator,
name: str,
dev_id: str,
description: BinarySensorEntityDescription,
) -> None:
"""Set up the Plugwise API."""
super().__init__(api, coordinator, name, dev_id, description)
self._attr_extra_state_attributes = {}
@callback
def _async_process_data(self) -> None:
"""Update the entity."""
notify = self._api.notifications
notify = self.coordinator.data.gateway["notifications"]
self._attr_extra_state_attributes = {}
for severity in SEVERITIES:
self._attr_extra_state_attributes[f"{severity}_msg"] = []