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 commentspull/69515/head
parent
f194f7809b
commit
af5d29735f
|
@ -7,11 +7,7 @@ from typing import Any, cast
|
||||||
|
|
||||||
from pytradfri.command import Command
|
from pytradfri.command import Command
|
||||||
|
|
||||||
from homeassistant.components.fan import (
|
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_SET_SPEED,
|
|
||||||
FanEntity,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
@ -58,6 +54,8 @@ async def async_setup_entry(
|
||||||
class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity):
|
class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity):
|
||||||
"""The platform class required by Home Assistant."""
|
"""The platform class required by Home Assistant."""
|
||||||
|
|
||||||
|
_attr_supported_features = FanEntityFeature.PRESET_MODE | FanEntityFeature.SET_SPEED
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
||||||
|
@ -78,11 +76,6 @@ class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity):
|
||||||
"""Refresh the device."""
|
"""Refresh the device."""
|
||||||
self._device_data = self.coordinator.data.air_purifier_control.air_purifiers[0]
|
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
|
@property
|
||||||
def speed_count(self) -> int:
|
def speed_count(self) -> int:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -11,11 +11,11 @@ from homeassistant.components.light import (
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
SUPPORT_BRIGHTNESS,
|
COLOR_MODE_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
COLOR_MODE_COLOR_TEMP,
|
||||||
SUPPORT_COLOR_TEMP,
|
COLOR_MODE_HS,
|
||||||
SUPPORT_TRANSITION,
|
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
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 .const import CONF_GATEWAY_ID, COORDINATOR, COORDINATOR_LIST, DOMAIN, KEY_API
|
||||||
from .coordinator import TradfriDeviceDataUpdateCoordinator
|
from .coordinator import TradfriDeviceDataUpdateCoordinator
|
||||||
|
|
||||||
SUPPORTED_LIGHT_FEATURES = SUPPORT_TRANSITION
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -53,6 +51,8 @@ async def async_setup_entry(
|
||||||
class TradfriLight(TradfriBaseEntity, LightEntity):
|
class TradfriLight(TradfriBaseEntity, LightEntity):
|
||||||
"""The platform class required by Home Assistant."""
|
"""The platform class required by Home Assistant."""
|
||||||
|
|
||||||
|
_attr_supported_features = LightEntityFeature.TRANSITION
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
||||||
|
@ -72,15 +72,19 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
|
||||||
self._attr_unique_id = f"light-{gateway_id}-{self._device_id}"
|
self._attr_unique_id = f"light-{gateway_id}-{self._device_id}"
|
||||||
self._hs_color = None
|
self._hs_color = None
|
||||||
|
|
||||||
# Calculate supported features
|
# Calculate supported color modes
|
||||||
_features = SUPPORTED_LIGHT_FEATURES
|
self._attr_supported_color_modes = set()
|
||||||
if self._device.light_control.can_set_dimmer:
|
|
||||||
_features |= SUPPORT_BRIGHTNESS
|
|
||||||
if self._device.light_control.can_set_color:
|
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:
|
if self._device.light_control.can_set_temp:
|
||||||
_features |= SUPPORT_COLOR_TEMP
|
self._attr_supported_color_modes.add(COLOR_MODE_COLOR_TEMP)
|
||||||
self._attr_supported_features = _features
|
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:
|
if self._device_control:
|
||||||
self._attr_min_mireds = self._device_control.min_mireds
|
self._attr_min_mireds = self._device_control.min_mireds
|
||||||
|
|
Loading…
Reference in New Issue