Skip to content

Commit

Permalink
Merge pull request #100 from peribeir/peribeir/issue88
Browse files Browse the repository at this point in the history
Use Scenes from HomePilot in HomeAssistant
  • Loading branch information
peribeir authored Nov 28, 2023
2 parents 67b82be + 5021308 commit c06fbbc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/rademacher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# List of platforms to support. There should be a matching .py file for each,
# eg <cover.py> and <sensor.py>
PLATFORMS = ["cover", "button", "switch", "sensor", "binary_sensor", "climate", "light", "number", "update"]
PLATFORMS = ["cover", "button", "switch", "sensor", "binary_sensor", "climate", "light", "number", "update", "scene"]

_LOGGER = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/rademacher/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"integration_type": "hub",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/peribeir/homeassistant-rademacher/issues",
"requirements": ["pyrademacher==0.11.2"],
"version": "2.0.1"
"requirements": ["pyrademacher==0.12.3"],
"version": "2.1.0"
}
53 changes: 53 additions & 0 deletions custom_components/rademacher/scene.py
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()

0 comments on commit c06fbbc

Please sign in to comment.