2019-02-14 05:35:12 +01:00
|
|
|
"""Support for Lutron Caseta lights."""
|
2017-03-22 19:18:14 -05:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.light import (
|
2019-07-31 12:25:30 -07:00
|
|
|
ATTR_BRIGHTNESS,
|
|
|
|
DOMAIN,
|
|
|
|
SUPPORT_BRIGHTNESS,
|
|
|
|
Light,
|
|
|
|
)
|
|
|
|
from homeassistant.components.lutron.light import to_hass_level, to_lutron_level
|
2019-03-20 22:56:46 -07:00
|
|
|
|
|
|
|
from . import LUTRON_CASETA_SMARTBRIDGE, LutronCasetaDevice
|
2017-03-22 19:18:14 -05:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2017-05-02 18:18:47 +02:00
|
|
|
"""Set up the Lutron Caseta lights."""
|
2017-03-22 19:18:14 -05:00
|
|
|
devs = []
|
|
|
|
bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE]
|
2017-09-05 05:30:36 -04:00
|
|
|
light_devices = bridge.get_devices_by_domain(DOMAIN)
|
2017-03-22 19:18:14 -05:00
|
|
|
for light_device in light_devices:
|
|
|
|
dev = LutronCasetaLight(light_device, bridge)
|
|
|
|
devs.append(dev)
|
|
|
|
|
2018-08-24 16:37:30 +02:00
|
|
|
async_add_entities(devs, True)
|
2017-03-22 19:18:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
class LutronCasetaLight(LutronCasetaDevice, Light):
|
|
|
|
"""Representation of a Lutron Light, including dimmable."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_BRIGHTNESS
|
|
|
|
|
|
|
|
@property
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of the light."""
|
|
|
|
return to_hass_level(self._state["current_state"])
|
|
|
|
|
2018-10-01 08:56:50 +02:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2017-03-22 19:18:14 -05:00
|
|
|
"""Turn the light on."""
|
2018-07-18 12:54:27 +03:00
|
|
|
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
2019-07-31 12:25:30 -07:00
|
|
|
self._smartbridge.set_value(self._device_id, to_lutron_level(brightness))
|
2017-03-22 19:18:14 -05:00
|
|
|
|
2018-10-01 08:56:50 +02:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2017-03-22 19:18:14 -05:00
|
|
|
"""Turn the light off."""
|
|
|
|
self._smartbridge.set_value(self._device_id, 0)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if device is on."""
|
|
|
|
return self._state["current_state"] > 0
|
|
|
|
|
2018-10-01 08:56:50 +02:00
|
|
|
async def async_update(self):
|
2017-04-30 23:10:08 -04:00
|
|
|
"""Call when forcing a refresh of the device."""
|
2017-03-22 19:18:14 -05:00
|
|
|
self._state = self._smartbridge.get_device_by_id(self._device_id)
|
|
|
|
_LOGGER.debug(self._state)
|