From 9ab9fcfc56405da50314e0cb1666c255a1c75738 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 6 Apr 2022 10:55:25 +0200 Subject: [PATCH] Use EntityFeature enum in components (f**) (#69389) --- homeassistant/components/fibaro/climate.py | 19 +++--- homeassistant/components/fjaraskupan/fan.py | 13 +---- homeassistant/components/flexit/climate.py | 21 +++---- homeassistant/components/flux_led/light.py | 5 +- homeassistant/components/foscam/camera.py | 12 +--- .../components/freedompro/climate.py | 5 +- homeassistant/components/freedompro/cover.py | 8 +-- homeassistant/components/freedompro/fan.py | 11 +--- homeassistant/components/fritzbox/climate.py | 13 ++--- .../frontier_silicon/media_player.py | 58 +++++++------------ 10 files changed, 61 insertions(+), 104 deletions(-) diff --git a/homeassistant/components/fibaro/climate.py b/homeassistant/components/fibaro/climate.py index b639324acd0..89e319a5a8c 100644 --- a/homeassistant/components/fibaro/climate.py +++ b/homeassistant/components/fibaro/climate.py @@ -3,7 +3,11 @@ from __future__ import annotations import logging -from homeassistant.components.climate import ENTITY_ID_FORMAT, ClimateEntity +from homeassistant.components.climate import ( + ENTITY_ID_FORMAT, + ClimateEntity, + ClimateEntityFeature, +) from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_COOL, @@ -13,9 +17,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_OFF, PRESET_AWAY, PRESET_BOOST, - SUPPORT_FAN_MODE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT @@ -157,16 +158,16 @@ class FibaroThermostat(FibaroDevice, ClimateEntity): or "setHeatingThermostatSetpoint" in device.actions ): self._target_temp_device = FibaroDevice(device) - self._support_flags |= SUPPORT_TARGET_TEMPERATURE + self._support_flags |= ClimateEntityFeature.TARGET_TEMPERATURE tempunit = device.properties.unit if "setMode" in device.actions or "setOperatingMode" in device.actions: self._op_mode_device = FibaroDevice(device) - self._support_flags |= SUPPORT_PRESET_MODE + self._support_flags |= ClimateEntityFeature.PRESET_MODE if "setFanMode" in device.actions: self._fan_mode_device = FibaroDevice(device) - self._support_flags |= SUPPORT_FAN_MODE + self._support_flags |= ClimateEntityFeature.FAN_MODE if tempunit == "F": self._unit_of_temp = TEMP_FAHRENHEIT @@ -286,7 +287,7 @@ class FibaroThermostat(FibaroDevice, ClimateEntity): def preset_mode(self): """Return the current preset mode, e.g., home, away, temp. - Requires SUPPORT_PRESET_MODE. + Requires ClimateEntityFeature.PRESET_MODE. """ if not self._op_mode_device: return None @@ -304,7 +305,7 @@ class FibaroThermostat(FibaroDevice, ClimateEntity): def preset_modes(self): """Return a list of available preset modes. - Requires SUPPORT_PRESET_MODE. + Requires ClimateEntityFeature.PRESET_MODE. """ if not self._op_mode_device: return None diff --git a/homeassistant/components/fjaraskupan/fan.py b/homeassistant/components/fjaraskupan/fan.py index 4b04910a167..a8f8e13f3da 100644 --- a/homeassistant/components/fjaraskupan/fan.py +++ b/homeassistant/components/fjaraskupan/fan.py @@ -10,11 +10,7 @@ from fjaraskupan import ( State, ) -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, callback from homeassistant.exceptions import HomeAssistantError @@ -73,6 +69,8 @@ async def async_setup_entry( class Fan(CoordinatorEntity[DataUpdateCoordinator[State]], FanEntity): """Fan entity.""" + _attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE + def __init__( self, coordinator: DataUpdateCoordinator[State], @@ -155,11 +153,6 @@ class Fan(CoordinatorEntity[DataUpdateCoordinator[State]], FanEntity): """Return the current speed.""" return self._percentage - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_SET_SPEED | SUPPORT_PRESET_MODE - @property def is_on(self) -> bool: """Return true if fan is on.""" diff --git a/homeassistant/components/flexit/climate.py b/homeassistant/components/flexit/climate.py index 9e2b9e41255..f7433d32a0e 100644 --- a/homeassistant/components/flexit/climate.py +++ b/homeassistant/components/flexit/climate.py @@ -5,12 +5,12 @@ import logging import voluptuous as vol -from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity -from homeassistant.components.climate.const import ( - HVAC_MODE_COOL, - SUPPORT_FAN_MODE, - SUPPORT_TARGET_TEMPERATURE, +from homeassistant.components.climate import ( + PLATFORM_SCHEMA, + ClimateEntity, + ClimateEntityFeature, ) +from homeassistant.components.climate.const import HVAC_MODE_COOL from homeassistant.components.modbus import get_hub from homeassistant.components.modbus.const import ( CALL_TYPE_REGISTER_HOLDING, @@ -42,8 +42,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( _LOGGER = logging.getLogger(__name__) -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE - async def async_setup_platform( hass: HomeAssistant, @@ -61,6 +59,10 @@ async def async_setup_platform( class Flexit(ClimateEntity): """Representation of a Flexit AC unit.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE + ) + def __init__( self, hub: ModbusHub, modbus_slave: int | None, name: str | None ) -> None: @@ -83,11 +85,6 @@ class Flexit(ClimateEntity): self._alarm = False self._outdoor_air_temp = None - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS - async def async_update(self): """Update unit attributes.""" self._target_temperature = await self._async_read_temp_from_register( diff --git a/homeassistant/components/flux_led/light.py b/homeassistant/components/flux_led/light.py index 2942a13c734..202f0f95e23 100644 --- a/homeassistant/components/flux_led/light.py +++ b/homeassistant/components/flux_led/light.py @@ -19,9 +19,8 @@ from homeassistant.components.light import ( ATTR_RGBW_COLOR, ATTR_RGBWW_COLOR, ATTR_WHITE, - SUPPORT_EFFECT, - SUPPORT_TRANSITION, LightEntity, + LightEntityFeature, ) from homeassistant.const import CONF_NAME from homeassistant.core import HomeAssistant, callback @@ -192,7 +191,7 @@ class FluxLight( ): """Representation of a Flux light.""" - _attr_supported_features = SUPPORT_TRANSITION | SUPPORT_EFFECT + _attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT def __init__( self, diff --git a/homeassistant/components/foscam/camera.py b/homeassistant/components/foscam/camera.py index eee1e136af0..d3eaf0d03d3 100644 --- a/homeassistant/components/foscam/camera.py +++ b/homeassistant/components/foscam/camera.py @@ -6,7 +6,7 @@ import asyncio from libpyfoscam import FoscamCamera import voluptuous as vol -from homeassistant.components.camera import SUPPORT_STREAM, Camera +from homeassistant.components.camera import Camera, CameraEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from homeassistant.core import HomeAssistant @@ -106,6 +106,8 @@ class HassFoscamCamera(Camera): self._unique_id = config_entry.entry_id self._rtsp_port = config_entry.data[CONF_RTSP_PORT] self._motion_status = False + if self._rtsp_port: + self._attr_supported_features = CameraEntityFeature.STREAM async def async_added_to_hass(self): """Handle entity addition to hass.""" @@ -145,14 +147,6 @@ class HassFoscamCamera(Camera): return response - @property - def supported_features(self): - """Return supported features.""" - if self._rtsp_port: - return SUPPORT_STREAM - - return None - async def stream_source(self): """Return the stream source.""" if self._rtsp_port: diff --git a/homeassistant/components/freedompro/climate.py b/homeassistant/components/freedompro/climate.py index 8e84e4f3d51..04ca01fdc07 100644 --- a/homeassistant/components/freedompro/climate.py +++ b/homeassistant/components/freedompro/climate.py @@ -4,13 +4,12 @@ import logging from pyfreedompro import put_state -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, CONF_API_KEY, TEMP_CELSIUS @@ -72,7 +71,7 @@ class Device(CoordinatorEntity, ClimateEntity): model=device["type"], name=self.name, ) - self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE + self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE self._attr_current_temperature = 0 self._attr_target_temperature = 0 self._attr_hvac_mode = HVAC_MODE_OFF diff --git a/homeassistant/components/freedompro/cover.py b/homeassistant/components/freedompro/cover.py index 7525d37182f..ab3914519dd 100644 --- a/homeassistant/components/freedompro/cover.py +++ b/homeassistant/components/freedompro/cover.py @@ -5,11 +5,9 @@ from pyfreedompro import put_state from homeassistant.components.cover import ( ATTR_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY @@ -66,7 +64,9 @@ class Device(CoordinatorEntity, CoverEntity): self._attr_current_cover_position = 0 self._attr_is_closed = True self._attr_supported_features = ( - SUPPORT_CLOSE | SUPPORT_OPEN | SUPPORT_SET_POSITION + CoverEntityFeature.CLOSE + | CoverEntityFeature.OPEN + | CoverEntityFeature.SET_POSITION ) self._attr_device_class = DEVICE_CLASS_MAP[device["type"]] diff --git a/homeassistant/components/freedompro/fan.py b/homeassistant/components/freedompro/fan.py index dc7e3bb3d9d..b7758813865 100644 --- a/homeassistant/components/freedompro/fan.py +++ b/homeassistant/components/freedompro/fan.py @@ -5,7 +5,7 @@ import json from pyfreedompro import put_state -from homeassistant.components.fan import SUPPORT_SET_SPEED, FanEntity +from homeassistant.components.fan import FanEntity, FanEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY from homeassistant.core import HomeAssistant, callback @@ -51,6 +51,8 @@ class FreedomproFan(CoordinatorEntity, FanEntity): ) self._attr_is_on = False self._attr_percentage = 0 + if "rotationSpeed" in self._characteristics: + self._attr_supported_features = FanEntityFeature.SET_SPEED @property def is_on(self) -> bool | None: @@ -62,13 +64,6 @@ class FreedomproFan(CoordinatorEntity, FanEntity): """Return the current speed percentage.""" return self._attr_percentage - @property - def supported_features(self): - """Flag supported features.""" - if "rotationSpeed" in self._characteristics: - return SUPPORT_SET_SPEED - return 0 - @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" diff --git a/homeassistant/components/fritzbox/climate.py b/homeassistant/components/fritzbox/climate.py index f27b1efa857..ce21c080588 100644 --- a/homeassistant/components/fritzbox/climate.py +++ b/homeassistant/components/fritzbox/climate.py @@ -3,15 +3,13 @@ from __future__ import annotations from typing import Any -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_OFF, PRESET_COMFORT, PRESET_ECO, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -34,8 +32,6 @@ from .const import ( ) from .model import ClimateExtraAttributes -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE - OPERATION_LIST = [HVAC_MODE_HEAT, HVAC_MODE_OFF] MIN_TEMPERATURE = 8 @@ -68,10 +64,9 @@ async def async_setup_entry( class FritzboxThermostat(FritzBoxEntity, ClimateEntity): """The thermostat class for FRITZ!SmartHome thermostats.""" - @property - def supported_features(self) -> int: - """Return the list of supported features.""" - return SUPPORT_FLAGS + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) @property def temperature_unit(self) -> str: diff --git a/homeassistant/components/frontier_silicon/media_player.py b/homeassistant/components/frontier_silicon/media_player.py index a7829e23c57..034762a09ac 100644 --- a/homeassistant/components/frontier_silicon/media_player.py +++ b/homeassistant/components/frontier_silicon/media_player.py @@ -7,23 +7,12 @@ from afsapi import AFSAPI import requests import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity -from homeassistant.components.media_player.const import ( - MEDIA_TYPE_MUSIC, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SEEK, - SUPPORT_SELECT_SOURCE, - SUPPORT_STOP, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, - SUPPORT_VOLUME_STEP, +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, ) +from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC from homeassistant.const import ( CONF_HOST, CONF_NAME, @@ -42,22 +31,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType _LOGGER = logging.getLogger(__name__) -SUPPORT_FRONTIER_SILICON = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_MUTE - | SUPPORT_VOLUME_STEP - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_SEEK - | SUPPORT_PLAY_MEDIA - | SUPPORT_PLAY - | SUPPORT_STOP - | SUPPORT_TURN_ON - | SUPPORT_TURN_OFF - | SUPPORT_SELECT_SOURCE -) - DEFAULT_PORT = 80 DEFAULT_PASSWORD = "1234" @@ -104,6 +77,22 @@ async def async_setup_platform( class AFSAPIDevice(MediaPlayerEntity): """Representation of a Frontier Silicon device on the network.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.SEEK + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.SELECT_SOURCE + ) + def __init__(self, device_url, password, name): """Initialize the Frontier Silicon API device.""" self._device_url = device_url @@ -158,11 +147,6 @@ class AFSAPIDevice(MediaPlayerEntity): """Content type of current playing media.""" return MEDIA_TYPE_MUSIC - @property - def supported_features(self): - """Flag of media commands that are supported.""" - return SUPPORT_FRONTIER_SILICON - @property def state(self): """Return the state of the player."""