Skip to content

Commit

Permalink
Merge pull request #69 from peribeir/peribeir/issue66
Browse files Browse the repository at this point in the history
Rademacher Universal Dimmer
  • Loading branch information
peribeir authored Feb 18, 2023
2 parents 07c5e29 + f7bb1b5 commit 4964658
Show file tree
Hide file tree
Showing 3 changed files with 85 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 @@ -27,7 +27,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"]
PLATFORMS = ["cover", "button", "switch", "sensor", "binary_sensor", "climate", "light"]

_LOGGER = logging.getLogger(__name__)

Expand Down
82 changes: 82 additions & 0 deletions custom_components/rademacher/light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""Platform for Rademacher Bridge"""
import asyncio
import logging
from typing import Any

from homeassistant.const import CONF_EXCLUDE
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.components.light import (
LightEntity,
LightEntityFeature,
ColorMode,
ATTR_BRIGHTNESS,
)

from homepilot.actuator import HomePilotActuator
from homepilot.device import HomePilotDevice
from homepilot.manager import HomePilotManager

from .entity import HomePilotEntity

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Setup of entities for light platform"""
entry = hass.data[DOMAIN][config_entry.entry_id]
manager: HomePilotManager = entry[0]
coordinator: DataUpdateCoordinator = entry[1]
exclude_devices: list[str] = entry[3][CONF_EXCLUDE]
new_entities = []
for did in manager.devices:
if did not in exclude_devices:
device: HomePilotDevice = manager.devices[did]
if isinstance(device, HomePilotActuator):
_LOGGER.info("Found Actuator/Light for Device ID: %s", device.did)
new_entities.append(HomePilotLightEntity(coordinator, device))
# If we have any new devices, add them
if new_entities:
async_add_entities(new_entities)


class HomePilotLightEntity(HomePilotEntity, LightEntity):
"""This class represents the Light entity"""

def __init__(
self, coordinator: DataUpdateCoordinator, actuator: HomePilotActuator
) -> None:
super().__init__(
coordinator,
actuator,
unique_id=actuator.uid,
name=actuator.name,
)
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
self._attr_color_mode = ColorMode.BRIGHTNESS

@property
def brightness(self):
device: HomePilotActuator = self.coordinator.data[self.did]
return round(device.brightness*255/100)

@property
def is_on(self):
device: HomePilotActuator = self.coordinator.data[self.did]
return device.is_on

async def async_turn_on(self, **kwargs: Any) -> None:
device: HomePilotActuator = self.coordinator.data[self.did]
if ATTR_BRIGHTNESS in kwargs:
await device.async_set_brightness(round(kwargs[ATTR_BRIGHTNESS]*100/255))
else:
await device.async_turn_on()
await asyncio.sleep(5)
await self.coordinator.async_request_refresh()

async def async_turn_off(self, **kwargs: Any) -> None:
device: HomePilotActuator = self.coordinator.data[self.did]
await device.async_turn_off()
await asyncio.sleep(5)
await self.coordinator.async_request_refresh()
4 changes: 2 additions & 2 deletions custom_components/rademacher/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"domain": "rademacher",
"name": "Rademacher Homepilot",
"version": "1.9.7",
"version": "1.10.1",
"documentation": "https://github.com/peribeir/homeassistant-rademacher",
"issue_tracker": "https://github.com/peribeir/homeassistant-rademacher/issues",
"requirements": ["pyrademacher==0.6.9"],
"requirements": ["pyrademacher==0.8.3"],
"dhcp": [
{
"macaddress": "B01F81B*"
Expand Down

0 comments on commit 4964658

Please sign in to comment.