Use EntityFeature enum in components (a**) (#69333)

This commit is contained in:
epenet 2022-04-05 23:42:05 +02:00 committed by GitHub
parent 8b2948f030
commit 246f4e081a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 169 additions and 237 deletions

View file

@ -4,10 +4,7 @@ from __future__ import annotations
from abodepy.devices.alarm import AbodeAlarm as AbodeAl from abodepy.devices.alarm import AbodeAlarm as AbodeAl
import homeassistant.components.alarm_control_panel as alarm import homeassistant.components.alarm_control_panel as alarm
from homeassistant.components.alarm_control_panel.const import ( from homeassistant.components.alarm_control_panel import AlarmControlPanelEntityFeature
SUPPORT_ALARM_ARM_AWAY,
SUPPORT_ALARM_ARM_HOME,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_AWAY,
@ -38,7 +35,10 @@ class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
_attr_icon = ICON _attr_icon = ICON
_attr_code_arm_required = False _attr_code_arm_required = False
_attr_supported_features = SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY _attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)
_device: AbodeAl _device: AbodeAl
@property @property

View file

@ -3,15 +3,8 @@ from __future__ import annotations
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_POSITION, ATTR_POSITION,
SUPPORT_CLOSE,
SUPPORT_CLOSE_TILT,
SUPPORT_OPEN,
SUPPORT_OPEN_TILT,
SUPPORT_SET_POSITION,
SUPPORT_SET_TILT_POSITION,
SUPPORT_STOP,
SUPPORT_STOP_TILT,
CoverEntity, CoverEntity,
CoverEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -79,14 +72,17 @@ class AcmedaCover(AcmedaBase, CoverEntity):
supported_features = 0 supported_features = 0
if self.current_cover_position is not None: if self.current_cover_position is not None:
supported_features |= ( supported_features |= (
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION CoverEntityFeature.OPEN
| CoverEntityFeature.CLOSE
| CoverEntityFeature.STOP
| CoverEntityFeature.SET_POSITION
) )
if self.current_cover_tilt_position is not None: if self.current_cover_tilt_position is not None:
supported_features |= ( supported_features |= (
SUPPORT_OPEN_TILT CoverEntityFeature.OPEN_TILT
| SUPPORT_CLOSE_TILT | CoverEntityFeature.CLOSE_TILT
| SUPPORT_STOP_TILT | CoverEntityFeature.STOP_TILT
| SUPPORT_SET_TILT_POSITION | CoverEntityFeature.SET_TILT_POSITION
) )
return supported_features return supported_features

View file

@ -8,11 +8,8 @@ from homeassistant.components.cover import (
ATTR_POSITION, ATTR_POSITION,
DEVICE_CLASSES_SCHEMA, DEVICE_CLASSES_SCHEMA,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
SUPPORT_STOP,
CoverEntity, CoverEntity,
CoverEntityFeature,
) )
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -117,11 +114,13 @@ class AdsCover(AdsEntity, CoverEntity):
self._ads_var_close = ads_var_close self._ads_var_close = ads_var_close
self._ads_var_stop = ads_var_stop self._ads_var_stop = ads_var_stop
self._attr_device_class = device_class self._attr_device_class = device_class
self._attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE self._attr_supported_features = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
)
if ads_var_stop is not None: if ads_var_stop is not None:
self._attr_supported_features |= SUPPORT_STOP self._attr_supported_features |= CoverEntityFeature.STOP
if ads_var_pos_set is not None: if ads_var_pos_set is not None:
self._attr_supported_features |= SUPPORT_SET_POSITION self._attr_supported_features |= CoverEntityFeature.SET_POSITION
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Register device notification.""" """Register device notification."""

View file

@ -3,7 +3,7 @@ from __future__ import annotations
import logging import logging
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
FAN_AUTO, FAN_AUTO,
FAN_HIGH, FAN_HIGH,
@ -16,8 +16,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL, HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF, HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
@ -108,7 +106,9 @@ class AdvantageAirAC(AdvantageAirClimateEntity):
_attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH] _attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH]
_attr_hvac_modes = AC_HVAC_MODES _attr_hvac_modes = AC_HVAC_MODES
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
)
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an AdvantageAir AC unit.""" """Initialize an AdvantageAir AC unit."""
@ -169,7 +169,7 @@ class AdvantageAirZone(AdvantageAirClimateEntity):
"""AdvantageAir Zone control.""" """AdvantageAir Zone control."""
_attr_hvac_modes = ZONE_HVAC_MODES _attr_hvac_modes = ZONE_HVAC_MODES
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an AdvantageAir Zone control.""" """Initialize an AdvantageAir Zone control."""

View file

@ -1,11 +1,9 @@
"""Cover platform for Advantage Air integration.""" """Cover platform for Advantage Air integration."""
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_POSITION, ATTR_POSITION,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
CoverDeviceClass, CoverDeviceClass,
CoverEntity, CoverEntity,
CoverEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -43,7 +41,11 @@ class AdvantageAirZoneVent(AdvantageAirEntity, CoverEntity):
"""Advantage Air Cover Class.""" """Advantage Air Cover Class."""
_attr_device_class = CoverDeviceClass.DAMPER _attr_device_class = CoverDeviceClass.DAMPER
_attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION _attr_supported_features = (
CoverEntityFeature.OPEN
| CoverEntityFeature.CLOSE
| CoverEntityFeature.SET_POSITION
)
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Cover Class.""" """Initialize an Advantage Air Cover Class."""

View file

@ -1,9 +1,7 @@
"""Support for Agent DVR Alarm Control Panels.""" """Support for Agent DVR Alarm Control Panels."""
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity from homeassistant.components.alarm_control_panel import (
from homeassistant.components.alarm_control_panel.const import ( AlarmControlPanelEntity,
SUPPORT_ALARM_ARM_AWAY, AlarmControlPanelEntityFeature,
SUPPORT_ALARM_ARM_HOME,
SUPPORT_ALARM_ARM_NIGHT,
) )
from homeassistant.const import ( from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_AWAY,
@ -38,7 +36,9 @@ class AgentBaseStation(AlarmControlPanelEntity):
_attr_icon = ICON _attr_icon = ICON
_attr_supported_features = ( _attr_supported_features = (
SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
| AlarmControlPanelEntityFeature.ARM_NIGHT
) )
def __init__(self, client): def __init__(self, client):

View file

@ -4,7 +4,7 @@ import logging
from agent import AgentError from agent import AgentError
from homeassistant.components.camera import SUPPORT_ON_OFF from homeassistant.components.camera import CameraEntityFeature
from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers import entity_platform from homeassistant.helpers import entity_platform
@ -63,6 +63,8 @@ async def async_setup_entry(
class AgentCamera(MjpegCamera): class AgentCamera(MjpegCamera):
"""Representation of an Agent Device Stream.""" """Representation of an Agent Device Stream."""
_attr_supported_features = CameraEntityFeature.ON_OFF
def __init__(self, device): def __init__(self, device):
"""Initialize as a subclass of MjpegCamera.""" """Initialize as a subclass of MjpegCamera."""
self.device = device self.device = device
@ -134,11 +136,6 @@ class AgentCamera(MjpegCamera):
"""Return True if entity is connected.""" """Return True if entity is connected."""
return self.device.connected return self.device.connected
@property
def supported_features(self) -> int:
"""Return supported features."""
return SUPPORT_ON_OFF
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if on.""" """Return true if on."""

View file

@ -3,7 +3,7 @@ from __future__ import annotations
import logging import logging
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
FAN_AUTO, FAN_AUTO,
FAN_DIFFUSE, FAN_DIFFUSE,
@ -17,8 +17,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_FAN_ONLY, HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
HVAC_MODE_OFF, HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
@ -29,7 +27,6 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN from .const import DOMAIN
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
AT_TO_HA_STATE = { AT_TO_HA_STATE = {
"Heat": HVAC_MODE_HEAT, "Heat": HVAC_MODE_HEAT,
"Cool": HVAC_MODE_COOL, "Cool": HVAC_MODE_COOL,
@ -90,7 +87,9 @@ async def async_setup_entry(
class AirtouchAC(CoordinatorEntity, ClimateEntity): class AirtouchAC(CoordinatorEntity, ClimateEntity):
"""Representation of an AirTouch 4 ac.""" """Representation of an AirTouch 4 ac."""
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
)
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = TEMP_CELSIUS
def __init__(self, coordinator, ac_number, info): def __init__(self, coordinator, ac_number, info):
@ -204,7 +203,7 @@ class AirtouchAC(CoordinatorEntity, ClimateEntity):
class AirtouchGroup(CoordinatorEntity, ClimateEntity): class AirtouchGroup(CoordinatorEntity, ClimateEntity):
"""Representation of an AirTouch 4 group.""" """Representation of an AirTouch 4 group."""
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = TEMP_CELSIUS
_attr_hvac_modes = AT_GROUP_MODES _attr_hvac_modes = AT_GROUP_MODES

View file

@ -4,11 +4,7 @@ import voluptuous as vol
from homeassistant.components.alarm_control_panel import ( from homeassistant.components.alarm_control_panel import (
FORMAT_NUMBER, FORMAT_NUMBER,
AlarmControlPanelEntity, AlarmControlPanelEntity,
) AlarmControlPanelEntityFeature,
from homeassistant.components.alarm_control_panel.const import (
SUPPORT_ALARM_ARM_AWAY,
SUPPORT_ALARM_ARM_HOME,
SUPPORT_ALARM_ARM_NIGHT,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -83,7 +79,9 @@ class AlarmDecoderAlarmPanel(AlarmControlPanelEntity):
_attr_should_poll = False _attr_should_poll = False
_attr_code_format = FORMAT_NUMBER _attr_code_format = FORMAT_NUMBER
_attr_supported_features = ( _attr_supported_features = (
SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
| AlarmControlPanelEntityFeature.ARM_NIGHT
) )
def __init__(self, client, auto_bypass, code_arm_required, alt_night_mode): def __init__(self, client, auto_bypass, code_arm_required, alt_night_mode):

View file

@ -8,12 +8,8 @@ from typing import Any
import ambiclimate import ambiclimate
import voluptuous as vol import voluptuous as vol
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import HVAC_MODE_HEAT, HVAC_MODE_OFF
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_NAME, ATTR_NAME,
@ -41,8 +37,6 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE
SEND_COMFORT_FEEDBACK_SCHEMA = vol.Schema( SEND_COMFORT_FEEDBACK_SCHEMA = vol.Schema(
{vol.Required(ATTR_NAME): cv.string, vol.Required(ATTR_VALUE): cv.string} {vol.Required(ATTR_NAME): cv.string, vol.Required(ATTR_VALUE): cv.string}
) )
@ -154,7 +148,7 @@ class AmbiclimateEntity(ClimateEntity):
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = TEMP_CELSIUS
_attr_target_temperature_step = 1 _attr_target_temperature_step = 1
_attr_supported_features = SUPPORT_FLAGS _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_OFF] _attr_hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
def __init__(self, heater, store): def __init__(self, heater, store):

View file

@ -12,7 +12,7 @@ from amcrest import AmcrestError
from haffmpeg.camera import CameraMjpeg from haffmpeg.camera import CameraMjpeg
import voluptuous as vol import voluptuous as vol
from homeassistant.components.camera import SUPPORT_ON_OFF, SUPPORT_STREAM, Camera from homeassistant.components.camera import Camera, CameraEntityFeature
from homeassistant.components.camera.const import DOMAIN as CAMERA_DOMAIN from homeassistant.components.camera.const import DOMAIN as CAMERA_DOMAIN
from homeassistant.components.ffmpeg import FFmpegManager, get_ffmpeg_manager from homeassistant.components.ffmpeg import FFmpegManager, get_ffmpeg_manager
from homeassistant.const import ATTR_ENTITY_ID, CONF_NAME, STATE_OFF, STATE_ON from homeassistant.const import ATTR_ENTITY_ID, CONF_NAME, STATE_OFF, STATE_ON
@ -164,6 +164,8 @@ class AmcrestCommandFailed(Exception):
class AmcrestCam(Camera): class AmcrestCam(Camera):
"""An implementation of an Amcrest IP camera.""" """An implementation of an Amcrest IP camera."""
_attr_supported_features = CameraEntityFeature.ON_OFF | CameraEntityFeature.STREAM
def __init__(self, name: str, device: AmcrestDevice, ffmpeg: FFmpegManager) -> None: def __init__(self, name: str, device: AmcrestDevice, ffmpeg: FFmpegManager) -> None:
"""Initialize an Amcrest camera.""" """Initialize an Amcrest camera."""
super().__init__() super().__init__()
@ -311,11 +313,6 @@ class AmcrestCam(Camera):
"""Return True if entity is available.""" """Return True if entity is available."""
return self._api.available return self._api.available
@property
def supported_features(self) -> int:
"""Return supported features."""
return SUPPORT_ON_OFF | SUPPORT_STREAM
# Camera property overrides # Camera property overrides
@property @property

View file

@ -17,19 +17,9 @@ from androidtv.exceptions import LockNotAcquiredException
import voluptuous as vol import voluptuous as vol
from homeassistant.components import persistent_notification from homeassistant.components import persistent_notification
from homeassistant.components.media_player import MediaPlayerEntity from homeassistant.components.media_player import (
from homeassistant.components.media_player.const import ( MediaPlayerEntity,
SUPPORT_NEXT_TRACK, MediaPlayerEntityFeature,
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,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -73,31 +63,6 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
SUPPORT_ANDROIDTV = (
SUPPORT_PAUSE
| SUPPORT_PLAY
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_SELECT_SOURCE
| SUPPORT_STOP
| SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_STEP
)
SUPPORT_FIRETV = (
SUPPORT_PAUSE
| SUPPORT_PLAY
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_SELECT_SOURCE
| SUPPORT_STOP
)
ATTR_ADB_RESPONSE = "adb_response" ATTR_ADB_RESPONSE = "adb_response"
ATTR_DEVICE_PATH = "device_path" ATTR_DEVICE_PATH = "device_path"
ATTR_HDMI_INPUT = "hdmi_input" ATTR_HDMI_INPUT = "hdmi_input"
@ -467,7 +432,19 @@ class ADBDevice(MediaPlayerEntity):
class AndroidTVDevice(ADBDevice): class AndroidTVDevice(ADBDevice):
"""Representation of an Android TV device.""" """Representation of an Android TV device."""
_attr_supported_features = SUPPORT_ANDROIDTV _attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_STEP
)
@adb_decorator(override_available=True) @adb_decorator(override_available=True)
async def async_update(self): async def async_update(self):
@ -543,7 +520,16 @@ class AndroidTVDevice(ADBDevice):
class FireTVDevice(ADBDevice): class FireTVDevice(ADBDevice):
"""Representation of a Fire TV device.""" """Representation of a Fire TV device."""
_attr_supported_features = SUPPORT_FIRETV _attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.STOP
)
@adb_decorator(override_available=True) @adb_decorator(override_available=True)
async def async_update(self): async def async_update(self):

View file

@ -6,13 +6,10 @@ import logging
import anthemav import anthemav
import voluptuous as vol import voluptuous as vol
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity from homeassistant.components.media_player import (
from homeassistant.components.media_player.const import ( PLATFORM_SCHEMA,
SUPPORT_SELECT_SOURCE, MediaPlayerEntity,
SUPPORT_TURN_OFF, MediaPlayerEntityFeature,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
@ -37,14 +34,6 @@ DOMAIN = "anthemav"
DEFAULT_PORT = 14999 DEFAULT_PORT = 14999
SUPPORT_ANTHEMAV = (
SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_MUTE
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_SELECT_SOURCE
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
vol.Required(CONF_HOST): cv.string, vol.Required(CONF_HOST): cv.string,
@ -92,7 +81,13 @@ class AnthemAVR(MediaPlayerEntity):
"""Entity reading values from Anthem AVR protocol.""" """Entity reading values from Anthem AVR protocol."""
_attr_should_poll = False _attr_should_poll = False
_attr_supported_features = SUPPORT_ANTHEMAV _attr_supported_features = (
MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.SELECT_SOURCE
)
def __init__(self, avr, name): def __init__(self, avr, name):
"""Initialize entity with transport.""" """Initialize entity with transport."""

View file

@ -13,7 +13,11 @@ from pyatv.const import (
) )
from pyatv.helpers import is_streamable from pyatv.helpers import is_streamable
from homeassistant.components.media_player import BrowseMedia, MediaPlayerEntity from homeassistant.components.media_player import (
BrowseMedia,
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import (
MEDIA_TYPE_APP, MEDIA_TYPE_APP,
MEDIA_TYPE_MUSIC, MEDIA_TYPE_MUSIC,
@ -22,21 +26,6 @@ from homeassistant.components.media_player.const import (
REPEAT_MODE_ALL, REPEAT_MODE_ALL,
REPEAT_MODE_OFF, REPEAT_MODE_OFF,
REPEAT_MODE_ONE, REPEAT_MODE_ONE,
SUPPORT_BROWSE_MEDIA,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_REPEAT_SET,
SUPPORT_SEEK,
SUPPORT_SELECT_SOURCE,
SUPPORT_SHUFFLE_SET,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -60,45 +49,47 @@ _LOGGER = logging.getLogger(__name__)
PARALLEL_UPDATES = 0 PARALLEL_UPDATES = 0
# We always consider these to be supported # We always consider these to be supported
SUPPORT_BASE = SUPPORT_TURN_ON | SUPPORT_TURN_OFF SUPPORT_BASE = MediaPlayerEntityFeature.TURN_ON | MediaPlayerEntityFeature.TURN_OFF
# This is the "optimistic" view of supported features and will be returned until the # This is the "optimistic" view of supported features and will be returned until the
# actual set of supported feature have been determined (will always be all or a subset # actual set of supported feature have been determined (will always be all or a subset
# of these). # of these).
SUPPORT_APPLE_TV = ( SUPPORT_APPLE_TV = (
SUPPORT_BASE SUPPORT_BASE
| SUPPORT_BROWSE_MEDIA | MediaPlayerEntityFeature.BROWSE_MEDIA
| SUPPORT_PLAY_MEDIA | MediaPlayerEntityFeature.PLAY_MEDIA
| SUPPORT_PAUSE | MediaPlayerEntityFeature.PAUSE
| SUPPORT_PLAY | MediaPlayerEntityFeature.PLAY
| SUPPORT_SEEK | MediaPlayerEntityFeature.SEEK
| SUPPORT_STOP | MediaPlayerEntityFeature.STOP
| SUPPORT_NEXT_TRACK | MediaPlayerEntityFeature.NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK | MediaPlayerEntityFeature.PREVIOUS_TRACK
| SUPPORT_VOLUME_SET | MediaPlayerEntityFeature.VOLUME_SET
| SUPPORT_VOLUME_STEP | MediaPlayerEntityFeature.VOLUME_STEP
| SUPPORT_REPEAT_SET | MediaPlayerEntityFeature.REPEAT_SET
| SUPPORT_SHUFFLE_SET | MediaPlayerEntityFeature.SHUFFLE_SET
) )
# Map features in pyatv to Home Assistant # Map features in pyatv to Home Assistant
SUPPORT_FEATURE_MAPPING = { SUPPORT_FEATURE_MAPPING = {
FeatureName.PlayUrl: SUPPORT_PLAY_MEDIA, FeatureName.PlayUrl: MediaPlayerEntityFeature.PLAY_MEDIA,
FeatureName.StreamFile: SUPPORT_PLAY_MEDIA, FeatureName.StreamFile: MediaPlayerEntityFeature.PLAY_MEDIA,
FeatureName.Pause: SUPPORT_PAUSE, FeatureName.Pause: MediaPlayerEntityFeature.PAUSE,
FeatureName.Play: SUPPORT_PLAY, FeatureName.Play: MediaPlayerEntityFeature.PLAY,
FeatureName.SetPosition: SUPPORT_SEEK, FeatureName.SetPosition: MediaPlayerEntityFeature.SEEK,
FeatureName.Stop: SUPPORT_STOP, FeatureName.Stop: MediaPlayerEntityFeature.STOP,
FeatureName.Next: SUPPORT_NEXT_TRACK, FeatureName.Next: MediaPlayerEntityFeature.NEXT_TRACK,
FeatureName.Previous: SUPPORT_PREVIOUS_TRACK, FeatureName.Previous: MediaPlayerEntityFeature.PREVIOUS_TRACK,
FeatureName.VolumeUp: SUPPORT_VOLUME_STEP, FeatureName.VolumeUp: MediaPlayerEntityFeature.VOLUME_STEP,
FeatureName.VolumeDown: SUPPORT_VOLUME_STEP, FeatureName.VolumeDown: MediaPlayerEntityFeature.VOLUME_STEP,
FeatureName.SetRepeat: SUPPORT_REPEAT_SET, FeatureName.SetRepeat: MediaPlayerEntityFeature.REPEAT_SET,
FeatureName.SetShuffle: SUPPORT_SHUFFLE_SET, FeatureName.SetShuffle: MediaPlayerEntityFeature.SHUFFLE_SET,
FeatureName.SetVolume: SUPPORT_VOLUME_SET, FeatureName.SetVolume: MediaPlayerEntityFeature.VOLUME_SET,
FeatureName.AppList: SUPPORT_BROWSE_MEDIA | SUPPORT_SELECT_SOURCE, FeatureName.AppList: MediaPlayerEntityFeature.BROWSE_MEDIA
FeatureName.LaunchApp: SUPPORT_BROWSE_MEDIA | SUPPORT_SELECT_SOURCE, | MediaPlayerEntityFeature.SELECT_SOURCE,
FeatureName.LaunchApp: MediaPlayerEntityFeature.BROWSE_MEDIA
| MediaPlayerEntityFeature.SELECT_SOURCE,
} }

View file

@ -6,18 +6,10 @@ import logging
import sharp_aquos_rc import sharp_aquos_rc
import voluptuous as vol import voluptuous as vol
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity from homeassistant.components.media_player import (
from homeassistant.components.media_player.const import ( PLATFORM_SCHEMA,
SUPPORT_NEXT_TRACK, MediaPlayerEntity,
SUPPORT_PAUSE, MediaPlayerEntityFeature,
SUPPORT_PLAY,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SELECT_SOURCE,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
@ -43,18 +35,6 @@ DEFAULT_PASSWORD = "password"
DEFAULT_TIMEOUT = 0.5 DEFAULT_TIMEOUT = 0.5
DEFAULT_RETRIES = 2 DEFAULT_RETRIES = 2
SUPPORT_SHARPTV = (
SUPPORT_TURN_OFF
| SUPPORT_NEXT_TRACK
| SUPPORT_PAUSE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_SELECT_SOURCE
| SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_STEP
| SUPPORT_VOLUME_SET
| SUPPORT_PLAY
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
vol.Required(CONF_HOST): cv.string, vol.Required(CONF_HOST): cv.string,
@ -122,7 +102,17 @@ class SharpAquosTVDevice(MediaPlayerEntity):
"""Representation of a Aquos TV.""" """Representation of a Aquos TV."""
_attr_source_list = list(SOURCES.values()) _attr_source_list = list(SOURCES.values())
_attr_supported_features = SUPPORT_SHARPTV _attr_supported_features = (
MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.PLAY
)
def __init__( def __init__(
self, name: str, remote: sharp_aquos_rc.TV, power_on_enabled: bool = False self, name: str, remote: sharp_aquos_rc.TV, power_on_enabled: bool = False
@ -130,7 +120,7 @@ class SharpAquosTVDevice(MediaPlayerEntity):
"""Initialize the aquos device.""" """Initialize the aquos device."""
self._power_on_enabled = power_on_enabled self._power_on_enabled = power_on_enabled
if power_on_enabled: if power_on_enabled:
self._attr_supported_features |= SUPPORT_TURN_ON self._attr_supported_features |= MediaPlayerEntityFeature.TURN_ON
# Save a reference to the imported class # Save a reference to the imported class
self._attr_name = name self._attr_name = name
# Assume that the TV is not muted # Assume that the TV is not muted

View file

@ -4,20 +4,15 @@ import logging
from arcam.fmj import SourceCodes from arcam.fmj import SourceCodes
from arcam.fmj.state import State from arcam.fmj.state import State
from homeassistant.components.media_player import BrowseMedia, MediaPlayerEntity from homeassistant.components.media_player import (
BrowseMedia,
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import (
MEDIA_CLASS_DIRECTORY, MEDIA_CLASS_DIRECTORY,
MEDIA_CLASS_MUSIC, MEDIA_CLASS_MUSIC,
MEDIA_TYPE_MUSIC, MEDIA_TYPE_MUSIC,
SUPPORT_BROWSE_MEDIA,
SUPPORT_PLAY_MEDIA,
SUPPORT_SELECT_SOUND_MODE,
SUPPORT_SELECT_SOURCE,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
) )
from homeassistant.components.media_player.errors import BrowseError from homeassistant.components.media_player.errors import BrowseError
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -77,17 +72,17 @@ class ArcamFmj(MediaPlayerEntity):
self._attr_name = f"{device_name} - Zone: {state.zn}" self._attr_name = f"{device_name} - Zone: {state.zn}"
self._uuid = uuid self._uuid = uuid
self._attr_supported_features = ( self._attr_supported_features = (
SUPPORT_SELECT_SOURCE MediaPlayerEntityFeature.SELECT_SOURCE
| SUPPORT_PLAY_MEDIA | MediaPlayerEntityFeature.PLAY_MEDIA
| SUPPORT_BROWSE_MEDIA | MediaPlayerEntityFeature.BROWSE_MEDIA
| SUPPORT_VOLUME_SET | MediaPlayerEntityFeature.VOLUME_SET
| SUPPORT_VOLUME_MUTE | MediaPlayerEntityFeature.VOLUME_MUTE
| SUPPORT_VOLUME_STEP | MediaPlayerEntityFeature.VOLUME_STEP
| SUPPORT_TURN_OFF | MediaPlayerEntityFeature.TURN_OFF
| SUPPORT_TURN_ON | MediaPlayerEntityFeature.TURN_ON
) )
if state.zn == 1: if state.zn == 1:
self._attr_supported_features |= SUPPORT_SELECT_SOUND_MODE self._attr_supported_features |= MediaPlayerEntityFeature.SELECT_SOUND_MODE
self._attr_unique_id = f"{uuid}-{state.zn}" self._attr_unique_id = f"{uuid}-{state.zn}"
self._attr_entity_registry_enabled_default = state.zn == 1 self._attr_entity_registry_enabled_default = state.zn == 1

View file

@ -8,11 +8,7 @@ import voluptuous as vol
from homeassistant.components.alarm_control_panel import ( from homeassistant.components.alarm_control_panel import (
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA, PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
AlarmControlPanelEntity, AlarmControlPanelEntity,
) AlarmControlPanelEntityFeature,
from homeassistant.components.alarm_control_panel.const import (
SUPPORT_ALARM_ARM_AWAY,
SUPPORT_ALARM_ARM_HOME,
SUPPORT_ALARM_ARM_NIGHT,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
@ -78,7 +74,9 @@ class ArloBaseStation(AlarmControlPanelEntity):
"""Representation of an Arlo Alarm Control Panel.""" """Representation of an Arlo Alarm Control Panel."""
_attr_supported_features = ( _attr_supported_features = (
SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
| AlarmControlPanelEntityFeature.ARM_NIGHT
) )
_attr_icon = ICON _attr_icon = ICON

View file

@ -1,7 +1,7 @@
"""Initialization of ATAG One climate platform.""" """Initialization of ATAG One climate platform."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT, CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE, CURRENT_HVAC_IDLE,
@ -9,8 +9,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
PRESET_AWAY, PRESET_AWAY,
PRESET_BOOST, PRESET_BOOST,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, Platform from homeassistant.const import ATTR_TEMPERATURE, Platform
@ -27,7 +25,6 @@ PRESET_MAP = {
PRESET_BOOST: "fireplace", PRESET_BOOST: "fireplace",
} }
PRESET_INVERTED = {v: k for k, v in PRESET_MAP.items()} PRESET_INVERTED = {v: k for k, v in PRESET_MAP.items()}
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
HVAC_MODES = [HVAC_MODE_AUTO, HVAC_MODE_HEAT] HVAC_MODES = [HVAC_MODE_AUTO, HVAC_MODE_HEAT]
@ -44,7 +41,9 @@ class AtagThermostat(AtagEntity, ClimateEntity):
_attr_hvac_modes = HVAC_MODES _attr_hvac_modes = HVAC_MODES
_attr_preset_modes = list(PRESET_MAP.keys()) _attr_preset_modes = list(PRESET_MAP.keys())
_attr_supported_features = SUPPORT_FLAGS _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
def __init__(self, coordinator, atag_id): def __init__(self, coordinator, atag_id):
"""Initialize an Atag climate device.""" """Initialize an Atag climate device."""

View file

@ -11,7 +11,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DOMAIN, AtagEntity from . import DOMAIN, AtagEntity
SUPPORT_FLAGS_HEATER = 0
OPERATION_LIST = [STATE_OFF, STATE_ECO, STATE_PERFORMANCE] OPERATION_LIST = [STATE_OFF, STATE_ECO, STATE_PERFORMANCE]
@ -29,7 +28,7 @@ class AtagWaterHeater(AtagEntity, WaterHeaterEntity):
"""Representation of an ATAG water heater.""" """Representation of an ATAG water heater."""
_attr_operation_list = OPERATION_LIST _attr_operation_list = OPERATION_LIST
_attr_supported_features = SUPPORT_FLAGS_HEATER _attr_supported_features = 0
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = TEMP_CELSIUS
@property @property

View file

@ -1,7 +1,7 @@
"""Support for Axis camera streaming.""" """Support for Axis camera streaming."""
from urllib.parse import urlencode from urllib.parse import urlencode
from homeassistant.components.camera import SUPPORT_STREAM from homeassistant.components.camera import CameraEntityFeature
from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import HTTP_DIGEST_AUTHENTICATION from homeassistant.const import HTTP_DIGEST_AUTHENTICATION
@ -32,6 +32,8 @@ async def async_setup_entry(
class AxisCamera(AxisEntityBase, MjpegCamera): class AxisCamera(AxisEntityBase, MjpegCamera):
"""Representation of a Axis camera.""" """Representation of a Axis camera."""
_attr_supported_features = CameraEntityFeature.STREAM
def __init__(self, device): def __init__(self, device):
"""Initialize Axis Communications camera component.""" """Initialize Axis Communications camera component."""
AxisEntityBase.__init__(self, device) AxisEntityBase.__init__(self, device)
@ -58,11 +60,6 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
await super().async_added_to_hass() await super().async_added_to_hass()
@property
def supported_features(self) -> int:
"""Return supported features."""
return SUPPORT_STREAM
def _new_address(self) -> None: def _new_address(self) -> None:
"""Set new device address for video stream.""" """Set new device address for video stream."""
self._mjpeg_url = self.mjpeg_source self._mjpeg_url = self.mjpeg_source