2019-02-19 13:09:06 +00:00
|
|
|
"""Support for Insteon lights via PowerLinc Modem."""
|
2022-04-28 19:35:43 +00:00
|
|
|
from pyinsteon.config import ON_LEVEL
|
2021-12-21 09:37:29 +00:00
|
|
|
|
2020-04-26 16:49:41 +00:00
|
|
|
from homeassistant.components.light import (
|
|
|
|
ATTR_BRIGHTNESS,
|
2020-08-11 23:04:44 +00:00
|
|
|
DOMAIN as LIGHT_DOMAIN,
|
2022-04-23 19:16:40 +00:00
|
|
|
ColorMode,
|
2020-04-26 16:49:41 +00:00
|
|
|
LightEntity,
|
|
|
|
)
|
2022-01-03 14:02:21 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-08-11 23:04:44 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2022-01-03 14:02:21 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2020-08-11 23:04:44 +00:00
|
|
|
from .const import SIGNAL_ADD_ENTITIES
|
2020-01-30 09:47:44 +00:00
|
|
|
from .insteon_entity import InsteonEntity
|
2020-05-17 13:27:38 +00:00
|
|
|
from .utils import async_add_insteon_entities
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-02-21 07:53:39 +00:00
|
|
|
MAX_BRIGHTNESS = 255
|
|
|
|
|
|
|
|
|
2022-01-03 14:02:21 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-08-11 23:04:44 +00:00
|
|
|
"""Set up the Insteon lights from a config entry."""
|
|
|
|
|
2021-02-02 09:17:17 +00:00
|
|
|
@callback
|
|
|
|
def async_add_insteon_light_entities(discovery_info=None):
|
2020-08-11 23:04:44 +00:00
|
|
|
"""Add the Insteon entities for the platform."""
|
|
|
|
async_add_insteon_entities(
|
|
|
|
hass, LIGHT_DOMAIN, InsteonDimmerEntity, async_add_entities, discovery_info
|
|
|
|
)
|
|
|
|
|
|
|
|
signal = f"{SIGNAL_ADD_ENTITIES}_{LIGHT_DOMAIN}"
|
2021-02-02 09:17:17 +00:00
|
|
|
async_dispatcher_connect(hass, signal, async_add_insteon_light_entities)
|
|
|
|
async_add_insteon_light_entities()
|
2017-02-21 07:53:39 +00:00
|
|
|
|
|
|
|
|
2020-05-17 13:27:38 +00:00
|
|
|
class InsteonDimmerEntity(InsteonEntity, LightEntity):
|
|
|
|
"""A Class for an Insteon light entity."""
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2022-04-23 19:16:40 +00:00
|
|
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
|
|
|
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
2022-04-04 16:25:40 +00:00
|
|
|
|
2017-02-21 07:53:39 +00:00
|
|
|
@property
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of this light between 0..255."""
|
2020-05-17 13:27:38 +00:00
|
|
|
return self._insteon_device_group.value
|
2017-02-21 07:53:39 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the boolean response if the node is on."""
|
2018-02-25 19:13:39 +00:00
|
|
|
return bool(self.brightness)
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-10-01 06:56:50 +00:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Turn light on."""
|
2017-02-21 07:53:39 +00:00
|
|
|
if ATTR_BRIGHTNESS in kwargs:
|
|
|
|
brightness = int(kwargs[ATTR_BRIGHTNESS])
|
2022-05-09 18:20:45 +00:00
|
|
|
elif self._insteon_device_group.group == 1:
|
2021-12-21 09:37:29 +00:00
|
|
|
brightness = self.get_device_property(ON_LEVEL)
|
2022-05-09 18:20:45 +00:00
|
|
|
if brightness:
|
2020-05-17 13:27:38 +00:00
|
|
|
await self._insteon_device.async_on(
|
|
|
|
on_level=brightness, group=self._insteon_device_group.group
|
|
|
|
)
|
2017-02-21 07:53:39 +00:00
|
|
|
else:
|
2020-05-17 13:27:38 +00:00
|
|
|
await self._insteon_device.async_on(group=self._insteon_device_group.group)
|
2017-02-21 07:53:39 +00:00
|
|
|
|
2018-10-01 06:56:50 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Turn light off."""
|
|
|
|
await self._insteon_device.async_off(self._insteon_device_group.group)
|