mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add lock entity to Overkiz integration (#62713)
This commit is contained in:
parent
41531b528e
commit
f722931920
@ -806,6 +806,7 @@ omit =
|
|||||||
homeassistant/components/overkiz/coordinator.py
|
homeassistant/components/overkiz/coordinator.py
|
||||||
homeassistant/components/overkiz/entity.py
|
homeassistant/components/overkiz/entity.py
|
||||||
homeassistant/components/overkiz/executor.py
|
homeassistant/components/overkiz/executor.py
|
||||||
|
homeassistant/components/overkiz/lock.py
|
||||||
homeassistant/components/overkiz/sensor.py
|
homeassistant/components/overkiz/sensor.py
|
||||||
homeassistant/components/ovo_energy/__init__.py
|
homeassistant/components/ovo_energy/__init__.py
|
||||||
homeassistant/components/ovo_energy/const.py
|
homeassistant/components/ovo_energy/const.py
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
"""The Overkiz (by Somfy) integration."""
|
"""The Overkiz (by Somfy) integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -10,6 +13,7 @@ from pyoverkiz.exceptions import (
|
|||||||
MaintenanceException,
|
MaintenanceException,
|
||||||
TooManyRequestsException,
|
TooManyRequestsException,
|
||||||
)
|
)
|
||||||
|
from pyoverkiz.models import Device
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
@ -21,6 +25,7 @@ from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
|||||||
from .const import (
|
from .const import (
|
||||||
CONF_HUB,
|
CONF_HUB,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
OVERKIZ_DEVICE_TO_PLATFORM,
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
UPDATE_INTERVAL,
|
UPDATE_INTERVAL,
|
||||||
UPDATE_INTERVAL_ALL_ASSUMED_STATE,
|
UPDATE_INTERVAL_ALL_ASSUMED_STATE,
|
||||||
@ -35,6 +40,7 @@ class HomeAssistantOverkizData:
|
|||||||
"""Overkiz data stored in the Home Assistant data object."""
|
"""Overkiz data stored in the Home Assistant data object."""
|
||||||
|
|
||||||
coordinator: OverkizDataUpdateCoordinator
|
coordinator: OverkizDataUpdateCoordinator
|
||||||
|
platforms: dict[str, Device]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
@ -85,8 +91,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
coordinator.update_interval = UPDATE_INTERVAL_ALL_ASSUMED_STATE
|
coordinator.update_interval = UPDATE_INTERVAL_ALL_ASSUMED_STATE
|
||||||
|
|
||||||
|
platforms: dict[str, Device] = defaultdict(list)
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = HomeAssistantOverkizData(
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = HomeAssistantOverkizData(
|
||||||
coordinator=coordinator,
|
coordinator=coordinator,
|
||||||
|
platforms=platforms,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Map Overkiz device to Home Assistant platform
|
# Map Overkiz device to Home Assistant platform
|
||||||
@ -96,6 +105,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
device,
|
device,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if platform := OVERKIZ_DEVICE_TO_PLATFORM.get(
|
||||||
|
device.widget
|
||||||
|
) or OVERKIZ_DEVICE_TO_PLATFORM.get(device.ui_class):
|
||||||
|
platforms[platform].append(device)
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
device_registry = await dr.async_get_registry(hass)
|
device_registry = await dr.async_get_registry(hass)
|
||||||
|
@ -18,6 +18,7 @@ UPDATE_INTERVAL: Final = timedelta(seconds=30)
|
|||||||
UPDATE_INTERVAL_ALL_ASSUMED_STATE: Final = timedelta(minutes=60)
|
UPDATE_INTERVAL_ALL_ASSUMED_STATE: Final = timedelta(minutes=60)
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
|
Platform.LOCK,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -25,3 +26,8 @@ IGNORED_OVERKIZ_DEVICES: list[UIClass | UIWidget] = [
|
|||||||
UIClass.PROTOCOL_GATEWAY,
|
UIClass.PROTOCOL_GATEWAY,
|
||||||
UIClass.POD,
|
UIClass.POD,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Used to map the Somfy widget and ui_class to the Home Assistant platform
|
||||||
|
OVERKIZ_DEVICE_TO_PLATFORM: dict[UIClass | UIWidget, Platform] = {
|
||||||
|
UIClass.DOOR_LOCK: Platform.LOCK,
|
||||||
|
}
|
||||||
|
52
homeassistant/components/overkiz/lock.py
Normal file
52
homeassistant/components/overkiz/lock.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
"""Support for Overkiz locks."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
|
||||||
|
|
||||||
|
from homeassistant.components.lock import LockEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import HomeAssistantOverkizData
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .entity import OverkizEntity
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
):
|
||||||
|
"""Set up the Overkiz locks from a config entry."""
|
||||||
|
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
|
entities: list[OverkizLock] = [
|
||||||
|
OverkizLock(device.device_url, data.coordinator)
|
||||||
|
for device in data.platforms[Platform.LOCK]
|
||||||
|
]
|
||||||
|
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class OverkizLock(OverkizEntity, LockEntity):
|
||||||
|
"""Representation of an Overkiz Lock."""
|
||||||
|
|
||||||
|
async def async_lock(self, **_: Any) -> None:
|
||||||
|
"""Lock method."""
|
||||||
|
await self.executor.async_execute_command(OverkizCommand.LOCK)
|
||||||
|
|
||||||
|
async def async_unlock(self, **_: Any) -> None:
|
||||||
|
"""Unlock method."""
|
||||||
|
await self.executor.async_execute_command(OverkizCommand.UNLOCK)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_locked(self) -> bool | None:
|
||||||
|
"""Return a boolean for the state of the lock."""
|
||||||
|
return (
|
||||||
|
self.executor.select_state(OverkizState.CORE_LOCKED_UNLOCKED)
|
||||||
|
== OverkizCommandParam.LOCKED
|
||||||
|
)
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from pyoverkiz.enums import OverkizAttribute, OverkizState, UIWidget
|
from pyoverkiz.enums import OverkizAttribute, OverkizState, UIWidget
|
||||||
|
|
||||||
from homeassistant.components.overkiz import HomeAssistantOverkizData
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
@ -26,6 +25,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import HomeAssistantOverkizData
|
||||||
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
||||||
from .coordinator import OverkizDataUpdateCoordinator
|
from .coordinator import OverkizDataUpdateCoordinator
|
||||||
from .entity import OverkizDescriptiveEntity, OverkizEntity, OverkizSensorDescription
|
from .entity import OverkizDescriptiveEntity, OverkizEntity, OverkizSensorDescription
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "Device is already configured"
|
"already_configured": "Account is already configured"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "Failed to connect",
|
"cannot_connect": "Failed to connect",
|
||||||
"invalid_auth": "Invalid authentication",
|
"invalid_auth": "Invalid authentication",
|
||||||
|
"server_in_maintenance": "Server is down for maintenance",
|
||||||
|
"too_many_requests": "Too many requests, try again later.",
|
||||||
"unknown": "Unexpected error"
|
"unknown": "Unexpected error"
|
||||||
},
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"data": {
|
"data": {
|
||||||
"host": "Host",
|
"host": "Host",
|
||||||
|
"hub": "Hub",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"username": "Username"
|
"username": "Username"
|
||||||
}
|
},
|
||||||
|
"description": "The Overkiz platform is used by various vendors like Somfy (Connexoon / TaHoma), Hitachi (Hi Kumo), Rexel (Energeasy Connect) and Atlantic (Cozytouch). Enter your application credentials and select your hub."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user