Skip to content

Commit

Permalink
fix light level on OS 3.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
nalin29 committed Jun 25, 2023
1 parent f84887d commit 11a0e6f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions homeassistant/components/control4/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

CONTROL4_CATEGORY = "lights"
CONTROL4_NON_DIMMER_VAR = "LIGHT_STATE"
CONTROL4_DIMMER_VAR = "LIGHT_LEVEL"
CONTROL4_DIMMER_VARS = ["LIGHT_LEVEL", "Brightness Percent"]


async def async_setup_entry(
Expand All @@ -57,7 +57,7 @@ async def async_update_data_dimmer():
"""Fetch data from Control4 director for dimmer lights."""
try:
return await update_variables_for_config_entry(
hass, entry, {CONTROL4_DIMMER_VAR}
hass, entry, {*CONTROL4_DIMMER_VARS}
)
except C4Exception as err:
raise UpdateFailed(f"Error communicating with API: {err}") from err
Expand Down Expand Up @@ -190,14 +190,18 @@ def _create_api_object(self):
def is_on(self):
"""Return whether this light is on or off."""
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
return self.coordinator.data[self._idx][CONTROL4_NON_DIMMER_VAR] > 0

@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
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

@property
Expand Down

0 comments on commit 11a0e6f

Please sign in to comment.