mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Update plugwise to async and config_flow binary_sensor part (#36378)
* Add binary_sensor component * Version bump * Blushing commit - tnx @bdraco
This commit is contained in:
parent
26cbca101a
commit
c68e0a1d46
@ -604,6 +604,7 @@ omit =
|
|||||||
homeassistant/components/plex/media_player.py
|
homeassistant/components/plex/media_player.py
|
||||||
homeassistant/components/plex/sensor.py
|
homeassistant/components/plex/sensor.py
|
||||||
homeassistant/components/plugwise/__init__.py
|
homeassistant/components/plugwise/__init__.py
|
||||||
|
homeassistant/components/plugwise/binary_sensor.py
|
||||||
homeassistant/components/plugwise/climate.py
|
homeassistant/components/plugwise/climate.py
|
||||||
homeassistant/components/plugwise/sensor.py
|
homeassistant/components/plugwise/sensor.py
|
||||||
homeassistant/components/plum_lightpad/*
|
homeassistant/components/plum_lightpad/*
|
||||||
|
@ -24,7 +24,7 @@ CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SENSOR_PLATFORMS = ["sensor"]
|
SENSOR_PLATFORMS = ["sensor"]
|
||||||
ALL_PLATFORMS = ["climate", "sensor"]
|
ALL_PLATFORMS = ["binary_sensor", "climate", "sensor"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict):
|
async def async_setup(hass: HomeAssistant, config: dict):
|
||||||
|
96
homeassistant/components/plugwise/binary_sensor.py
Normal file
96
homeassistant/components/plugwise/binary_sensor.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
"""Plugwise Binary Sensor component for Home Assistant."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||||
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
|
from homeassistant.core import callback
|
||||||
|
|
||||||
|
from .const import DOMAIN, FLAME_ICON, FLOW_OFF_ICON, FLOW_ON_ICON, IDLE_ICON
|
||||||
|
from .sensor import SmileSensor
|
||||||
|
|
||||||
|
BINARY_SENSOR_MAP = {
|
||||||
|
"dhw_state": ["Domestic Hot Water State", None],
|
||||||
|
"slave_boiler_state": ["Secondary Heater Device State", None],
|
||||||
|
}
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
|
"""Set up the Smile binary_sensors from a config entry."""
|
||||||
|
api = hass.data[DOMAIN][config_entry.entry_id]["api"]
|
||||||
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"]
|
||||||
|
|
||||||
|
entities = []
|
||||||
|
|
||||||
|
all_devices = api.get_all_devices()
|
||||||
|
for dev_id, device_properties in all_devices.items():
|
||||||
|
if device_properties["class"] == "heater_central":
|
||||||
|
data = api.get_device_data(dev_id)
|
||||||
|
for binary_sensor, dummy in BINARY_SENSOR_MAP.items():
|
||||||
|
if binary_sensor in data:
|
||||||
|
entities.append(
|
||||||
|
PwBinarySensor(
|
||||||
|
api,
|
||||||
|
coordinator,
|
||||||
|
device_properties["name"],
|
||||||
|
binary_sensor,
|
||||||
|
dev_id,
|
||||||
|
device_properties["class"],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
|
||||||
|
class PwBinarySensor(SmileSensor, BinarySensorEntity):
|
||||||
|
"""Representation of a Plugwise binary_sensor."""
|
||||||
|
|
||||||
|
def __init__(self, api, coordinator, name, binary_sensor, dev_id, model):
|
||||||
|
"""Set up the Plugwise API."""
|
||||||
|
super().__init__(api, coordinator, name, dev_id, binary_sensor)
|
||||||
|
|
||||||
|
self._binary_sensor = binary_sensor
|
||||||
|
|
||||||
|
self._is_on = False
|
||||||
|
self._icon = None
|
||||||
|
|
||||||
|
self._unique_id = f"{dev_id}-{binary_sensor}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""Return true if the binary sensor is on."""
|
||||||
|
return self._is_on
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Return the icon to use in the frontend."""
|
||||||
|
return self._icon
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_process_data(self):
|
||||||
|
"""Update the entity."""
|
||||||
|
data = self._api.get_device_data(self._dev_id)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
_LOGGER.error("Received no data for device %s.", self._binary_sensor)
|
||||||
|
self.async_write_ha_state()
|
||||||
|
return
|
||||||
|
|
||||||
|
if self._binary_sensor in data:
|
||||||
|
self._is_on = data[self._binary_sensor]
|
||||||
|
|
||||||
|
self._state = STATE_OFF
|
||||||
|
if self._binary_sensor == "dhw_state":
|
||||||
|
self._icon = FLOW_OFF_ICON
|
||||||
|
if self._binary_sensor == "slave_boiler_state":
|
||||||
|
self._icon = IDLE_ICON
|
||||||
|
if self._is_on:
|
||||||
|
self._state = STATE_ON
|
||||||
|
if self._binary_sensor == "dhw_state":
|
||||||
|
self._icon = FLOW_ON_ICON
|
||||||
|
if self._binary_sensor == "slave_boiler_state":
|
||||||
|
self._icon = FLAME_ICON
|
||||||
|
|
||||||
|
self.async_write_ha_state()
|
@ -37,3 +37,5 @@ SCHEDULE_OFF = "false"
|
|||||||
COOL_ICON = "mdi:snowflake"
|
COOL_ICON = "mdi:snowflake"
|
||||||
FLAME_ICON = "mdi:fire"
|
FLAME_ICON = "mdi:fire"
|
||||||
IDLE_ICON = "mdi:circle-off-outline"
|
IDLE_ICON = "mdi:circle-off-outline"
|
||||||
|
FLOW_OFF_ICON = "mdi:water-pump-off"
|
||||||
|
FLOW_ON_ICON = "mdi:water-pump"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "plugwise",
|
"domain": "plugwise",
|
||||||
"name": "Plugwise",
|
"name": "Plugwise",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/plugwise",
|
"documentation": "https://www.home-assistant.io/integrations/plugwise",
|
||||||
"requirements": ["Plugwise_Smile==0.2.10"],
|
"requirements": ["Plugwise_Smile==0.2.13"],
|
||||||
"codeowners": ["@CoMPaTech", "@bouwew"],
|
"codeowners": ["@CoMPaTech", "@bouwew"],
|
||||||
"config_flow": true
|
"config_flow": true
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ Mastodon.py==1.5.1
|
|||||||
OPi.GPIO==0.4.0
|
OPi.GPIO==0.4.0
|
||||||
|
|
||||||
# homeassistant.components.plugwise
|
# homeassistant.components.plugwise
|
||||||
Plugwise_Smile==0.2.10
|
Plugwise_Smile==0.2.13
|
||||||
|
|
||||||
# homeassistant.components.essent
|
# homeassistant.components.essent
|
||||||
PyEssent==0.13
|
PyEssent==0.13
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
HAP-python==2.9.1
|
HAP-python==2.9.1
|
||||||
|
|
||||||
# homeassistant.components.plugwise
|
# homeassistant.components.plugwise
|
||||||
Plugwise_Smile==0.2.10
|
Plugwise_Smile==0.2.13
|
||||||
|
|
||||||
# homeassistant.components.flick_electric
|
# homeassistant.components.flick_electric
|
||||||
PyFlick==0.0.2
|
PyFlick==0.0.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user