Use EntityFeature enum in components (m**) (#69414)

* Use EntityFeature in melcloud

* Use EntityFeature in mystrom

* Use EntityFeature in mysensors

* Use EntityFeature in myq

* Use EntityFeature in mpd

* Use EntityFeature in monoprice

* Use EntityFeature in moehlenhoff_alpha2

* Use EntityFeature in modern_forms

* Use EntityFeature in modbus

* Use EntityFeature in melissa

* Use EntityFeature in mediaroom

* Use EntityFeature in maxcube

* Use EntityFeature in manual_mqtt

* Fix maxcube tests

* Revert "Use EntityFeature in modbus"

This reverts commit 56cf9d900d.

* Revert "Use EntityFeature in myq"

This reverts commit 44a31b1a03.

* Revert "Use EntityFeature in mystrom"

This reverts commit 7260ee0384.

* Revert "Revert "Use EntityFeature in modbus""

This reverts commit 916a612a60.

* Revert "Revert "Use EntityFeature in myq""

This reverts commit a6be42fa17.
This commit is contained in:
epenet 2022-04-06 17:33:41 +02:00 committed by GitHub
parent 8e090a8c04
commit 5e2cc2b9b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 109 additions and 160 deletions

View file

@ -10,12 +10,7 @@ import voluptuous as vol
from homeassistant.components import mqtt from homeassistant.components import mqtt
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,
SUPPORT_ALARM_ARM_NIGHT,
SUPPORT_ALARM_TRIGGER,
)
from homeassistant.const import ( from homeassistant.const import (
CONF_CODE, CONF_CODE,
CONF_DELAY_TIME, CONF_DELAY_TIME,
@ -209,6 +204,13 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
A trigger_time of zero disables the alarm_trigger service. A trigger_time of zero disables the alarm_trigger service.
""" """
_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
| AlarmControlPanelEntityFeature.ARM_NIGHT
| AlarmControlPanelEntityFeature.TRIGGER
)
def __init__( def __init__(
self, self,
hass, hass,
@ -293,16 +295,6 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
return self._state return self._state
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return (
SUPPORT_ALARM_ARM_HOME
| SUPPORT_ALARM_ARM_AWAY
| SUPPORT_ALARM_ARM_NIGHT
| SUPPORT_ALARM_TRIGGER
)
@property @property
def _active_state(self): def _active_state(self):
"""Get the current state.""" """Get the current state."""

View file

@ -11,7 +11,7 @@ from maxcube.device import (
MAX_DEVICE_MODE_VACATION, MAX_DEVICE_MODE_VACATION,
) )
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,
@ -24,8 +24,6 @@ from homeassistant.components.climate.const import (
PRESET_COMFORT, PRESET_COMFORT,
PRESET_ECO, PRESET_ECO,
PRESET_NONE, PRESET_NONE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -50,8 +48,6 @@ MIN_TEMPERATURE = 5.0
# Largest Value without fully opening # Largest Value without fully opening
MAX_TEMPERATURE = 30.0 MAX_TEMPERATURE = 30.0
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
def setup_platform( def setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
@ -73,13 +69,16 @@ def setup_platform(
class MaxCubeClimate(ClimateEntity): class MaxCubeClimate(ClimateEntity):
"""MAX! Cube ClimateEntity.""" """MAX! Cube ClimateEntity."""
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
def __init__(self, handler, device): def __init__(self, handler, device):
"""Initialize MAX! Cube ClimateEntity.""" """Initialize MAX! Cube ClimateEntity."""
room = handler.cube.room_by_id(device.room_id) room = handler.cube.room_by_id(device.room_id)
self._attr_name = f"{room.name} {device.name}" self._attr_name = f"{room.name} {device.name}"
self._cubehandle = handler self._cubehandle = handler
self._device = device self._device = device
self._attr_supported_features = SUPPORT_FLAGS
self._attr_should_poll = True self._attr_should_poll = True
self._attr_unique_id = self._device.serial self._attr_unique_id = self._device.serial
self._attr_temperature_unit = TEMP_CELSIUS self._attr_temperature_unit = TEMP_CELSIUS

View file

@ -12,20 +12,12 @@ from pymediaroom import (
) )
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,
MEDIA_TYPE_CHANNEL, MediaPlayerEntity,
SUPPORT_NEXT_TRACK, MediaPlayerEntityFeature,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_STEP,
) )
from homeassistant.components.media_player.const import MEDIA_TYPE_CHANNEL
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_NAME, CONF_NAME,
@ -54,18 +46,7 @@ DISCOVERY_MEDIAROOM = "mediaroom_discovery_installed"
MEDIA_TYPE_MEDIAROOM = "mediaroom" MEDIA_TYPE_MEDIAROOM = "mediaroom"
SIGNAL_STB_NOTIFY = "mediaroom_stb_discovered" SIGNAL_STB_NOTIFY = "mediaroom_stb_discovered"
SUPPORT_MEDIAROOM = (
SUPPORT_PAUSE
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_VOLUME_STEP
| SUPPORT_VOLUME_MUTE
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_PLAY
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
@ -136,6 +117,19 @@ async def async_setup_platform(
class MediaroomDevice(MediaPlayerEntity): class MediaroomDevice(MediaPlayerEntity):
"""Representation of a Mediaroom set-up-box on the network.""" """Representation of a Mediaroom set-up-box on the network."""
_attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.PLAY
)
def set_state(self, mediaroom_state): def set_state(self, mediaroom_state):
"""Map pymediaroom state to HA state.""" """Map pymediaroom state to HA state."""
@ -242,11 +236,6 @@ class MediaroomDevice(MediaPlayerEntity):
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_MEDIAROOM
@property @property
def media_content_type(self): def media_content_type(self):
"""Return the content type of current playing media.""" """Return the content type of current playing media."""

View file

@ -14,7 +14,7 @@ from pymelcloud.atw_device import (
) )
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 (
ATTR_HVAC_MODE, ATTR_HVAC_MODE,
DEFAULT_MAX_TEMP, DEFAULT_MAX_TEMP,
@ -25,9 +25,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_SWING_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
@ -128,7 +125,9 @@ class AtaDeviceClimate(MelCloudClimate):
"""Air-to-Air climate device.""" """Air-to-Air climate device."""
_attr_supported_features = ( _attr_supported_features = (
SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE | SUPPORT_SWING_MODE ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.SWING_MODE
) )
def __init__(self, device: MelCloudDevice, ata_device: AtaDevice) -> None: def __init__(self, device: MelCloudDevice, ata_device: AtaDevice) -> None:
@ -296,7 +295,7 @@ class AtwDeviceZoneClimate(MelCloudClimate):
_attr_max_temp = 30 _attr_max_temp = 30
_attr_min_temp = 10 _attr_min_temp = 10
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def __init__( def __init__(
self, device: MelCloudDevice, atw_device: AtwDevice, atw_zone: Zone self, device: MelCloudDevice, atw_device: AtwDevice, atw_zone: Zone

View file

@ -9,9 +9,8 @@ from pymelcloud.atw_device import (
from pymelcloud.device import PROPERTY_POWER from pymelcloud.device import PROPERTY_POWER
from homeassistant.components.water_heater import ( from homeassistant.components.water_heater import (
SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE,
WaterHeaterEntity, WaterHeaterEntity,
WaterHeaterEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
@ -39,6 +38,11 @@ async def async_setup_entry(
class AtwWaterHeater(WaterHeaterEntity): class AtwWaterHeater(WaterHeaterEntity):
"""Air-to-Water water heater.""" """Air-to-Water water heater."""
_attr_supported_features = (
WaterHeaterEntityFeature.TARGET_TEMPERATURE
| WaterHeaterEntityFeature.OPERATION_MODE
)
def __init__(self, api: MelCloudDevice, device: AtwDevice) -> None: def __init__(self, api: MelCloudDevice, device: AtwDevice) -> None:
"""Initialize water heater device.""" """Initialize water heater device."""
self._api = api self._api = api
@ -117,11 +121,6 @@ class AtwWaterHeater(WaterHeaterEntity):
"""Set new target operation mode.""" """Set new target operation mode."""
await self._device.set({PROPERTY_OPERATION_MODE: operation_mode}) await self._device.set({PROPERTY_OPERATION_MODE: operation_mode})
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
@property @property
def min_temp(self) -> float | None: def min_temp(self) -> float | None:
"""Return the minimum temperature.""" """Return the minimum temperature."""

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,
@ -15,8 +15,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.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -27,8 +25,6 @@ from . import DATA_MELISSA
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
SUPPORT_FLAGS = SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE
OP_MODES = [ OP_MODES = [
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
HVAC_MODE_COOL, HVAC_MODE_COOL,
@ -62,6 +58,10 @@ async def async_setup_platform(
class MelissaClimate(ClimateEntity): class MelissaClimate(ClimateEntity):
"""Representation of a Melissa Climate device.""" """Representation of a Melissa Climate device."""
_attr_supported_features = (
ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
)
def __init__(self, api, serial_number, init_data): def __init__(self, api, serial_number, init_data):
"""Initialize the climate device.""" """Initialize the climate device."""
self._name = init_data["name"] self._name = init_data["name"]
@ -147,11 +147,6 @@ class MelissaClimate(ClimateEntity):
"""Return the maximum supported temperature for the thermostat.""" """Return the maximum supported temperature for the thermostat."""
return 30 return 30
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS
async def async_set_temperature(self, **kwargs): async def async_set_temperature(self, **kwargs):
"""Set new target temperature.""" """Set new target temperature."""
temp = kwargs.get(ATTR_TEMPERATURE) temp = kwargs.get(ATTR_TEMPERATURE)

View file

@ -5,11 +5,8 @@ from datetime import datetime
import struct import struct
from typing import Any from typing import Any
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_AUTO
HVAC_MODE_AUTO,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import ( from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
CONF_NAME, CONF_NAME,
@ -63,6 +60,8 @@ async def async_setup_platform(
class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity): class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
"""Representation of a Modbus Thermostat.""" """Representation of a Modbus Thermostat."""
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def __init__( def __init__(
self, self,
hub: ModbusHub, hub: ModbusHub,
@ -73,7 +72,6 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
self._target_temperature_register = config[CONF_TARGET_TEMP] self._target_temperature_register = config[CONF_TARGET_TEMP]
self._unit = config[CONF_TEMPERATURE_UNIT] self._unit = config[CONF_TEMPERATURE_UNIT]
self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE
self._attr_hvac_mode = HVAC_MODE_AUTO self._attr_hvac_mode = HVAC_MODE_AUTO
self._attr_hvac_modes = [HVAC_MODE_AUTO] self._attr_hvac_modes = [HVAC_MODE_AUTO]
self._attr_current_temperature = None self._attr_current_temperature = None

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import datetime from datetime import datetime
from typing import Any from typing import Any
from homeassistant.components.cover import SUPPORT_CLOSE, SUPPORT_OPEN, CoverEntity from homeassistant.components.cover import CoverEntity, CoverEntityFeature
from homeassistant.const import ( from homeassistant.const import (
CONF_COVERS, CONF_COVERS,
CONF_NAME, CONF_NAME,
@ -59,6 +59,8 @@ async def async_setup_platform(
class ModbusCover(BasePlatform, CoverEntity, RestoreEntity): class ModbusCover(BasePlatform, CoverEntity, RestoreEntity):
"""Representation of a Modbus cover.""" """Representation of a Modbus cover."""
_attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
def __init__( def __init__(
self, self,
hub: ModbusHub, hub: ModbusHub,
@ -73,7 +75,6 @@ class ModbusCover(BasePlatform, CoverEntity, RestoreEntity):
self._status_register = config.get(CONF_STATUS_REGISTER) self._status_register = config.get(CONF_STATUS_REGISTER)
self._status_register_type = config[CONF_STATUS_REGISTER_TYPE] self._status_register_type = config[CONF_STATUS_REGISTER_TYPE]
self._attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE
self._attr_is_closed = False self._attr_is_closed = False
# If we read cover status from coil, and not from optional status register, # If we read cover status from coil, and not from optional status register,

View file

@ -6,7 +6,7 @@ from typing import Any
from aiomodernforms.const import FAN_POWER_OFF, FAN_POWER_ON from aiomodernforms.const import FAN_POWER_OFF, FAN_POWER_ON
import voluptuous as vol import voluptuous as vol
from homeassistant.components.fan import SUPPORT_DIRECTION, SUPPORT_SET_SPEED, FanEntity from homeassistant.components.fan import FanEntity, FanEntityFeature
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 import entity_platform from homeassistant.helpers import entity_platform
@ -72,6 +72,8 @@ class ModernFormsFanEntity(FanEntity, ModernFormsDeviceEntity):
SPEED_RANGE = (1, 6) # off is not included SPEED_RANGE = (1, 6) # off is not included
_attr_supported_features = FanEntityFeature.DIRECTION | FanEntityFeature.SET_SPEED
def __init__( def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
) -> None: ) -> None:
@ -83,11 +85,6 @@ class ModernFormsFanEntity(FanEntity, ModernFormsDeviceEntity):
) )
self._attr_unique_id = f"{self.coordinator.data.info.mac_address}" self._attr_unique_id = f"{self.coordinator.data.info.mac_address}"
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_DIRECTION | SUPPORT_SET_SPEED
@property @property
def percentage(self) -> int | None: def percentage(self) -> int | None:
"""Return the current speed percentage.""" """Return the current speed percentage."""

View file

@ -1,15 +1,13 @@
"""Support for Alpha2 room control unit via Alpha2 base.""" """Support for Alpha2 room control unit via Alpha2 base."""
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 (
CURRENT_HVAC_COOL, CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT, CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE, CURRENT_HVAC_IDLE,
HVAC_MODE_COOL, HVAC_MODE_COOL,
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
SUPPORT_PRESET_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
@ -43,7 +41,9 @@ class Alpha2Climate(CoordinatorEntity[Alpha2BaseCoordinator], ClimateEntity):
target_temperature_step = 0.2 target_temperature_step = 0.2
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
_attr_hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_COOL] _attr_hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_COOL]
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = TEMP_CELSIUS
_attr_preset_modes = [PRESET_AUTO, PRESET_DAY, PRESET_NIGHT] _attr_preset_modes = [PRESET_AUTO, PRESET_DAY, PRESET_NIGHT]

View file

@ -4,14 +4,9 @@ import logging
from serial import SerialException from serial import SerialException
from homeassistant import core from homeassistant import core
from homeassistant.components.media_player import MediaPlayerEntity from homeassistant.components.media_player import (
from homeassistant.components.media_player.const import ( MediaPlayerEntity,
SUPPORT_SELECT_SOURCE, MediaPlayerEntityFeature,
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 CONF_PORT, STATE_OFF, STATE_ON from homeassistant.const import CONF_PORT, STATE_OFF, STATE_ON
@ -33,15 +28,6 @@ _LOGGER = logging.getLogger(__name__)
PARALLEL_UPDATES = 1 PARALLEL_UPDATES = 1
SUPPORT_MONOPRICE = (
SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_STEP
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_SELECT_SOURCE
)
@core.callback @core.callback
def _get_sources_from_dict(data): def _get_sources_from_dict(data):
@ -127,6 +113,15 @@ async def async_setup_entry(
class MonopriceZone(MediaPlayerEntity): class MonopriceZone(MediaPlayerEntity):
"""Representation of a Monoprice amplifier zone.""" """Representation of a Monoprice amplifier zone."""
_attr_supported_features = (
MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.SELECT_SOURCE
)
def __init__(self, monoprice, sources, namespace, zone_id): def __init__(self, monoprice, sources, namespace, zone_id):
"""Initialize new zone.""" """Initialize new zone."""
self._monoprice = monoprice self._monoprice = monoprice
@ -211,11 +206,6 @@ class MonopriceZone(MediaPlayerEntity):
"""Boolean if volume is currently muted.""" """Boolean if volume is currently muted."""
return self._mute return self._mute
@property
def supported_features(self):
"""Return flag of media commands that are supported."""
return SUPPORT_MONOPRICE
@property @property
def media_title(self): def media_title(self):
"""Return the current source as medial title.""" """Return the current source as medial title."""

View file

@ -12,7 +12,11 @@ from mpd.asyncio import MPDClient
import voluptuous as vol import voluptuous as vol
from homeassistant.components import media_source 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 ( from homeassistant.components.media_player.browse_media import (
async_process_play_media_url, async_process_play_media_url,
) )
@ -22,23 +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_CLEAR_PLAYLIST,
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_MUTE,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
@ -64,19 +51,19 @@ DEFAULT_PORT = 6600
PLAYLIST_UPDATE_INTERVAL = timedelta(seconds=120) PLAYLIST_UPDATE_INTERVAL = timedelta(seconds=120)
SUPPORT_MPD = ( SUPPORT_MPD = (
SUPPORT_PAUSE MediaPlayerEntityFeature.PAUSE
| SUPPORT_PREVIOUS_TRACK | MediaPlayerEntityFeature.PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK | MediaPlayerEntityFeature.NEXT_TRACK
| SUPPORT_PLAY_MEDIA | MediaPlayerEntityFeature.PLAY_MEDIA
| SUPPORT_PLAY | MediaPlayerEntityFeature.PLAY
| SUPPORT_CLEAR_PLAYLIST | MediaPlayerEntityFeature.CLEAR_PLAYLIST
| SUPPORT_REPEAT_SET | MediaPlayerEntityFeature.REPEAT_SET
| SUPPORT_SHUFFLE_SET | MediaPlayerEntityFeature.SHUFFLE_SET
| SUPPORT_SEEK | MediaPlayerEntityFeature.SEEK
| SUPPORT_STOP | MediaPlayerEntityFeature.STOP
| SUPPORT_TURN_OFF | MediaPlayerEntityFeature.TURN_OFF
| SUPPORT_TURN_ON | MediaPlayerEntityFeature.TURN_ON
| SUPPORT_BROWSE_MEDIA | MediaPlayerEntityFeature.BROWSE_MEDIA
) )
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
@ -373,9 +360,13 @@ class MpdDevice(MediaPlayerEntity):
supported = SUPPORT_MPD supported = SUPPORT_MPD
if "volume" in self._status: if "volume" in self._status:
supported |= SUPPORT_VOLUME_SET | SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_MUTE supported |= (
MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_MUTE
)
if self._playlists is not None: if self._playlists is not None:
supported |= SUPPORT_SELECT_SOURCE supported |= MediaPlayerEntityFeature.SELECT_SOURCE
return supported return supported

View file

@ -3,10 +3,9 @@ from pymyq.const import DEVICE_TYPE_GATE as MYQ_DEVICE_TYPE_GATE
from pymyq.errors import MyQError from pymyq.errors import MyQError
from homeassistant.components.cover import ( from homeassistant.components.cover import (
SUPPORT_CLOSE,
SUPPORT_OPEN,
CoverDeviceClass, CoverDeviceClass,
CoverEntity, CoverEntity,
CoverEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING
@ -36,7 +35,7 @@ async def async_setup_entry(
class MyQCover(MyQEntity, CoverEntity): class MyQCover(MyQEntity, CoverEntity):
"""Representation of a MyQ cover.""" """Representation of a MyQ cover."""
_attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
def __init__(self, coordinator, device): def __init__(self, coordinator, device):
"""Initialize with API object, device id.""" """Initialize with API object, device id."""

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.components import mysensors from homeassistant.components import mysensors
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 (
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_LOW,
@ -12,9 +12,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_COOL, HVAC_MODE_COOL,
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
HVAC_MODE_OFF, HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -84,14 +81,14 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
features = 0 features = 0
set_req = self.gateway.const.SetReq set_req = self.gateway.const.SetReq
if set_req.V_HVAC_SPEED in self._values: if set_req.V_HVAC_SPEED in self._values:
features = features | SUPPORT_FAN_MODE features = features | ClimateEntityFeature.FAN_MODE
if ( if (
set_req.V_HVAC_SETPOINT_COOL in self._values set_req.V_HVAC_SETPOINT_COOL in self._values
and set_req.V_HVAC_SETPOINT_HEAT in self._values and set_req.V_HVAC_SETPOINT_HEAT in self._values
): ):
features = features | SUPPORT_TARGET_TEMPERATURE_RANGE features = features | ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
else: else:
features = features | SUPPORT_TARGET_TEMPERATURE features = features | ClimateEntityFeature.TARGET_TEMPERATURE
return features return features
@property @property

View file

@ -39,6 +39,7 @@ from homeassistant.components.climate.const import (
SERVICE_SET_HVAC_MODE, SERVICE_SET_HVAC_MODE,
SERVICE_SET_PRESET_MODE, SERVICE_SET_PRESET_MODE,
SERVICE_SET_TEMPERATURE, SERVICE_SET_TEMPERATURE,
ClimateEntityFeature,
) )
from homeassistant.components.maxcube.climate import ( from homeassistant.components.maxcube.climate import (
MAX_TEMPERATURE, MAX_TEMPERATURE,
@ -46,7 +47,6 @@ from homeassistant.components.maxcube.climate import (
OFF_TEMPERATURE, OFF_TEMPERATURE,
ON_TEMPERATURE, ON_TEMPERATURE,
PRESET_ON, PRESET_ON,
SUPPORT_FLAGS,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
@ -89,7 +89,10 @@ async def test_setup_thermostat(hass, cube: MaxCube):
PRESET_ON, PRESET_ON,
] ]
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_NONE assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_NONE
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == SUPPORT_FLAGS assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
== ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
assert state.attributes.get(ATTR_MAX_TEMP) == MAX_TEMPERATURE assert state.attributes.get(ATTR_MAX_TEMP) == MAX_TEMPERATURE
assert state.attributes.get(ATTR_MIN_TEMP) == 5.0 assert state.attributes.get(ATTR_MIN_TEMP) == 5.0
assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 19.0 assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 19.0