From cac8d71764d33009cdad55591a7e0b1c09c8c345 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 7 Apr 2022 15:15:05 +0200 Subject: [PATCH] Use EntityFeature enum in components (o**) (#69433) --- homeassistant/components/oem/climate.py | 15 ++--- .../components/onkyo/media_player.py | 49 +++++--------- homeassistant/components/onvif/camera.py | 9 +-- homeassistant/components/opengarage/cover.py | 5 +- .../components/openhome/media_player.py | 67 ++++++++----------- .../components/opentherm_gw/climate.py | 19 +++--- .../components/overkiz/alarm_control_panel.py | 26 +++---- 7 files changed, 80 insertions(+), 110 deletions(-) diff --git a/homeassistant/components/oem/climate.py b/homeassistant/components/oem/climate.py index d5b4ffe5d71..babd93953db 100644 --- a/homeassistant/components/oem/climate.py +++ b/homeassistant/components/oem/climate.py @@ -5,7 +5,11 @@ from oemthermostat import Thermostat import requests import voluptuous as vol -from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity +from homeassistant.components.climate import ( + PLATFORM_SCHEMA, + ClimateEntity, + ClimateEntityFeature, +) from homeassistant.components.climate.const import ( CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, @@ -13,7 +17,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.const import ( ATTR_TEMPERATURE, @@ -39,7 +42,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( } ) -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] @@ -67,6 +69,8 @@ def setup_platform( class ThermostatDevice(ClimateEntity): """Interface class for the oemthermostat module.""" + _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE + def __init__(self, thermostat, name): """Initialize the device.""" self._name = name @@ -78,11 +82,6 @@ class ThermostatDevice(ClimateEntity): self._setpoint = None self._mode = None - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS - @property def hvac_mode(self): """Return hvac operation ie. heat, cool mode. diff --git a/homeassistant/components/onkyo/media_player.py b/homeassistant/components/onkyo/media_player.py index aafcbf6a54d..381f48b0b16 100644 --- a/homeassistant/components/onkyo/media_player.py +++ b/homeassistant/components/onkyo/media_player.py @@ -7,18 +7,12 @@ import eiscp from eiscp import eISCP import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity -from homeassistant.components.media_player.const import ( - DOMAIN, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_SELECT_SOURCE, - 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 DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, CONF_HOST, @@ -41,23 +35,19 @@ DEFAULT_NAME = "Onkyo Receiver" SUPPORTED_MAX_VOLUME = 100 DEFAULT_RECEIVER_MAX_VOLUME = 80 -SUPPORT_ONKYO = ( - SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_MUTE - | SUPPORT_VOLUME_STEP - | SUPPORT_TURN_ON - | SUPPORT_TURN_OFF - | SUPPORT_SELECT_SOURCE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA -) SUPPORT_ONKYO_WO_VOLUME = ( - SUPPORT_TURN_ON - | SUPPORT_TURN_OFF - | SUPPORT_SELECT_SOURCE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA + MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA +) +SUPPORT_ONKYO = ( + SUPPORT_ONKYO_WO_VOLUME + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_STEP ) KNOWN_HOSTS: list[str] = [] @@ -254,6 +244,8 @@ def setup_platform( class OnkyoDevice(MediaPlayerEntity): """Representation of an Onkyo device.""" + _attr_supported_features = SUPPORT_ONKYO + def __init__( self, receiver, @@ -389,11 +381,6 @@ class OnkyoDevice(MediaPlayerEntity): """Return boolean indicating mute status.""" return self._muted - @property - def supported_features(self): - """Return media player features that are supported.""" - return SUPPORT_ONKYO - @property def source(self): """Return the current input source of the device.""" diff --git a/homeassistant/components/onvif/camera.py b/homeassistant/components/onvif/camera.py index c5f68661e69..9393b61f37b 100644 --- a/homeassistant/components/onvif/camera.py +++ b/homeassistant/components/onvif/camera.py @@ -7,7 +7,7 @@ import voluptuous as vol from yarl import URL from homeassistant.components import ffmpeg -from homeassistant.components.camera import SUPPORT_STREAM, Camera +from homeassistant.components.camera import Camera, CameraEntityFeature from homeassistant.components.ffmpeg import CONF_EXTRA_ARGUMENTS, get_ffmpeg_manager from homeassistant.config_entries import ConfigEntry from homeassistant.const import HTTP_BASIC_AUTHENTICATION @@ -88,6 +88,8 @@ async def async_setup_entry( class ONVIFCameraEntity(ONVIFBaseEntity, Camera): """Representation of an ONVIF camera.""" + _attr_supported_features = CameraEntityFeature.STREAM + def __init__(self, device, profile): """Initialize ONVIF camera entity.""" ONVIFBaseEntity.__init__(self, device, profile) @@ -101,11 +103,6 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera): ) self._stream_uri = None - @property - def supported_features(self) -> int: - """Return supported features.""" - return SUPPORT_STREAM - @property def name(self) -> str: """Return the name of this camera.""" diff --git a/homeassistant/components/opengarage/cover.py b/homeassistant/components/opengarage/cover.py index 86edd074ed2..9d5bd6e5cb6 100644 --- a/homeassistant/components/opengarage/cover.py +++ b/homeassistant/components/opengarage/cover.py @@ -2,10 +2,9 @@ import logging from homeassistant.components.cover import ( - SUPPORT_CLOSE, - SUPPORT_OPEN, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING @@ -33,7 +32,7 @@ class OpenGarageCover(OpenGarageEntity, CoverEntity): """Representation of a OpenGarage cover.""" _attr_device_class = CoverDeviceClass.GARAGE - _attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE + _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE def __init__(self, open_garage_data_coordinator, device_id): """Initialize the cover.""" diff --git a/homeassistant/components/openhome/media_player.py b/homeassistant/components/openhome/media_player.py index 21c3c465775..95d9ca57992 100644 --- a/homeassistant/components/openhome/media_player.py +++ b/homeassistant/components/openhome/media_player.py @@ -11,26 +11,14 @@ from openhomedevice.device import Device import voluptuous as vol from homeassistant.components import media_source -from homeassistant.components.media_player import MediaPlayerEntity +from homeassistant.components.media_player import ( + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.browse_media import ( async_process_play_media_url, ) -from homeassistant.components.media_player.const import ( - MEDIA_TYPE_MUSIC, - SUPPORT_BROWSE_MEDIA, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - 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.const import MEDIA_TYPE_MUSIC from homeassistant.const import STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv, entity_platform @@ -39,7 +27,11 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from .const import ATTR_PIN_INDEX, DATA_OPENHOME, SERVICE_INVOKE_PIN -SUPPORT_OPENHOME = SUPPORT_SELECT_SOURCE | SUPPORT_TURN_OFF | SUPPORT_TURN_ON +SUPPORT_OPENHOME = ( + MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.TURN_ON +) _LOGGER = logging.getLogger(__name__) @@ -113,7 +105,7 @@ class OpenhomeDevice(MediaPlayerEntity): self._transport_state = None self._volume_level = None self._volume_muted = None - self._supported_features = SUPPORT_OPENHOME + self._attr_supported_features = SUPPORT_OPENHOME self._source_names = [] self._source_index = {} self._source = {} @@ -134,13 +126,15 @@ class OpenhomeDevice(MediaPlayerEntity): self._track_information = await self._device.track_info() self._source = await self._device.source() self._name = await self._device.room() - self._supported_features = SUPPORT_OPENHOME + self._attr_supported_features = SUPPORT_OPENHOME source_index = {} source_names = [] if self._device.volume_enabled: - self._supported_features |= ( - SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET + self._attr_supported_features |= ( + MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_SET ) self._volume_level = await self._device.volume() / 100.0 self._volume_muted = await self._device.is_muted() @@ -153,20 +147,20 @@ class OpenhomeDevice(MediaPlayerEntity): self._source_names = source_names if self._source["type"] == "Radio": - self._supported_features |= ( - SUPPORT_STOP - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_BROWSE_MEDIA + self._attr_supported_features |= ( + MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.BROWSE_MEDIA ) if self._source["type"] in ("Playlist", "Spotify"): - self._supported_features |= ( - SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_PAUSE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_BROWSE_MEDIA + self._attr_supported_features |= ( + MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.BROWSE_MEDIA ) if self._in_standby: @@ -262,11 +256,6 @@ class OpenhomeDevice(MediaPlayerEntity): """Return the name of the device.""" return self._name - @property - def supported_features(self): - """Flag of features commands that are supported.""" - return self._supported_features - @property def unique_id(self): """Return a unique ID.""" diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index e6b15688fb6..4441fa0968e 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -3,7 +3,11 @@ import logging from pyotgw import vars as gw_vars -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 ( CURRENT_HVAC_COOL, CURRENT_HVAC_HEAT, @@ -12,8 +16,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_HEAT, PRESET_AWAY, PRESET_NONE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -43,8 +45,6 @@ _LOGGER = logging.getLogger(__name__) DEFAULT_FLOOR_TEMP = False -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE - async def async_setup_entry( hass: HomeAssistant, @@ -66,6 +66,10 @@ async def async_setup_entry( class OpenThermClimate(ClimateEntity): """Representation of a climate device.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) + def __init__(self, gw_dev, options): """Initialize the device.""" self._gateway = gw_dev @@ -284,11 +288,6 @@ class OpenThermClimate(ClimateEntity): ) self.async_write_ha_state() - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_FLAGS - @property def min_temp(self): """Return the minimum temperature.""" diff --git a/homeassistant/components/overkiz/alarm_control_panel.py b/homeassistant/components/overkiz/alarm_control_panel.py index 059f2562544..2229c583297 100644 --- a/homeassistant/components/overkiz/alarm_control_panel.py +++ b/homeassistant/components/overkiz/alarm_control_panel.py @@ -12,12 +12,7 @@ from pyoverkiz.types import StateType as OverkizStateType from homeassistant.components.alarm_control_panel import ( AlarmControlPanelEntity, AlarmControlPanelEntityDescription, -) -from homeassistant.components.alarm_control_panel.const import ( - SUPPORT_ALARM_ARM_AWAY, - SUPPORT_ALARM_ARM_HOME, - SUPPORT_ALARM_ARM_NIGHT, - SUPPORT_ALARM_TRIGGER, + AlarmControlPanelEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -162,10 +157,10 @@ ALARM_DESCRIPTIONS: list[OverkizAlarmDescription] = [ key=UIWidget.TSKALARM_CONTROLLER, entity_registry_enabled_default=False, supported_features=( - SUPPORT_ALARM_ARM_AWAY - | SUPPORT_ALARM_ARM_HOME - | SUPPORT_ALARM_ARM_NIGHT - | SUPPORT_ALARM_TRIGGER + AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_NIGHT + | AlarmControlPanelEntityFeature.TRIGGER ), fn_state=_state_tsk_alarm_controller, alarm_disarm=OverkizCommand.ALARM_OFF, @@ -181,7 +176,9 @@ ALARM_DESCRIPTIONS: list[OverkizAlarmDescription] = [ OverkizAlarmDescription( key=UIWidget.STATEFUL_ALARM_CONTROLLER, supported_features=( - SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_NIGHT + AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_NIGHT ), fn_state=_state_stateful_alarm_controller, alarm_disarm=OverkizCommand.ALARM_OFF, @@ -195,7 +192,8 @@ ALARM_DESCRIPTIONS: list[OverkizAlarmDescription] = [ # MyFoxAlarmController OverkizAlarmDescription( key=UIWidget.MY_FOX_ALARM_CONTROLLER, - supported_features=SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT, + supported_features=AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_NIGHT, fn_state=_state_myfox_alarm_controller, alarm_disarm=OverkizCommand.DISARM, alarm_arm_night=OverkizCommand.PARTIAL, @@ -205,7 +203,9 @@ ALARM_DESCRIPTIONS: list[OverkizAlarmDescription] = [ OverkizAlarmDescription( key=UIWidget.ALARM_PANEL_CONTROLLER, supported_features=( - SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_NIGHT + AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_NIGHT ), fn_state=_state_alarm_panel_controller, alarm_disarm=OverkizCommand.DISARM,