From 1cda675bbef3a987da434f2b71fc94c5f42fd5c3 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 26 Jul 2023 15:01:29 -0700 Subject: [PATCH] Add @bind_hass to functions (#667) --- custom_components/adaptive_lighting/switch.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 6dae39f2..6bba8afe 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -78,6 +78,7 @@ from homeassistant.helpers.event import ( from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.sun import get_astral_location from homeassistant.helpers.template import area_entities +from homeassistant.loader import bind_hass from homeassistant.util import slugify from homeassistant.util.color import ( color_RGB_to_xy, @@ -274,6 +275,7 @@ def is_our_context(context: Context | None) -> bool: return is_our_context_id(context.id) +@bind_hass def _switches_with_lights( hass: HomeAssistant, lights: list[str], @@ -299,6 +301,7 @@ class NoSwitchFoundError(ValueError): """No switches found for lights.""" +@bind_hass def _switch_with_lights( hass: HomeAssistant, lights: list[str], @@ -328,6 +331,7 @@ def _switch_with_lights( # For documentation on this function, see integration_entities() from HomeAssistant Core: # https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/template.py#L1109 +@bind_hass def _switches_from_service_call( hass: HomeAssistant, service_call: ServiceCall, @@ -617,6 +621,7 @@ def _is_state_event(event: Event, from_or_to_state: Iterable[str]): ) +@bind_hass def _expand_light_groups(hass: HomeAssistant, lights: list[str]) -> list[str]: all_lights = set() manager = hass.data[DOMAIN][ATTR_ADAPTIVE_LIGHTING_MANAGER] @@ -635,6 +640,7 @@ def _expand_light_groups(hass: HomeAssistant, lights: list[str]) -> list[str]: return list(all_lights) +@bind_hass def _supported_features(hass: HomeAssistant, light: str) -> set[str]: state = hass.states.get(light) supported_features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)