Add iaqualink binary sensor and unique_id (#26616)
* Add binary_platform to iaqualink integration, add unique_id * Revert Mixin changes, move self.dev to AqualinkEntity * Style fixes
This commit is contained in:
parent
bca7363a80
commit
a71cd6e90e
7 changed files with 74 additions and 31 deletions
|
@ -289,6 +289,7 @@ omit =
|
|||
homeassistant/components/hydrawise/*
|
||||
homeassistant/components/hyperion/light.py
|
||||
homeassistant/components/ialarm/alarm_control_panel.py
|
||||
homeassistant/components/iaqualink/binary_sensor.py
|
||||
homeassistant/components/iaqualink/climate.py
|
||||
homeassistant/components/iaqualink/light.py
|
||||
homeassistant/components/iaqualink/sensor.py
|
||||
|
|
|
@ -7,7 +7,9 @@ from aiohttp import CookieJar
|
|||
import voluptuous as vol
|
||||
|
||||
from iaqualink import (
|
||||
AqualinkBinarySensor,
|
||||
AqualinkClient,
|
||||
AqualinkDevice,
|
||||
AqualinkLight,
|
||||
AqualinkLoginException,
|
||||
AqualinkSensor,
|
||||
|
@ -16,6 +18,7 @@ from iaqualink import (
|
|||
)
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
|
@ -76,6 +79,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None
|
|||
password = entry.data[CONF_PASSWORD]
|
||||
|
||||
# These will contain the initialized devices
|
||||
binary_sensors = hass.data[DOMAIN][BINARY_SENSOR_DOMAIN] = []
|
||||
climates = hass.data[DOMAIN][CLIMATE_DOMAIN] = []
|
||||
lights = hass.data[DOMAIN][LIGHT_DOMAIN] = []
|
||||
sensors = hass.data[DOMAIN][SENSOR_DOMAIN] = []
|
||||
|
@ -103,12 +107,17 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None
|
|||
climates += [dev]
|
||||
elif isinstance(dev, AqualinkLight):
|
||||
lights += [dev]
|
||||
elif isinstance(dev, AqualinkBinarySensor):
|
||||
binary_sensors += [dev]
|
||||
elif isinstance(dev, AqualinkSensor):
|
||||
sensors += [dev]
|
||||
elif isinstance(dev, AqualinkToggle):
|
||||
switches += [dev]
|
||||
|
||||
forward_setup = hass.config_entries.async_forward_entry_setup
|
||||
if binary_sensors:
|
||||
_LOGGER.debug("Got %s binary sensors: %s", len(binary_sensors), binary_sensors)
|
||||
hass.async_create_task(forward_setup(entry, BINARY_SENSOR_DOMAIN))
|
||||
if climates:
|
||||
_LOGGER.debug("Got %s climates: %s", len(climates), climates)
|
||||
hass.async_create_task(forward_setup(entry, CLIMATE_DOMAIN))
|
||||
|
@ -138,6 +147,8 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo
|
|||
|
||||
tasks = []
|
||||
|
||||
if hass.data[DOMAIN][BINARY_SENSOR_DOMAIN]:
|
||||
tasks += [forward_unload(entry, BINARY_SENSOR_DOMAIN)]
|
||||
if hass.data[DOMAIN][CLIMATE_DOMAIN]:
|
||||
tasks += [forward_unload(entry, CLIMATE_DOMAIN)]
|
||||
if hass.data[DOMAIN][LIGHT_DOMAIN]:
|
||||
|
@ -174,6 +185,10 @@ class AqualinkEntity(Entity):
|
|||
class.
|
||||
"""
|
||||
|
||||
def __init__(self, dev: AqualinkDevice):
|
||||
"""Initialize the entity."""
|
||||
self.dev = dev
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Set up a listener when this entity is added to HA."""
|
||||
async_dispatcher_connect(self.hass, DOMAIN, self._update_callback)
|
||||
|
@ -190,3 +205,8 @@ class AqualinkEntity(Entity):
|
|||
updates on a timer.
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique identifier for this entity."""
|
||||
return f"{self.dev.system.serial}_{self.dev.name}"
|
||||
|
|
48
homeassistant/components/iaqualink/binary_sensor.py
Normal file
48
homeassistant/components/iaqualink/binary_sensor.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
"""Support for Aqualink temperature sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDevice,
|
||||
DEVICE_CLASS_COLD,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from . import AqualinkEntity
|
||||
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
|
||||
) -> None:
|
||||
"""Set up discovered binary sensors."""
|
||||
devs = []
|
||||
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
|
||||
devs.append(HassAqualinkBinarySensor(dev))
|
||||
async_add_entities(devs, True)
|
||||
|
||||
|
||||
class HassAqualinkBinarySensor(AqualinkEntity, BinarySensorDevice):
|
||||
"""Representation of a binary sensor."""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the binary sensor."""
|
||||
return self.dev.label
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return whether the binary sensor is on or not."""
|
||||
return self.dev.is_on
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
"""Return the class of the binary sensor."""
|
||||
if self.name == "Freeze Protection":
|
||||
return DEVICE_CLASS_COLD
|
||||
return None
|
|
@ -2,13 +2,7 @@
|
|||
import logging
|
||||
from typing import List, Optional
|
||||
|
||||
from iaqualink import (
|
||||
AqualinkState,
|
||||
AqualinkHeater,
|
||||
AqualinkPump,
|
||||
AqualinkSensor,
|
||||
AqualinkThermostat,
|
||||
)
|
||||
from iaqualink import AqualinkHeater, AqualinkPump, AqualinkSensor, AqualinkState
|
||||
from iaqualink.const import (
|
||||
AQUALINK_TEMP_CELSIUS_HIGH,
|
||||
AQUALINK_TEMP_CELSIUS_LOW,
|
||||
|
@ -45,13 +39,9 @@ async def async_setup_entry(
|
|||
async_add_entities(devs, True)
|
||||
|
||||
|
||||
class HassAqualinkThermostat(ClimateDevice, AqualinkEntity):
|
||||
class HassAqualinkThermostat(AqualinkEntity, ClimateDevice):
|
||||
"""Representation of a thermostat."""
|
||||
|
||||
def __init__(self, dev: AqualinkThermostat):
|
||||
"""Initialize the thermostat."""
|
||||
self.dev = dev
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the thermostat."""
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Support for Aqualink pool lights."""
|
||||
import logging
|
||||
|
||||
from iaqualink import AqualinkLight, AqualinkLightEffect
|
||||
from iaqualink import AqualinkLightEffect
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
|
@ -32,13 +32,9 @@ async def async_setup_entry(
|
|||
async_add_entities(devs, True)
|
||||
|
||||
|
||||
class HassAqualinkLight(Light, AqualinkEntity):
|
||||
class HassAqualinkLight(AqualinkEntity, Light):
|
||||
"""Representation of a light."""
|
||||
|
||||
def __init__(self, dev: AqualinkLight):
|
||||
"""Initialize the light."""
|
||||
self.dev = dev
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the light."""
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
import logging
|
||||
from typing import Optional
|
||||
|
||||
from iaqualink import AqualinkSensor
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
|
@ -30,10 +28,6 @@ async def async_setup_entry(
|
|||
class HassAqualinkSensor(AqualinkEntity):
|
||||
"""Representation of a sensor."""
|
||||
|
||||
def __init__(self, dev: AqualinkSensor):
|
||||
"""Initialize the sensor."""
|
||||
self.dev = dev
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the sensor."""
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Support for Aqualink pool feature switches."""
|
||||
import logging
|
||||
|
||||
from iaqualink import AqualinkToggle
|
||||
|
||||
from homeassistant.components.switch import DOMAIN, SwitchDevice
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
@ -25,13 +23,9 @@ async def async_setup_entry(
|
|||
async_add_entities(devs, True)
|
||||
|
||||
|
||||
class HassAqualinkSwitch(SwitchDevice, AqualinkEntity):
|
||||
class HassAqualinkSwitch(AqualinkEntity, SwitchDevice):
|
||||
"""Representation of a switch."""
|
||||
|
||||
def __init__(self, dev: AqualinkToggle):
|
||||
"""Initialize the switch."""
|
||||
self.dev = dev
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the switch."""
|
||||
|
|
Loading…
Add table
Reference in a new issue