mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Fix control4 light switches on OS 3.3+ (#95196)
This commit is contained in:
parent
5bd5ca8433
commit
f08f0fbb8b
@ -30,7 +30,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
CONTROL4_CATEGORY = "lights"
|
CONTROL4_CATEGORY = "lights"
|
||||||
CONTROL4_NON_DIMMER_VAR = "LIGHT_STATE"
|
CONTROL4_NON_DIMMER_VAR = "LIGHT_STATE"
|
||||||
CONTROL4_DIMMER_VAR = "LIGHT_LEVEL"
|
CONTROL4_DIMMER_VARS = ["LIGHT_LEVEL", "Brightness Percent"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -57,7 +57,7 @@ async def async_setup_entry(
|
|||||||
"""Fetch data from Control4 director for dimmer lights."""
|
"""Fetch data from Control4 director for dimmer lights."""
|
||||||
try:
|
try:
|
||||||
return await update_variables_for_config_entry(
|
return await update_variables_for_config_entry(
|
||||||
hass, entry, {CONTROL4_DIMMER_VAR}
|
hass, entry, {*CONTROL4_DIMMER_VARS}
|
||||||
)
|
)
|
||||||
except C4Exception as err:
|
except C4Exception as err:
|
||||||
raise UpdateFailed(f"Error communicating with API: {err}") from err
|
raise UpdateFailed(f"Error communicating with API: {err}") from err
|
||||||
@ -190,14 +190,19 @@ class Control4Light(Control4Entity, LightEntity):
|
|||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return whether this light is on or off."""
|
"""Return whether this light is on or off."""
|
||||||
if self._is_dimmer:
|
if self._is_dimmer:
|
||||||
return self.coordinator.data[self._idx][CONTROL4_DIMMER_VAR] > 0
|
for var in CONTROL4_DIMMER_VARS:
|
||||||
|
if var in self.coordinator.data[self._idx]:
|
||||||
|
return self.coordinator.data[self._idx][var] > 0
|
||||||
|
raise RuntimeError("Dimmer Variable Not Found")
|
||||||
return self.coordinator.data[self._idx][CONTROL4_NON_DIMMER_VAR] > 0
|
return self.coordinator.data[self._idx][CONTROL4_NON_DIMMER_VAR] > 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
if self._is_dimmer:
|
if self._is_dimmer:
|
||||||
return round(self.coordinator.data[self._idx][CONTROL4_DIMMER_VAR] * 2.55)
|
for var in CONTROL4_DIMMER_VARS:
|
||||||
|
if var in self.coordinator.data[self._idx]:
|
||||||
|
return round(self.coordinator.data[self._idx][var] * 2.55)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user