Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix control4 light switches on OS 3.3+ #95196

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]:
nalin29 marked this conversation as resolved.
Show resolved Hide resolved
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