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

suggested fix for HA2025 deprecation warnings #1168

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 14 additions & 35 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,15 @@
import voluptuous as vol
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_FLASH,
ATTR_RGB_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
ATTR_TRANSITION,
ATTR_XY_COLOR,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS,
COLOR_MODE_RGB,
COLOR_MODE_RGBW,
COLOR_MODE_RGBWW,
COLOR_MODE_XY,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_TRANSITION,
ColorMode,
LightEntityFeature,
is_on,
preprocess_turn_on_alternatives,
)
Expand Down Expand Up @@ -179,13 +169,6 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity_platform import AddEntitiesCallback

_SUPPORT_OPTS = {
"brightness": SUPPORT_BRIGHTNESS,
"color_temp": SUPPORT_COLOR_TEMP,
"color": SUPPORT_COLOR,
"transition": SUPPORT_TRANSITION,
}


_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -651,17 +634,19 @@ def _supported_features(hass: HomeAssistant, light: str) -> set[str]:
assert state is not None
supported_features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
assert isinstance(supported_features, int)
supported = {
key for key, value in _SUPPORT_OPTS.items() if supported_features & value
}

supported = set()

if supported_features & LightEntityFeature.TRANSITION:
supported.add("transition")

supported_color_modes = state.attributes.get(ATTR_SUPPORTED_COLOR_MODES, set())
color_modes = {
COLOR_MODE_RGB,
COLOR_MODE_RGBW,
COLOR_MODE_RGBWW,
COLOR_MODE_XY,
COLOR_MODE_HS,
ColorMode.RGB,
ColorMode.RGBW,
ColorMode.RGBWW,
ColorMode.XY,
ColorMode.HS,
}

# Adding brightness when color mode is supported, see
Expand All @@ -672,10 +657,10 @@ def _supported_features(hass: HomeAssistant, light: str) -> set[str]:
supported.update({"color", "brightness"})
break

if COLOR_MODE_COLOR_TEMP in supported_color_modes:
if ColorMode.COLOR_TEMP in supported_color_modes:
supported.update({"color_temp", "brightness"})

if COLOR_MODE_BRIGHTNESS in supported_color_modes:
if ColorMode.BRIGHTNESS in supported_color_modes:
supported.add("brightness")

return supported
Expand Down Expand Up @@ -2009,12 +1994,6 @@ def modify_service_data(service_data, entity_ids):
context.id,
)
service_data = {ATTR_ENTITY_ID: skipped, **service_data_copy[CONF_PARAMS]}
if (
ATTR_COLOR_TEMP in service_data
and ATTR_COLOR_TEMP_KELVIN in service_data
):
# ATTR_COLOR_TEMP and ATTR_COLOR_TEMP_KELVIN are mutually exclusive
del service_data[ATTR_COLOR_TEMP]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can this code be deleted?

await self.hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
Expand Down
Loading