2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron Caseta switches."""
|
2017-03-23 00:18:14 +00:00
|
|
|
import logging
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
from homeassistant.components.switch import DOMAIN, SwitchEntity
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2021-01-26 22:32:08 +00:00
|
|
|
from . import LutronCasetaDevice
|
|
|
|
from .const import BRIDGE_DEVICE, BRIDGE_LEAP, DOMAIN as CASETA_DOMAIN
|
2017-03-23 00:18:14 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-05-11 09:05:13 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Lutron Caseta switch platform.
|
|
|
|
|
|
|
|
Adds switches from the Caseta bridge associated with the config_entry as
|
|
|
|
switch entities.
|
|
|
|
"""
|
2020-03-22 16:35:01 +00:00
|
|
|
entities = []
|
2021-01-26 22:32:08 +00:00
|
|
|
data = hass.data[CASETA_DOMAIN][config_entry.entry_id]
|
|
|
|
bridge = data[BRIDGE_LEAP]
|
|
|
|
bridge_device = data[BRIDGE_DEVICE]
|
2017-09-05 09:30:36 +00:00
|
|
|
switch_devices = bridge.get_devices_by_domain(DOMAIN)
|
2017-03-23 00:18:14 +00:00
|
|
|
|
|
|
|
for switch_device in switch_devices:
|
2021-01-26 22:32:08 +00:00
|
|
|
entity = LutronCasetaLight(switch_device, bridge, bridge_device)
|
2020-03-22 16:35:01 +00:00
|
|
|
entities.append(entity)
|
2017-03-23 00:18:14 +00:00
|
|
|
|
2020-03-22 16:35:01 +00:00
|
|
|
async_add_entities(entities, True)
|
2017-03-23 00:18:14 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
class LutronCasetaLight(LutronCasetaDevice, SwitchEntity):
|
2017-03-23 00:18:14 +00:00
|
|
|
"""Representation of a Lutron Caseta switch."""
|
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_on(self, **kwargs):
|
2017-03-23 00:18:14 +00:00
|
|
|
"""Turn the switch on."""
|
2020-10-03 20:06:23 +00:00
|
|
|
await self._smartbridge.turn_on(self.device_id)
|
2017-03-23 00:18:14 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
2017-03-23 00:18:14 +00:00
|
|
|
"""Turn the switch off."""
|
2020-10-03 20:06:23 +00:00
|
|
|
await self._smartbridge.turn_off(self.device_id)
|
2017-03-23 00:18:14 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if device is on."""
|
2019-11-26 17:06:14 +00:00
|
|
|
return self._device["current_state"] > 0
|
2017-03-23 00:18:14 +00:00
|
|
|
|
2018-10-01 06:55:00 +00:00
|
|
|
async def async_update(self):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Update when forcing a refresh of the device."""
|
2019-11-26 17:06:14 +00:00
|
|
|
self._device = self._smartbridge.get_device_by_id(self.device_id)
|
|
|
|
_LOGGER.debug(self._device)
|