-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from peribeir/peribeir/issue88
Use Scenes from HomePilot in HomeAssistant
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Platform for Rademacher Bridge""" | ||
import asyncio | ||
import logging | ||
from typing import Any | ||
|
||
from homeassistant.helpers.entity import EntityCategory | ||
|
||
from homeassistant.components.scene import Scene | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator | ||
|
||
from homepilot.manager import HomePilotManager | ||
from homepilot.scenes import HomePilotScene | ||
|
||
from .const import DOMAIN | ||
from .entity import HomePilotEntity | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Setup of entities for switch platform""" | ||
entry = hass.data[DOMAIN][config_entry.entry_id] | ||
manager: HomePilotManager = entry[0] | ||
new_entities = [] | ||
for sid in manager.scenes: | ||
scene: HomePilotScene = manager.scenes[sid] | ||
_LOGGER.info("Found Scene for ID: %s", sid) | ||
new_entities.append(HomePilotSceneEntity(sid, scene)) | ||
# If we have any new devices, add them | ||
if new_entities: | ||
async_add_entities(new_entities) | ||
|
||
|
||
class HomePilotSceneEntity(Scene): | ||
"""This class represents Cover Ventilation Position""" | ||
_sid: str | ||
_scene: HomePilotScene | ||
|
||
def __init__( | ||
self, sid: str, scene: HomePilotScene | ||
) -> None: | ||
self._sid = sid | ||
self._scene = scene | ||
self._attr_unique_id = f"scene_{sid}" | ||
self._attr_name = f"Homepilot - {scene.name}" | ||
|
||
@property | ||
def available(self): | ||
return True | ||
|
||
async def async_activate(self, **kwargs: Any) -> None: | ||
"""Activate scene. Try to get entities into requested state.""" | ||
await self._scene.async_execute_scene() |