From 8af37235ecc5c3b73d1c4538c7485a5b80c8f3c3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 5 Apr 2022 23:53:45 +0200 Subject: [PATCH] Use EntityFeature enum in components (b**) (#69336) --- homeassistant/components/balboa/climate.py | 11 ++-- .../components/blackbird/media_player.py | 17 +++--- homeassistant/components/blebox/climate.py | 5 +- homeassistant/components/blebox/cover.py | 13 ++--- .../components/blink/alarm_control_panel.py | 8 ++- .../components/bluesound/media_player.py | 55 +++++++++---------- homeassistant/components/bond/cover.py | 19 +++---- homeassistant/components/bond/fan.py | 7 +-- homeassistant/components/bosch_shc/cover.py | 10 ++-- .../components/braviatv/media_player.py | 44 +++++---------- homeassistant/components/broadlink/remote.py | 7 ++- homeassistant/components/brunt/cover.py | 13 +++-- homeassistant/components/bsblan/climate.py | 10 ++-- 13 files changed, 97 insertions(+), 122 deletions(-) diff --git a/homeassistant/components/balboa/climate.py b/homeassistant/components/balboa/climate.py index 81016bbeb33..2d275460d66 100644 --- a/homeassistant/components/balboa/climate.py +++ b/homeassistant/components/balboa/climate.py @@ -3,7 +3,7 @@ from __future__ import annotations import asyncio -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, @@ -14,9 +14,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_FAN_MODE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -79,9 +76,11 @@ class BalboaSpaClimate(BalboaEntity, ClimateEntity): } scale = self._client.get_tempscale() self._attr_preset_modes = self._client.get_heatmode_stringlist() - self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE + self._attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) if self._client.have_blower(): - self._attr_supported_features |= SUPPORT_FAN_MODE + self._attr_supported_features |= ClimateEntityFeature.FAN_MODE self._attr_min_temp = self._client.tmin[self._client.TEMPRANGE_LOW][scale] self._attr_max_temp = self._client.tmax[self._client.TEMPRANGE_HIGH][scale] self._attr_temperature_unit = TEMP_FAHRENHEIT diff --git a/homeassistant/components/blackbird/media_player.py b/homeassistant/components/blackbird/media_player.py index b0fb9b785dd..a20c4294438 100644 --- a/homeassistant/components/blackbird/media_player.py +++ b/homeassistant/components/blackbird/media_player.py @@ -8,11 +8,10 @@ from pyblackbird import get_blackbird from serial import SerialException import voluptuous as vol -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity -from homeassistant.components.media_player.const import ( - SUPPORT_SELECT_SOURCE, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, ) from homeassistant.const import ( ATTR_ENTITY_ID, @@ -32,8 +31,6 @@ from .const import DOMAIN, SERVICE_SETALLZONES _LOGGER = logging.getLogger(__name__) -SUPPORT_BLACKBIRD = SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE - MEDIA_PLAYER_SCHEMA = vol.Schema({ATTR_ENTITY_ID: cv.comp_entity_ids}) ZONE_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string}) @@ -141,7 +138,11 @@ def setup_platform( class BlackbirdZone(MediaPlayerEntity): """Representation of a Blackbird matrix zone.""" - _attr_supported_features = SUPPORT_BLACKBIRD + _attr_supported_features = ( + MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.SELECT_SOURCE + ) def __init__(self, blackbird, sources, zone_id, zone_name): """Initialize new zone.""" diff --git a/homeassistant/components/blebox/climate.py b/homeassistant/components/blebox/climate.py index 1b864bd5537..36630b9df0e 100644 --- a/homeassistant/components/blebox/climate.py +++ b/homeassistant/components/blebox/climate.py @@ -1,12 +1,11 @@ """BleBox climate entity.""" -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, CURRENT_HVAC_OFF, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS @@ -31,7 +30,7 @@ async def async_setup_entry( class BleBoxClimateEntity(BleBoxEntity, ClimateEntity): """Representation of a BleBox climate feature (saunaBox).""" - _attr_supported_features = SUPPORT_TARGET_TEMPERATURE + _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_HEAT] _attr_temperature_unit = TEMP_CELSIUS diff --git a/homeassistant/components/blebox/cover.py b/homeassistant/components/blebox/cover.py index 3056144b2e6..09d28a4f87a 100644 --- a/homeassistant/components/blebox/cover.py +++ b/homeassistant/components/blebox/cover.py @@ -1,11 +1,8 @@ """BleBox cover entity.""" from homeassistant.components.cover import ( ATTR_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, - SUPPORT_STOP, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPENING @@ -35,9 +32,11 @@ class BleBoxCoverEntity(BleBoxEntity, CoverEntity): """Initialize a BleBox cover feature.""" super().__init__(feature) self._attr_device_class = BLEBOX_TO_HASS_DEVICE_CLASSES[feature.device_class] - position = SUPPORT_SET_POSITION if feature.is_slider else 0 - stop = SUPPORT_STOP if feature.has_stop else 0 - self._attr_supported_features = position | stop | SUPPORT_OPEN | SUPPORT_CLOSE + position = CoverEntityFeature.SET_POSITION if feature.is_slider else 0 + stop = CoverEntityFeature.STOP if feature.has_stop else 0 + self._attr_supported_features = ( + position | stop | CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE + ) @property def current_cover_position(self): diff --git a/homeassistant/components/blink/alarm_control_panel.py b/homeassistant/components/blink/alarm_control_panel.py index 52c05110394..dbea1371af2 100644 --- a/homeassistant/components/blink/alarm_control_panel.py +++ b/homeassistant/components/blink/alarm_control_panel.py @@ -1,8 +1,10 @@ """Support for Blink Alarm Control Panel.""" import logging -from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity -from homeassistant.components.alarm_control_panel.const import SUPPORT_ALARM_ARM_AWAY +from homeassistant.components.alarm_control_panel import ( + AlarmControlPanelEntity, + AlarmControlPanelEntityFeature, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_ATTRIBUTION, @@ -36,7 +38,7 @@ class BlinkSyncModule(AlarmControlPanelEntity): """Representation of a Blink Alarm Control Panel.""" _attr_icon = ICON - _attr_supported_features = SUPPORT_ALARM_ARM_AWAY + _attr_supported_features = AlarmControlPanelEntityFeature.ARM_AWAY def __init__(self, data, name, sync): """Initialize the alarm control panel.""" diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index 443d8faa5de..32f74743972 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -16,27 +16,17 @@ import voluptuous as vol import xmltodict from homeassistant.components import media_source -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, +) from homeassistant.components.media_player.browse_media import ( async_process_play_media_url, ) from homeassistant.components.media_player.const import ( ATTR_MEDIA_ENQUEUE, MEDIA_TYPE_MUSIC, - SUPPORT_BROWSE_MEDIA, - SUPPORT_CLEAR_PLAYLIST, - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PLAY_MEDIA, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SEEK, - SUPPORT_SELECT_SOURCE, - SUPPORT_SHUFFLE_SET, - SUPPORT_STOP, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, - SUPPORT_VOLUME_STEP, ) from homeassistant.const import ( ATTR_ENTITY_ID, @@ -803,34 +793,41 @@ class BluesoundPlayer(MediaPlayerEntity): return 0 if self.is_grouped and not self.is_master: - return SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE + return ( + MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE + ) - supported = SUPPORT_CLEAR_PLAYLIST | SUPPORT_BROWSE_MEDIA + supported = ( + MediaPlayerEntityFeature.CLEAR_PLAYLIST + | MediaPlayerEntityFeature.BROWSE_MEDIA + ) if self._status.get("indexing", "0") == "0": supported = ( supported - | SUPPORT_PAUSE - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_PLAY_MEDIA - | SUPPORT_STOP - | SUPPORT_PLAY - | SUPPORT_SELECT_SOURCE - | SUPPORT_SHUFFLE_SET + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PLAY_MEDIA + | MediaPlayerEntityFeature.STOP + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.SHUFFLE_SET ) current_vol = self.volume_level if current_vol is not None and current_vol >= 0: supported = ( supported - | SUPPORT_VOLUME_STEP - | SUPPORT_VOLUME_SET - | SUPPORT_VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.VOLUME_MUTE ) if self._status.get("canSeek", "") == "1": - supported = supported | SUPPORT_SEEK + supported = supported | MediaPlayerEntityFeature.SEEK return supported diff --git a/homeassistant/components/bond/cover.py b/homeassistant/components/bond/cover.py index 57be80c0fd7..664431a3145 100644 --- a/homeassistant/components/bond/cover.py +++ b/homeassistant/components/bond/cover.py @@ -6,14 +6,9 @@ from typing import Any from bond_api import Action, BPUPSubscriptions, DeviceType from homeassistant.components.cover import ( - SUPPORT_CLOSE, - SUPPORT_CLOSE_TILT, - SUPPORT_OPEN, - SUPPORT_OPEN_TILT, - SUPPORT_STOP, - SUPPORT_STOP_TILT, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -56,18 +51,18 @@ class BondCover(BondEntity, CoverEntity): super().__init__(hub, device, bpup_subs) supported_features = 0 if self._device.supports_open(): - supported_features |= SUPPORT_OPEN + supported_features |= CoverEntityFeature.OPEN if self._device.supports_close(): - supported_features |= SUPPORT_CLOSE + supported_features |= CoverEntityFeature.CLOSE if self._device.supports_tilt_open(): - supported_features |= SUPPORT_OPEN_TILT + supported_features |= CoverEntityFeature.OPEN_TILT if self._device.supports_tilt_close(): - supported_features |= SUPPORT_CLOSE_TILT + supported_features |= CoverEntityFeature.CLOSE_TILT if self._device.supports_hold(): if self._device.supports_open() or self._device.supports_close(): - supported_features |= SUPPORT_STOP + supported_features |= CoverEntityFeature.STOP if self._device.supports_tilt_open() or self._device.supports_tilt_close(): - supported_features |= SUPPORT_STOP_TILT + supported_features |= CoverEntityFeature.STOP_TILT self._attr_supported_features = supported_features def _apply_state(self, state: dict) -> None: diff --git a/homeassistant/components/bond/fan.py b/homeassistant/components/bond/fan.py index a2e35456ca3..9acc7874657 100644 --- a/homeassistant/components/bond/fan.py +++ b/homeassistant/components/bond/fan.py @@ -12,9 +12,8 @@ import voluptuous as vol from homeassistant.components.fan import ( DIRECTION_FORWARD, DIRECTION_REVERSE, - SUPPORT_DIRECTION, - SUPPORT_SET_SPEED, FanEntity, + FanEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -90,9 +89,9 @@ class BondFan(BondEntity, FanEntity): """Flag supported features.""" features = 0 if self._device.supports_speed(): - features |= SUPPORT_SET_SPEED + features |= FanEntityFeature.SET_SPEED if self._device.supports_direction(): - features |= SUPPORT_DIRECTION + features |= FanEntityFeature.DIRECTION return features diff --git a/homeassistant/components/bosch_shc/cover.py b/homeassistant/components/bosch_shc/cover.py index 6048cd51631..fd191d59bc3 100644 --- a/homeassistant/components/bosch_shc/cover.py +++ b/homeassistant/components/bosch_shc/cover.py @@ -3,12 +3,9 @@ from boschshcpy import SHCSession, SHCShutterControl from homeassistant.components.cover import ( ATTR_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, - SUPPORT_STOP, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -46,7 +43,10 @@ class ShutterControlCover(SHCEntity, CoverEntity): _attr_device_class = CoverDeviceClass.SHUTTER _attr_supported_features = ( - SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.STOP + | CoverEntityFeature.SET_POSITION ) @property diff --git a/homeassistant/components/braviatv/media_player.py b/homeassistant/components/braviatv/media_player.py index 99a2e5a1cb1..745325a4c39 100644 --- a/homeassistant/components/braviatv/media_player.py +++ b/homeassistant/components/braviatv/media_player.py @@ -1,24 +1,10 @@ """Support for interface with a Bravia TV.""" from __future__ import annotations -from typing import Final - from homeassistant.components.media_player import ( MediaPlayerDeviceClass, MediaPlayerEntity, -) -from homeassistant.components.media_player.const import ( - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SELECT_SOURCE, - SUPPORT_STOP, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, - SUPPORT_VOLUME_MUTE, - SUPPORT_VOLUME_SET, - SUPPORT_VOLUME_STEP, + MediaPlayerEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_OFF, STATE_PAUSED, STATE_PLAYING @@ -30,20 +16,6 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import BraviaTVCoordinator from .const import ATTR_MANUFACTURER, DEFAULT_NAME, DOMAIN -SUPPORT_BRAVIA: Final = ( - SUPPORT_PAUSE - | SUPPORT_VOLUME_STEP - | SUPPORT_VOLUME_MUTE - | SUPPORT_VOLUME_SET - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_NEXT_TRACK - | SUPPORT_TURN_ON - | SUPPORT_TURN_OFF - | SUPPORT_SELECT_SOURCE - | SUPPORT_PLAY - | SUPPORT_STOP -) - async def async_setup_entry( hass: HomeAssistant, @@ -71,7 +43,19 @@ class BraviaTVMediaPlayer(CoordinatorEntity[BraviaTVCoordinator], MediaPlayerEnt """Representation of a Bravia TV Media Player.""" _attr_device_class = MediaPlayerDeviceClass.TV - _attr_supported_features = SUPPORT_BRAVIA + _attr_supported_features = ( + MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.VOLUME_STEP + | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_SET + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.PLAY + | MediaPlayerEntityFeature.STOP + ) def __init__( self, diff --git a/homeassistant/components/broadlink/remote.py b/homeassistant/components/broadlink/remote.py index b7d81e5ba42..dd0f40d45bc 100644 --- a/homeassistant/components/broadlink/remote.py +++ b/homeassistant/components/broadlink/remote.py @@ -27,9 +27,8 @@ from homeassistant.components.remote import ( SERVICE_DELETE_COMMAND, SERVICE_LEARN_COMMAND, SERVICE_SEND_COMMAND, - SUPPORT_DELETE_COMMAND, - SUPPORT_LEARN_COMMAND, RemoteEntity, + RemoteEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_COMMAND, STATE_OFF @@ -117,7 +116,9 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity): self._attr_name = f"{device.name} Remote" self._attr_is_on = True - self._attr_supported_features = SUPPORT_LEARN_COMMAND | SUPPORT_DELETE_COMMAND + self._attr_supported_features = ( + RemoteEntityFeature.LEARN_COMMAND | RemoteEntityFeature.DELETE_COMMAND + ) self._attr_unique_id = device.unique_id def _extract_codes(self, commands, device=None): diff --git a/homeassistant/components/brunt/cover.py b/homeassistant/components/brunt/cover.py index 8bbb11914f7..c38dfa0eb78 100644 --- a/homeassistant/components/brunt/cover.py +++ b/homeassistant/components/brunt/cover.py @@ -9,11 +9,9 @@ from brunt import BruntClientAsync, Thing 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.core import HomeAssistant, callback @@ -37,8 +35,6 @@ from .const import ( REGULAR_INTERVAL, ) -COVER_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION - async def async_setup_entry( hass: HomeAssistant, @@ -62,6 +58,12 @@ class BruntDevice(CoordinatorEntity, CoverEntity): Contains the common logic for all Brunt devices. """ + _attr_supported_features = ( + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.SET_POSITION + ) + def __init__( self, coordinator: DataUpdateCoordinator, @@ -81,7 +83,6 @@ class BruntDevice(CoordinatorEntity, CoverEntity): self._attr_name = self._thing.name self._attr_device_class = CoverDeviceClass.BLIND - self._attr_supported_features = COVER_FEATURES self._attr_attribution = ATTRIBUTION self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self._attr_unique_id)}, diff --git a/homeassistant/components/bsblan/climate.py b/homeassistant/components/bsblan/climate.py index d7f4972c59e..8081b3f0638 100644 --- a/homeassistant/components/bsblan/climate.py +++ b/homeassistant/components/bsblan/climate.py @@ -7,7 +7,7 @@ from typing import Any from bsblan import BSBLan, BSBLanError, Info, State -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, ATTR_PRESET_MODE, @@ -16,8 +16,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_OFF, PRESET_ECO, PRESET_NONE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT @@ -32,8 +30,6 @@ _LOGGER = logging.getLogger(__name__) PARALLEL_UPDATES = 1 SCAN_INTERVAL = timedelta(seconds=20) -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE - HVAC_MODES = [ HVAC_MODE_AUTO, HVAC_MODE_HEAT, @@ -76,7 +72,9 @@ async def async_setup_entry( class BSBLanClimate(ClimateEntity): """Defines a BSBLan climate device.""" - _attr_supported_features = SUPPORT_FLAGS + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE + ) _attr_hvac_modes = HVAC_MODES _attr_preset_modes = PRESET_MODES