Deprecate SUPPORT_*-constants for Tradfri integration (#69368)

* Refactor constants

* Remove _LOGGER

* Fix sort order

* Refactor constats

* Run isort

* Remove SUPPORTED_ constants from Tradfri integration

* Remove constant

* Remove line

* Use brackets

* Add documentation

* Address review comments
pull/69515/head
Patrik Lindgren 2022-04-07 09:06:29 +02:00 committed by GitHub
parent f194f7809b
commit af5d29735f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 23 deletions

View File

@ -7,11 +7,7 @@ from typing import Any, cast
from pytradfri.command import Command
from homeassistant.components.fan import (
SUPPORT_PRESET_MODE,
SUPPORT_SET_SPEED,
FanEntity,
)
from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -58,6 +54,8 @@ async def async_setup_entry(
class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity):
"""The platform class required by Home Assistant."""
_attr_supported_features = FanEntityFeature.PRESET_MODE | FanEntityFeature.SET_SPEED
def __init__(
self,
device_coordinator: TradfriDeviceDataUpdateCoordinator,
@ -78,11 +76,6 @@ class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity):
"""Refresh the device."""
self._device_data = self.coordinator.data.air_purifier_control.air_purifiers[0]
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_PRESET_MODE + SUPPORT_SET_SPEED
@property
def speed_count(self) -> int:
"""

View File

@ -11,11 +11,11 @@ from homeassistant.components.light import (
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
ATTR_TRANSITION,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_TRANSITION,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS,
LightEntity,
LightEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -26,8 +26,6 @@ from .base_class import TradfriBaseEntity
from .const import CONF_GATEWAY_ID, COORDINATOR, COORDINATOR_LIST, DOMAIN, KEY_API
from .coordinator import TradfriDeviceDataUpdateCoordinator
SUPPORTED_LIGHT_FEATURES = SUPPORT_TRANSITION
async def async_setup_entry(
hass: HomeAssistant,
@ -53,6 +51,8 @@ async def async_setup_entry(
class TradfriLight(TradfriBaseEntity, LightEntity):
"""The platform class required by Home Assistant."""
_attr_supported_features = LightEntityFeature.TRANSITION
def __init__(
self,
device_coordinator: TradfriDeviceDataUpdateCoordinator,
@ -72,15 +72,19 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
self._attr_unique_id = f"light-{gateway_id}-{self._device_id}"
self._hs_color = None
# Calculate supported features
_features = SUPPORTED_LIGHT_FEATURES
if self._device.light_control.can_set_dimmer:
_features |= SUPPORT_BRIGHTNESS
# Calculate supported color modes
self._attr_supported_color_modes = set()
if self._device.light_control.can_set_color:
_features |= SUPPORT_COLOR | SUPPORT_COLOR_TEMP
self._attr_supported_color_modes.add(COLOR_MODE_HS)
if self._device.light_control.can_set_temp:
_features |= SUPPORT_COLOR_TEMP
self._attr_supported_features = _features
self._attr_supported_color_modes.add(COLOR_MODE_COLOR_TEMP)
if (
not self._attr_supported_color_modes
and self._device.light_control.can_set_dimmer
):
# Must be the only supported mode according to docs for
# COLOR_MODE_BRIGHTNESS
self._attr_supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
if self._device_control:
self._attr_min_mireds = self._device_control.min_mireds