fix the last commit

This commit is contained in:
Benjamin Auquite 2023-04-10 12:34:24 -05:00
commit 7106a77543

View file

@ -297,11 +297,9 @@ def _get_switches_with_lights(
if entry is None: # entry might be disabled and therefore missing
continue
switch = data[config.entry_id]["instance"]
all_check_lights = switch.get_lights(
hass, lights
) # pylint: disable=protected-access
all_check_lights = _expand_light_groups(hass, lights)
# Check if any of the lights are in the switch's lights
if set(switch.get_lights()) & set(
if set(switch.all_lights) & set(
all_check_lights
): # pylint: disable=protected-access
switches.append(switch)
@ -404,7 +402,7 @@ async def handle_change_switch_settings(
data,
)
all_lights = switch.get_lights() # pylint: disable=protected-access
all_lights = switch.all_lights # pylint: disable=protected-access
switch.turn_on_off_listener.reset(*all_lights, reset_manual_control=False)
if switch.is_on:
await switch._update_attrs_and_maybe_adapt_lights( # pylint: disable=protected-access
@ -487,9 +485,7 @@ async def async_setup_entry(
switches = _get_switches_from_service_call(hass, service_call)
lights = data[CONF_LIGHTS]
for switch in switches:
all_lights = (
lights or switch.get_lights()
) # pylint: disable=protected-access
all_lights = lights or switch.all_lights # pylint: disable=protected-access
switch.turn_on_off_listener.lights.update(all_lights)
for light in all_lights:
if data[CONF_TURN_ON_LIGHTS] or is_on(hass, light):
@ -516,9 +512,7 @@ async def async_setup_entry(
switches = _get_switches_from_service_call(hass, service_call)
lights = data[CONF_LIGHTS]
for switch in switches:
all_lights = (
lights or switch.get_lights()
) # pylint: disable=protected-access
all_lights = lights or switch.all_lights # pylint: disable=protected-access
if service_call.data[CONF_MANUAL_CONTROL]:
for light in all_lights:
_fire_manual_control_event(switch, light, service_call.context)
@ -938,7 +932,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
return self._state
@property
def get_lights(self):
def all_lights(self):
self._update_lights()
return self._lights
@ -989,7 +983,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
self.remove_listeners.extend([remove_interval, remove_sleep])
lights = self.get_lights()
lights = self.all_lights
if lights:
remove_state = async_track_state_change_event(
self.hass, lights, self._light_event
@ -1014,7 +1008,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
for key in self._settings:
extra_state_attributes[key] = None
return extra_state_attributes
lights = self.get_lights()
lights = self.all_lights
extra_state_attributes["manual_control"] = [
light
for light in lights
@ -1057,7 +1051,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
if self.is_on:
return
self._state = True
self.turn_on_off_listener.reset(*self.get_lights())
self.turn_on_off_listener.reset(*self.all_lights)
await self._setup_listeners()
if adapt_lights:
await self._update_attrs_and_maybe_adapt_lights(
@ -1072,7 +1066,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
return
self._state = False
self._remove_listeners()
self.turn_on_off_listener.reset(*self.get_lights())
self.turn_on_off_listener.reset(*self.all_lights)
async def _async_update_at_interval(self, now=None) -> None:
await self._update_attrs_and_maybe_adapt_lights(
@ -1208,7 +1202,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
self.async_write_ha_state()
if lights is None:
lights = self.get_lights()
lights = self.all_lights
filtered_lights = []
if not force:
@ -1300,7 +1294,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
"%s: _sleep_mode_switch_state_event, event: '%s'", self._name, event
)
# Reset the manually controlled status when the "sleep mode" changes
self.turn_on_off_listener.reset(*self.get_lights())
self.turn_on_off_listener.reset(*self.all_lights)
await self._update_attrs_and_maybe_adapt_lights(
transition=self._sleep_transition,
force=True,