Skip to content

Commit

Permalink
Start to fix deprecation warnings in HA.2024
Browse files Browse the repository at this point in the history
  • Loading branch information
h4de5 committed Apr 7, 2024
1 parent ddd17c7 commit eeb7374
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions custom_components/vimar/light.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
"""Platform for light integration."""

import logging

import homeassistant.util.color as color_util
from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR

from homeassistant.components.light import (
LightEntity,
ATTR_BRIGHTNESS,
ATTR_HS_COLOR,
ColorMode,
)
from .vimar_entity import VimarEntity, vimar_setup_entry

try:
from homeassistant.components.light import LightEntity
except ImportError:
from homeassistant.components.light import Light as LightEntity

from .const import DEVICE_TYPE_LIGHTS as CURR_PLATFORM

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,13 +60,26 @@ def hs_color(self):
return color_util.color_RGB_to_hs(*self.rgb_color)

@property
def supported_features(self):
"""Flag supported features."""
flags = 0
def color_mode(self) -> ColorMode:
"""Return the color mode of the light."""
if self.has_state("red") and self.has_state("green") and self.has_state("blue"):
return ColorMode.RGB
if self.has_state("value"):
flags |= SUPPORT_BRIGHTNESS
return ColorMode.BRIGHTNESS
return ColorMode.ONOFF

@property
def supported_color_modes(self) -> set[ColorMode] | None:
"""Flag supported color modes."""
flags: set[ColorMode] = set()

if self.has_state("red") and self.has_state("green") and self.has_state("blue"):
flags |= SUPPORT_COLOR
flags.add(ColorMode.RGB)
# flags.add(ColorMode.HS)
elif self.has_state("value"):
flags.add(ColorMode.BRIGHTNESS)
else:
flags.add(ColorMode.ONOFF)

return flags

Expand All @@ -82,7 +92,12 @@ async def async_turn_on(self, **kwargs):
else:
if ATTR_BRIGHTNESS in kwargs and self.has_state("value"):
brightness_value = self.calculate_brightness(kwargs[ATTR_BRIGHTNESS])
self.change_state("value", brightness_value, "on/off", ("0", "1")[brightness_value > 0])
self.change_state(
"value",
brightness_value,
"on/off",
("0", "1")[brightness_value > 0],
)

if ATTR_HS_COLOR in kwargs and self.has_state("red"):
rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
Expand Down

0 comments on commit eeb7374

Please sign in to comment.