mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix Control4 token refresh (#38302)
This commit is contained in:
parent
e208d8b93e
commit
96c6e4c2f4
@ -171,9 +171,7 @@ class Control4Entity(entity.Entity):
|
|||||||
):
|
):
|
||||||
"""Initialize a Control4 entity."""
|
"""Initialize a Control4 entity."""
|
||||||
self.entry = entry
|
self.entry = entry
|
||||||
self.account = entry_data[CONF_ACCOUNT]
|
self.entry_data = entry_data
|
||||||
self.director = entry_data[CONF_DIRECTOR]
|
|
||||||
self.director_token_expiry = entry_data[CONF_DIRECTOR_TOKEN_EXPIRATION]
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._idx = idx
|
self._idx = idx
|
||||||
self._coordinator = coordinator
|
self._coordinator = coordinator
|
||||||
|
@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from . import Control4Entity, get_items_of_category
|
from . import Control4Entity, get_items_of_category
|
||||||
from .const import CONTROL4_ENTITY_TYPE, DOMAIN
|
from .const import CONF_DIRECTOR, CONTROL4_ENTITY_TYPE, DOMAIN
|
||||||
from .director_utils import director_update_data
|
from .director_utils import director_update_data
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -138,12 +138,13 @@ class Control4Light(Control4Entity, LightEntity):
|
|||||||
device_id,
|
device_id,
|
||||||
)
|
)
|
||||||
self._is_dimmer = is_dimmer
|
self._is_dimmer = is_dimmer
|
||||||
self._c4_light = None
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
def create_api_object(self):
|
||||||
"""When entity is added to hass."""
|
"""Create a pyControl4 device object.
|
||||||
await super().async_added_to_hass()
|
|
||||||
self._c4_light = C4Light(self.director, self._idx)
|
This exists so the director token used is always the latest one, without needing to re-init the entire entity.
|
||||||
|
"""
|
||||||
|
return C4Light(self.entry_data[CONF_DIRECTOR], self._idx)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@ -167,6 +168,7 @@ class Control4Light(Control4Entity, LightEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs) -> None:
|
async def async_turn_on(self, **kwargs) -> None:
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
|
c4_light = self.create_api_object()
|
||||||
if self._is_dimmer:
|
if self._is_dimmer:
|
||||||
if ATTR_TRANSITION in kwargs:
|
if ATTR_TRANSITION in kwargs:
|
||||||
transition_length = kwargs[ATTR_TRANSITION] * 1000
|
transition_length = kwargs[ATTR_TRANSITION] * 1000
|
||||||
@ -176,10 +178,10 @@ class Control4Light(Control4Entity, LightEntity):
|
|||||||
brightness = (kwargs[ATTR_BRIGHTNESS] / 255) * 100
|
brightness = (kwargs[ATTR_BRIGHTNESS] / 255) * 100
|
||||||
else:
|
else:
|
||||||
brightness = 100
|
brightness = 100
|
||||||
await self._c4_light.rampToLevel(brightness, transition_length)
|
await c4_light.rampToLevel(brightness, transition_length)
|
||||||
else:
|
else:
|
||||||
transition_length = 0
|
transition_length = 0
|
||||||
await self._c4_light.setLevel(100)
|
await c4_light.setLevel(100)
|
||||||
if transition_length == 0:
|
if transition_length == 0:
|
||||||
transition_length = 1000
|
transition_length = 1000
|
||||||
delay_time = (transition_length / 1000) + 0.7
|
delay_time = (transition_length / 1000) + 0.7
|
||||||
@ -189,15 +191,16 @@ class Control4Light(Control4Entity, LightEntity):
|
|||||||
|
|
||||||
async def async_turn_off(self, **kwargs) -> None:
|
async def async_turn_off(self, **kwargs) -> None:
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
|
c4_light = self.create_api_object()
|
||||||
if self._is_dimmer:
|
if self._is_dimmer:
|
||||||
if ATTR_TRANSITION in kwargs:
|
if ATTR_TRANSITION in kwargs:
|
||||||
transition_length = kwargs[ATTR_TRANSITION] * 1000
|
transition_length = kwargs[ATTR_TRANSITION] * 1000
|
||||||
else:
|
else:
|
||||||
transition_length = 0
|
transition_length = 0
|
||||||
await self._c4_light.rampToLevel(0, transition_length)
|
await c4_light.rampToLevel(0, transition_length)
|
||||||
else:
|
else:
|
||||||
transition_length = 0
|
transition_length = 0
|
||||||
await self._c4_light.setLevel(0)
|
await c4_light.setLevel(0)
|
||||||
if transition_length == 0:
|
if transition_length == 0:
|
||||||
transition_length = 1500
|
transition_length = 1500
|
||||||
delay_time = (transition_length / 1000) + 0.7
|
delay_time = (transition_length / 1000) + 0.7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user