Lutron Caseta: update for light transition and cover stop (#41155)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Matthew Donoughe 2020-10-03 16:06:23 -04:00 committed by GitHub
parent 95c3ac0c09
commit b281e85c80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 22 deletions

View File

@ -64,9 +64,9 @@ async def async_setup_entry(hass, config_entry):
"""Set up a bridge from a config entry."""
host = config_entry.data[CONF_HOST]
keyfile = config_entry.data[CONF_KEYFILE]
certfile = config_entry.data[CONF_CERTFILE]
ca_certs = config_entry.data[CONF_CA_CERTS]
keyfile = hass.config.path(config_entry.data[CONF_KEYFILE])
certfile = hass.config.path(config_entry.data[CONF_CERTFILE])
ca_certs = hass.config.path(config_entry.data[CONF_CA_CERTS])
bridge = Smartbridge.create_tls(
hostname=host, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs

View File

@ -83,9 +83,9 @@ class LutronCasetaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
try:
bridge = Smartbridge.create_tls(
hostname=self.data[CONF_HOST],
keyfile=self.data[CONF_KEYFILE],
certfile=self.data[CONF_CERTFILE],
ca_certs=self.data[CONF_CA_CERTS],
keyfile=self.hass.config.path(self.data[CONF_KEYFILE]),
certfile=self.hass.config.path(self.data[CONF_CERTFILE]),
ca_certs=self.hass.config.path(self.data[CONF_CA_CERTS]),
)
await bridge.connect()

View File

@ -7,6 +7,7 @@ from homeassistant.components.cover import (
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
SUPPORT_STOP,
CoverEntity,
)
@ -39,7 +40,7 @@ class LutronCasetaCover(LutronCasetaDevice, CoverEntity):
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
@property
def is_closed(self):
@ -51,19 +52,27 @@ class LutronCasetaCover(LutronCasetaDevice, CoverEntity):
"""Return the current position of cover."""
return self._device["current_state"]
async def async_stop_cover(self, **kwargs):
"""Top the cover."""
await self._smartbridge.stop_cover(self.device_id)
async def async_close_cover(self, **kwargs):
"""Close the cover."""
self._smartbridge.set_value(self.device_id, 0)
await self._smartbridge.lower_cover(self.device_id)
self.async_update()
self.async_write_ha_state()
async def async_open_cover(self, **kwargs):
"""Open the cover."""
self._smartbridge.set_value(self.device_id, 100)
await self._smartbridge.raise_cover(self.device_id)
self.async_update()
self.async_write_ha_state()
async def async_set_cover_position(self, **kwargs):
"""Move the shade to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
self._smartbridge.set_value(self.device_id, position)
await self._smartbridge.set_value(self.device_id, position)
async def async_update(self):
"""Call when forcing a refresh of the device."""

View File

@ -84,7 +84,7 @@ class LutronCasetaFan(LutronCasetaDevice, FanEntity):
async def async_set_speed(self, speed: str) -> None:
"""Set the speed of the fan."""
self._smartbridge.set_fan(self.device_id, SPEED_TO_VALUE[speed])
await self._smartbridge.set_fan(self.device_id, SPEED_TO_VALUE[speed])
@property
def is_on(self):

View File

@ -1,10 +1,13 @@
"""Support for Lutron Caseta lights."""
from datetime import timedelta
import logging
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_TRANSITION,
DOMAIN,
SUPPORT_BRIGHTNESS,
SUPPORT_TRANSITION,
LightEntity,
)
@ -47,21 +50,31 @@ class LutronCasetaLight(LutronCasetaDevice, LightEntity):
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS
return SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
@property
def brightness(self):
"""Return the brightness of the light."""
return to_hass_level(self._device["current_state"])
async def _set_brightness(self, brightness, **kwargs):
args = {}
if ATTR_TRANSITION in kwargs:
args["fade_time"] = timedelta(seconds=kwargs[ATTR_TRANSITION])
await self._smartbridge.set_value(
self.device_id, to_lutron_level(brightness), **args
)
async def async_turn_on(self, **kwargs):
"""Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
self._smartbridge.set_value(self.device_id, to_lutron_level(brightness))
brightness = kwargs.pop(ATTR_BRIGHTNESS, 255)
await self._set_brightness(brightness, **kwargs)
async def async_turn_off(self, **kwargs):
"""Turn the light off."""
self._smartbridge.set_value(self.device_id, 0)
await self._set_brightness(0, **kwargs)
@property
def is_on(self):

View File

@ -3,9 +3,9 @@
"name": "Lutron Caséta",
"documentation": "https://www.home-assistant.io/integrations/lutron_caseta",
"requirements": [
"pylutron-caseta==0.6.1"
"pylutron-caseta==0.7.0"
],
"codeowners": [
"@swails"
]
}
}

View File

@ -43,4 +43,4 @@ class LutronCasetaScene(Scene):
async def async_activate(self, **kwargs: Any) -> None:
"""Activate the scene."""
self._bridge.activate_scene(self._scene_id)
await self._bridge.activate_scene(self._scene_id)

View File

@ -32,11 +32,11 @@ class LutronCasetaLight(LutronCasetaDevice, SwitchEntity):
async def async_turn_on(self, **kwargs):
"""Turn the switch on."""
self._smartbridge.turn_on(self.device_id)
await self._smartbridge.turn_on(self.device_id)
async def async_turn_off(self, **kwargs):
"""Turn the switch off."""
self._smartbridge.turn_off(self.device_id)
await self._smartbridge.turn_off(self.device_id)
@property
def is_on(self):

View File

@ -1473,7 +1473,7 @@ pylitejet==0.1
pyloopenergy==0.2.1
# homeassistant.components.lutron_caseta
pylutron-caseta==0.6.1
pylutron-caseta==0.7.0
# homeassistant.components.lutron
pylutron==0.2.5

View File

@ -716,7 +716,7 @@ pylibrespot-java==0.1.0
pylitejet==0.1
# homeassistant.components.lutron_caseta
pylutron-caseta==0.6.1
pylutron-caseta==0.7.0
# homeassistant.components.mailgun
pymailgunner==1.4