mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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
@ -289,6 +289,7 @@ omit =
|
|||||||
homeassistant/components/hydrawise/*
|
homeassistant/components/hydrawise/*
|
||||||
homeassistant/components/hyperion/light.py
|
homeassistant/components/hyperion/light.py
|
||||||
homeassistant/components/ialarm/alarm_control_panel.py
|
homeassistant/components/ialarm/alarm_control_panel.py
|
||||||
|
homeassistant/components/iaqualink/binary_sensor.py
|
||||||
homeassistant/components/iaqualink/climate.py
|
homeassistant/components/iaqualink/climate.py
|
||||||
homeassistant/components/iaqualink/light.py
|
homeassistant/components/iaqualink/light.py
|
||||||
homeassistant/components/iaqualink/sensor.py
|
homeassistant/components/iaqualink/sensor.py
|
||||||
|
@ -7,7 +7,9 @@ from aiohttp import CookieJar
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from iaqualink import (
|
from iaqualink import (
|
||||||
|
AqualinkBinarySensor,
|
||||||
AqualinkClient,
|
AqualinkClient,
|
||||||
|
AqualinkDevice,
|
||||||
AqualinkLight,
|
AqualinkLight,
|
||||||
AqualinkLoginException,
|
AqualinkLoginException,
|
||||||
AqualinkSensor,
|
AqualinkSensor,
|
||||||
@ -16,6 +18,7 @@ from iaqualink import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant import config_entries
|
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.climate import DOMAIN as CLIMATE_DOMAIN
|
||||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_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]
|
password = entry.data[CONF_PASSWORD]
|
||||||
|
|
||||||
# These will contain the initialized devices
|
# These will contain the initialized devices
|
||||||
|
binary_sensors = hass.data[DOMAIN][BINARY_SENSOR_DOMAIN] = []
|
||||||
climates = hass.data[DOMAIN][CLIMATE_DOMAIN] = []
|
climates = hass.data[DOMAIN][CLIMATE_DOMAIN] = []
|
||||||
lights = hass.data[DOMAIN][LIGHT_DOMAIN] = []
|
lights = hass.data[DOMAIN][LIGHT_DOMAIN] = []
|
||||||
sensors = hass.data[DOMAIN][SENSOR_DOMAIN] = []
|
sensors = hass.data[DOMAIN][SENSOR_DOMAIN] = []
|
||||||
@ -103,12 +107,17 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> None
|
|||||||
climates += [dev]
|
climates += [dev]
|
||||||
elif isinstance(dev, AqualinkLight):
|
elif isinstance(dev, AqualinkLight):
|
||||||
lights += [dev]
|
lights += [dev]
|
||||||
|
elif isinstance(dev, AqualinkBinarySensor):
|
||||||
|
binary_sensors += [dev]
|
||||||
elif isinstance(dev, AqualinkSensor):
|
elif isinstance(dev, AqualinkSensor):
|
||||||
sensors += [dev]
|
sensors += [dev]
|
||||||
elif isinstance(dev, AqualinkToggle):
|
elif isinstance(dev, AqualinkToggle):
|
||||||
switches += [dev]
|
switches += [dev]
|
||||||
|
|
||||||
forward_setup = hass.config_entries.async_forward_entry_setup
|
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:
|
if climates:
|
||||||
_LOGGER.debug("Got %s climates: %s", len(climates), climates)
|
_LOGGER.debug("Got %s climates: %s", len(climates), climates)
|
||||||
hass.async_create_task(forward_setup(entry, CLIMATE_DOMAIN))
|
hass.async_create_task(forward_setup(entry, CLIMATE_DOMAIN))
|
||||||
@ -138,6 +147,8 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo
|
|||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
|
if hass.data[DOMAIN][BINARY_SENSOR_DOMAIN]:
|
||||||
|
tasks += [forward_unload(entry, BINARY_SENSOR_DOMAIN)]
|
||||||
if hass.data[DOMAIN][CLIMATE_DOMAIN]:
|
if hass.data[DOMAIN][CLIMATE_DOMAIN]:
|
||||||
tasks += [forward_unload(entry, CLIMATE_DOMAIN)]
|
tasks += [forward_unload(entry, CLIMATE_DOMAIN)]
|
||||||
if hass.data[DOMAIN][LIGHT_DOMAIN]:
|
if hass.data[DOMAIN][LIGHT_DOMAIN]:
|
||||||
@ -174,6 +185,10 @@ class AqualinkEntity(Entity):
|
|||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __init__(self, dev: AqualinkDevice):
|
||||||
|
"""Initialize the entity."""
|
||||||
|
self.dev = dev
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Set up a listener when this entity is added to HA."""
|
"""Set up a listener when this entity is added to HA."""
|
||||||
async_dispatcher_connect(self.hass, DOMAIN, self._update_callback)
|
async_dispatcher_connect(self.hass, DOMAIN, self._update_callback)
|
||||||
@ -190,3 +205,8 @@ class AqualinkEntity(Entity):
|
|||||||
updates on a timer.
|
updates on a timer.
|
||||||
"""
|
"""
|
||||||
return False
|
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
|
import logging
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from iaqualink import (
|
from iaqualink import AqualinkHeater, AqualinkPump, AqualinkSensor, AqualinkState
|
||||||
AqualinkState,
|
|
||||||
AqualinkHeater,
|
|
||||||
AqualinkPump,
|
|
||||||
AqualinkSensor,
|
|
||||||
AqualinkThermostat,
|
|
||||||
)
|
|
||||||
from iaqualink.const import (
|
from iaqualink.const import (
|
||||||
AQUALINK_TEMP_CELSIUS_HIGH,
|
AQUALINK_TEMP_CELSIUS_HIGH,
|
||||||
AQUALINK_TEMP_CELSIUS_LOW,
|
AQUALINK_TEMP_CELSIUS_LOW,
|
||||||
@ -45,13 +39,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(devs, True)
|
async_add_entities(devs, True)
|
||||||
|
|
||||||
|
|
||||||
class HassAqualinkThermostat(ClimateDevice, AqualinkEntity):
|
class HassAqualinkThermostat(AqualinkEntity, ClimateDevice):
|
||||||
"""Representation of a thermostat."""
|
"""Representation of a thermostat."""
|
||||||
|
|
||||||
def __init__(self, dev: AqualinkThermostat):
|
|
||||||
"""Initialize the thermostat."""
|
|
||||||
self.dev = dev
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the thermostat."""
|
"""Return the name of the thermostat."""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Support for Aqualink pool lights."""
|
"""Support for Aqualink pool lights."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from iaqualink import AqualinkLight, AqualinkLightEffect
|
from iaqualink import AqualinkLightEffect
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
@ -32,13 +32,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(devs, True)
|
async_add_entities(devs, True)
|
||||||
|
|
||||||
|
|
||||||
class HassAqualinkLight(Light, AqualinkEntity):
|
class HassAqualinkLight(AqualinkEntity, Light):
|
||||||
"""Representation of a light."""
|
"""Representation of a light."""
|
||||||
|
|
||||||
def __init__(self, dev: AqualinkLight):
|
|
||||||
"""Initialize the light."""
|
|
||||||
self.dev = dev
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the light."""
|
"""Return the name of the light."""
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from iaqualink import AqualinkSensor
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN
|
from homeassistant.components.sensor import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
@ -30,10 +28,6 @@ async def async_setup_entry(
|
|||||||
class HassAqualinkSensor(AqualinkEntity):
|
class HassAqualinkSensor(AqualinkEntity):
|
||||||
"""Representation of a sensor."""
|
"""Representation of a sensor."""
|
||||||
|
|
||||||
def __init__(self, dev: AqualinkSensor):
|
|
||||||
"""Initialize the sensor."""
|
|
||||||
self.dev = dev
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
"""Support for Aqualink pool feature switches."""
|
"""Support for Aqualink pool feature switches."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from iaqualink import AqualinkToggle
|
|
||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN, SwitchDevice
|
from homeassistant.components.switch import DOMAIN, SwitchDevice
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
@ -25,13 +23,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(devs, True)
|
async_add_entities(devs, True)
|
||||||
|
|
||||||
|
|
||||||
class HassAqualinkSwitch(SwitchDevice, AqualinkEntity):
|
class HassAqualinkSwitch(AqualinkEntity, SwitchDevice):
|
||||||
"""Representation of a switch."""
|
"""Representation of a switch."""
|
||||||
|
|
||||||
def __init__(self, dev: AqualinkToggle):
|
|
||||||
"""Initialize the switch."""
|
|
||||||
self.dev = dev
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the switch."""
|
"""Return the name of the switch."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user