mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add scene entity to Overkiz integration (#62884)
This commit is contained in:
parent
cb135bc889
commit
0bcb0a6267
@ -810,6 +810,7 @@ omit =
|
||||
homeassistant/components/overkiz/light.py
|
||||
homeassistant/components/overkiz/lock.py
|
||||
homeassistant/components/overkiz/number.py
|
||||
homeassistant/components/overkiz/scene.py
|
||||
homeassistant/components/overkiz/sensor.py
|
||||
homeassistant/components/ovo_energy/__init__.py
|
||||
homeassistant/components/ovo_energy/const.py
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""The Overkiz (by Somfy) integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
@ -13,10 +14,10 @@ from pyoverkiz.exceptions import (
|
||||
MaintenanceException,
|
||||
TooManyRequestsException,
|
||||
)
|
||||
from pyoverkiz.models import Device
|
||||
from pyoverkiz.models import Device, Scenario
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
@ -40,7 +41,7 @@ class HomeAssistantOverkizData:
|
||||
"""Overkiz data stored in the Home Assistant data object."""
|
||||
|
||||
coordinator: OverkizDataUpdateCoordinator
|
||||
platforms: dict[str, Device]
|
||||
platforms: dict[Platform, Device | Scenario]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
@ -57,7 +58,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
try:
|
||||
await client.login()
|
||||
setup = await client.get_setup()
|
||||
|
||||
setup, scenarios = await asyncio.gather(
|
||||
*[
|
||||
client.get_setup(),
|
||||
client.get_scenarios(),
|
||||
]
|
||||
)
|
||||
except BadCredentialsException:
|
||||
_LOGGER.error("Invalid authentication")
|
||||
return False
|
||||
@ -91,14 +98,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
coordinator.update_interval = UPDATE_INTERVAL_ALL_ASSUMED_STATE
|
||||
|
||||
platforms: dict[str, Device] = defaultdict(list)
|
||||
platforms: dict[Platform, Device | Scenario] = defaultdict(list)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = HomeAssistantOverkizData(
|
||||
coordinator=coordinator,
|
||||
platforms=platforms,
|
||||
)
|
||||
|
||||
# Map Overkiz device to Home Assistant platform
|
||||
# Map Overkiz entities to Home Assistant platform
|
||||
platforms[Platform.SCENE] = scenarios
|
||||
|
||||
for device in coordinator.data.values():
|
||||
_LOGGER.debug(
|
||||
"The following device has been retrieved. Report an issue if not supported correctly (%s)",
|
||||
|
@ -22,6 +22,7 @@ PLATFORMS: list[Platform] = [
|
||||
Platform.LIGHT,
|
||||
Platform.LOCK,
|
||||
Platform.NUMBER,
|
||||
Platform.SCENE,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
||||
|
45
homeassistant/components/overkiz/scene.py
Normal file
45
homeassistant/components/overkiz/scene.py
Normal file
@ -0,0 +1,45 @@
|
||||
"""Support for Overkiz scenes."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pyoverkiz.client import OverkizClient
|
||||
from pyoverkiz.models import Scenario
|
||||
|
||||
from homeassistant.components.scene import Scene
|
||||
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
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
):
|
||||
"""Set up the Overkiz scenes from a config entry."""
|
||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async_add_entities(
|
||||
OverkizScene(scene, data.coordinator.client)
|
||||
for scene in data.platforms[Platform.SCENE]
|
||||
)
|
||||
|
||||
|
||||
class OverkizScene(Scene):
|
||||
"""Representation of an Overkiz Scene."""
|
||||
|
||||
def __init__(self, scenario: Scenario, client: OverkizClient) -> None:
|
||||
"""Initialize the scene."""
|
||||
self.scenario = scenario
|
||||
self.client = client
|
||||
self._attr_name = self.scenario.label
|
||||
self._attr_unique_id = self.scenario.oid
|
||||
|
||||
async def async_activate(self, **kwargs: Any) -> None:
|
||||
"""Activate the scene."""
|
||||
await self.client.execute_scenario(self.scenario.oid)
|
Loading…
x
Reference in New Issue
Block a user