Use EntityFeature enum in components (p**) (#69434)

This commit is contained in:
epenet 2022-04-07 15:03:42 +02:00 committed by GitHub
parent b8fc399882
commit 80a857c6c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 137 additions and 206 deletions

View file

@ -6,13 +6,10 @@ from datetime import timedelta
from panacotta import PanasonicBD from panacotta import PanasonicBD
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_PAUSE, MediaPlayerEntity,
SUPPORT_PLAY, MediaPlayerEntityFeature,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
@ -31,9 +28,6 @@ DEFAULT_NAME = "Panasonic Blu-Ray"
SCAN_INTERVAL = timedelta(seconds=30) SCAN_INTERVAL = timedelta(seconds=30)
SUPPORT_PANASONIC_BD = (
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PLAY | SUPPORT_STOP | SUPPORT_PAUSE
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
@ -59,6 +53,14 @@ def setup_platform(
class PanasonicBluRay(MediaPlayerEntity): class PanasonicBluRay(MediaPlayerEntity):
"""Representation of a Panasonic Blu-ray device.""" """Representation of a Panasonic Blu-ray device."""
_attr_supported_features = (
MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.PAUSE
)
def __init__(self, ip, name): def __init__(self, ip, name):
"""Initialize the Panasonic Blue-ray device.""" """Initialize the Panasonic Blue-ray device."""
self._device = PanasonicBD(ip) self._device = PanasonicBD(ip)
@ -83,11 +85,6 @@ class PanasonicBluRay(MediaPlayerEntity):
"""Return _state variable, containing the appropriate constant.""" """Return _state variable, containing the appropriate constant."""
return self._state return self._state
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_PANASONIC_BD
@property @property
def media_duration(self): def media_duration(self):
"""Duration of current playing media in seconds.""" """Duration of current playing media in seconds."""

View file

@ -9,25 +9,12 @@ from homeassistant.components import media_source
from homeassistant.components.media_player import ( from homeassistant.components.media_player import (
MediaPlayerDeviceClass, MediaPlayerDeviceClass,
MediaPlayerEntity, 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,
) )
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import MEDIA_TYPE_URL
MEDIA_TYPE_URL,
SUPPORT_BROWSE_MEDIA,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
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 CONF_NAME from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -45,21 +32,6 @@ from .const import (
DOMAIN, DOMAIN,
) )
SUPPORT_VIERATV = (
SUPPORT_PAUSE
| SUPPORT_VOLUME_STEP
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_MUTE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_TURN_OFF
| SUPPORT_TURN_ON
| SUPPORT_PLAY
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_BROWSE_MEDIA
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -83,6 +55,21 @@ async def async_setup_entry(
class PanasonicVieraTVEntity(MediaPlayerEntity): class PanasonicVieraTVEntity(MediaPlayerEntity):
"""Representation of a Panasonic Viera TV.""" """Representation of a Panasonic Viera TV."""
_attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.BROWSE_MEDIA
)
def __init__(self, remote, name, device_info): def __init__(self, remote, name, device_info):
"""Initialize the entity.""" """Initialize the entity."""
self._remote = remote self._remote = remote
@ -138,11 +125,6 @@ class PanasonicVieraTVEntity(MediaPlayerEntity):
"""Boolean if volume is currently muted.""" """Boolean if volume is currently muted."""
return self._remote.muted return self._remote.muted
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_VIERATV
async def async_update(self): async def async_update(self):
"""Retrieve the latest data.""" """Retrieve the latest data."""
await self._remote.async_update() await self._remote.async_update()

View file

@ -11,16 +11,11 @@ import signal
import pexpect import pexpect
from homeassistant import util from homeassistant import util
from homeassistant.components.media_player import MediaPlayerEntity from homeassistant.components.media_player import (
from homeassistant.components.media_player.const import ( MediaPlayerEntity,
MEDIA_TYPE_MUSIC, MediaPlayerEntityFeature,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_SELECT_SOURCE,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
) )
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
from homeassistant.const import ( from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_NEXT_TRACK,
@ -39,16 +34,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
# SUPPORT_VOLUME_SET is close to available but we need volume up/down
# controls in the GUI.
PANDORA_SUPPORT = (
SUPPORT_PAUSE
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_NEXT_TRACK
| SUPPORT_SELECT_SOURCE
| SUPPORT_PLAY
)
CMD_MAP = { CMD_MAP = {
SERVICE_MEDIA_NEXT_TRACK: "n", SERVICE_MEDIA_NEXT_TRACK: "n",
@ -85,6 +70,17 @@ def setup_platform(
class PandoraMediaPlayer(MediaPlayerEntity): class PandoraMediaPlayer(MediaPlayerEntity):
"""A media player that uses the Pianobar interface to Pandora.""" """A media player that uses the Pianobar interface to Pandora."""
# MediaPlayerEntityFeature.VOLUME_SET is close to available but we need volume up/down
# controls in the GUI.
_attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.PLAY
)
def __init__(self, name): def __init__(self, name):
"""Initialize the Pandora device.""" """Initialize the Pandora device."""
self._name = name self._name = name
@ -172,11 +168,6 @@ class PandoraMediaPlayer(MediaPlayerEntity):
self._send_pianobar_command(SERVICE_MEDIA_NEXT_TRACK) self._send_pianobar_command(SERVICE_MEDIA_NEXT_TRACK)
self.schedule_update_ha_state() self.schedule_update_ha_state()
@property
def supported_features(self):
"""Flag media player features that are supported."""
return PANDORA_SUPPORT
@property @property
def source(self): def source(self):
"""Name of the current input source.""" """Name of the current input source."""

View file

@ -7,6 +7,7 @@ from homeassistant.components.media_player import (
BrowseMedia, BrowseMedia,
MediaPlayerDeviceClass, MediaPlayerDeviceClass,
MediaPlayerEntity, MediaPlayerEntity,
MediaPlayerEntityFeature,
) )
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import (
MEDIA_CLASS_APP, MEDIA_CLASS_APP,
@ -16,19 +17,6 @@ from homeassistant.components.media_player.const import (
MEDIA_TYPE_APPS, MEDIA_TYPE_APPS,
MEDIA_TYPE_CHANNEL, MEDIA_TYPE_CHANNEL,
MEDIA_TYPE_CHANNELS, MEDIA_TYPE_CHANNELS,
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.errors import BrowseError from homeassistant.components.media_player.errors import BrowseError
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -42,18 +30,18 @@ from . import LOGGER as _LOGGER, PhilipsTVDataUpdateCoordinator
from .const import DOMAIN from .const import DOMAIN
SUPPORT_PHILIPS_JS = ( SUPPORT_PHILIPS_JS = (
SUPPORT_TURN_OFF MediaPlayerEntityFeature.TURN_OFF
| SUPPORT_VOLUME_STEP | MediaPlayerEntityFeature.VOLUME_STEP
| SUPPORT_VOLUME_SET | MediaPlayerEntityFeature.VOLUME_SET
| SUPPORT_VOLUME_MUTE | MediaPlayerEntityFeature.VOLUME_MUTE
| SUPPORT_SELECT_SOURCE | MediaPlayerEntityFeature.SELECT_SOURCE
| SUPPORT_NEXT_TRACK | MediaPlayerEntityFeature.NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK | MediaPlayerEntityFeature.PREVIOUS_TRACK
| SUPPORT_PLAY_MEDIA | MediaPlayerEntityFeature.PLAY_MEDIA
| SUPPORT_BROWSE_MEDIA | MediaPlayerEntityFeature.BROWSE_MEDIA
| SUPPORT_PLAY | MediaPlayerEntityFeature.PLAY
| SUPPORT_PAUSE | MediaPlayerEntityFeature.PAUSE
| SUPPORT_STOP | MediaPlayerEntityFeature.STOP
) )
CONF_ON_ACTION = "turn_on_action" CONF_ON_ACTION = "turn_on_action"
@ -128,7 +116,7 @@ class PhilipsTVMediaPlayer(
if self.coordinator.turn_on or ( if self.coordinator.turn_on or (
self._tv.on and self._tv.powerstate is not None self._tv.on and self._tv.powerstate is not None
): ):
supports |= SUPPORT_TURN_ON supports |= MediaPlayerEntityFeature.TURN_ON
return supports return supports
@property @property

View file

@ -6,16 +6,10 @@ import telnetlib
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_PAUSE, MediaPlayerEntity,
SUPPORT_PLAY, MediaPlayerEntityFeature,
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,
@ -39,16 +33,6 @@ DEFAULT_PORT = 23 # telnet default. Some Pioneer AVRs use 8102
DEFAULT_TIMEOUT = None DEFAULT_TIMEOUT = None
DEFAULT_SOURCES: dict[str, str] = {} DEFAULT_SOURCES: dict[str, str] = {}
SUPPORT_PIONEER = (
SUPPORT_PAUSE
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_STEP
| SUPPORT_VOLUME_MUTE
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_SELECT_SOURCE
| SUPPORT_PLAY
)
MAX_VOLUME = 185 MAX_VOLUME = 185
MAX_SOURCE_NUMBERS = 60 MAX_SOURCE_NUMBERS = 60
@ -86,6 +70,17 @@ def setup_platform(
class PioneerDevice(MediaPlayerEntity): class PioneerDevice(MediaPlayerEntity):
"""Representation of a Pioneer device.""" """Representation of a Pioneer device."""
_attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.PLAY
)
def __init__(self, name, host, port, timeout, sources): def __init__(self, name, host, port, timeout, sources):
"""Initialize the Pioneer device.""" """Initialize the Pioneer device."""
self._name = name self._name = name
@ -200,11 +195,6 @@ class PioneerDevice(MediaPlayerEntity):
"""Boolean if volume is currently muted.""" """Boolean if volume is currently muted."""
return self._muted return self._muted
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_PIONEER
@property @property
def source(self): def source(self):
"""Return the current input source.""" """Return the current input source."""

View file

@ -5,12 +5,10 @@ from pypjlink import MUTE_AUDIO, Projector
from pypjlink.projector import ProjectorError from pypjlink.projector import ProjectorError
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,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
@ -41,10 +39,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
} }
) )
SUPPORT_PJLINK = (
SUPPORT_VOLUME_MUTE | SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE
)
def setup_platform( def setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
@ -80,6 +74,13 @@ def format_input_source(input_source_name, input_source_number):
class PjLinkDevice(MediaPlayerEntity): class PjLinkDevice(MediaPlayerEntity):
"""Representation of a PJLink device.""" """Representation of a PJLink device."""
_attr_supported_features = (
MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.SELECT_SOURCE
)
def __init__(self, host, port, name, encoding, password): def __init__(self, host, port, name, encoding, password):
"""Iinitialize the PJLink device.""" """Iinitialize the PJLink device."""
self._host = host self._host = host
@ -160,11 +161,6 @@ class PjLinkDevice(MediaPlayerEntity):
"""Return all available input sources.""" """Return all available input sources."""
return self._source_list return self._source_list
@property
def supported_features(self):
"""Return projector supported features."""
return SUPPORT_PJLINK
def turn_off(self): def turn_off(self):
"""Turn projector off.""" """Turn projector off."""
with self.projector() as projector: with self.projector() as projector:

View file

@ -7,20 +7,12 @@ import logging
import plexapi.exceptions import plexapi.exceptions
import requests.exceptions import requests.exceptions
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN, MediaPlayerEntity from homeassistant.components.media_player import (
from homeassistant.components.media_player.const import ( DOMAIN as MP_DOMAIN,
MEDIA_TYPE_MUSIC, MediaPlayerEntity,
SUPPORT_BROWSE_MEDIA, MediaPlayerEntityFeature,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SEEK,
SUPPORT_STOP,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
) )
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_IDLE, STATE_PAUSED, STATE_PLAYING from homeassistant.const import STATE_IDLE, STATE_PAUSED, STATE_PLAYING
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -389,19 +381,21 @@ class PlexMediaPlayer(MediaPlayerEntity):
"""Flag media player features that are supported.""" """Flag media player features that are supported."""
if self.device and "playback" in self._device_protocol_capabilities: if self.device and "playback" in self._device_protocol_capabilities:
return ( return (
SUPPORT_PAUSE MediaPlayerEntityFeature.PAUSE
| SUPPORT_PREVIOUS_TRACK | MediaPlayerEntityFeature.PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK | MediaPlayerEntityFeature.NEXT_TRACK
| SUPPORT_STOP | MediaPlayerEntityFeature.STOP
| SUPPORT_SEEK | MediaPlayerEntityFeature.SEEK
| SUPPORT_VOLUME_SET | MediaPlayerEntityFeature.VOLUME_SET
| SUPPORT_PLAY | MediaPlayerEntityFeature.PLAY
| SUPPORT_PLAY_MEDIA | MediaPlayerEntityFeature.PLAY_MEDIA
| SUPPORT_VOLUME_MUTE | MediaPlayerEntityFeature.VOLUME_MUTE
| SUPPORT_BROWSE_MEDIA | MediaPlayerEntityFeature.BROWSE_MEDIA
) )
return SUPPORT_BROWSE_MEDIA | SUPPORT_PLAY_MEDIA return (
MediaPlayerEntityFeature.BROWSE_MEDIA | MediaPlayerEntityFeature.PLAY_MEDIA
)
def set_volume_level(self, volume): def set_volume_level(self, volume):
"""Set volume level, range 0..1.""" """Set volume level, range 0..1."""

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
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 (
CURRENT_HVAC_COOL, CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT, CURRENT_HVAC_HEAT,
@ -12,8 +12,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_AUTO, HVAC_MODE_AUTO,
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
@ -57,9 +55,9 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
self._attr_name = self.device.get("name") self._attr_name = self.device.get("name")
# Determine preset modes # Determine preset modes
self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
if presets := self.device.get("presets"): if presets := self.device.get("presets"):
self._attr_supported_features |= SUPPORT_PRESET_MODE self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
self._attr_preset_modes = list(presets) self._attr_preset_modes = list(presets)
# Determine hvac modes and current hvac mode # Determine hvac modes and current hvac mode

View file

@ -1,8 +1,11 @@
"""Support for Minut Point.""" """Support for Minut Point."""
import logging import logging
from homeassistant.components.alarm_control_panel import DOMAIN, AlarmControlPanelEntity from homeassistant.components.alarm_control_panel import (
from homeassistant.components.alarm_control_panel.const import SUPPORT_ALARM_ARM_AWAY DOMAIN,
AlarmControlPanelEntity,
AlarmControlPanelEntityFeature,
)
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,
@ -46,6 +49,8 @@ async def async_setup_entry(
class MinutPointAlarmControl(AlarmControlPanelEntity): class MinutPointAlarmControl(AlarmControlPanelEntity):
"""The platform class required by Home Assistant.""" """The platform class required by Home Assistant."""
_attr_supported_features = AlarmControlPanelEntityFeature.ARM_AWAY
def __init__(self, point_client, home_id): def __init__(self, point_client, home_id):
"""Initialize the entity.""" """Initialize the entity."""
self._client = point_client self._client = point_client
@ -96,11 +101,6 @@ class MinutPointAlarmControl(AlarmControlPanelEntity):
"""Return state of the device.""" """Return state of the device."""
return EVENT_MAP.get(self._home["alarm_status"], STATE_ALARM_ARMED_AWAY) return EVENT_MAP.get(self._home["alarm_status"], STATE_ALARM_ARMED_AWAY)
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_AWAY
@property @property
def changed_by(self): def changed_by(self):
"""Return the user the last change was triggered by.""" """Return the user the last change was triggered by."""

View file

@ -4,7 +4,11 @@ from __future__ import annotations
import proliphix import proliphix
import voluptuous as vol 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 ( from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL, CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT, CURRENT_HVAC_HEAT,
@ -13,7 +17,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_TARGET_TEMPERATURE,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
@ -59,16 +62,13 @@ def setup_platform(
class ProliphixThermostat(ClimateEntity): class ProliphixThermostat(ClimateEntity):
"""Representation a Proliphix thermostat.""" """Representation a Proliphix thermostat."""
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def __init__(self, pdp): def __init__(self, pdp):
"""Initialize the thermostat.""" """Initialize the thermostat."""
self._pdp = pdp self._pdp = pdp
self._name = None self._name = None
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE
@property @property
def should_poll(self): def should_poll(self):
"""Set up polling needed for thermostat.""" """Set up polling needed for thermostat."""

View file

@ -5,10 +5,7 @@ from pyprosegur.auth import Auth
from pyprosegur.installation import Installation, Status from pyprosegur.installation import Installation, Status
import homeassistant.components.alarm_control_panel as alarm import homeassistant.components.alarm_control_panel as alarm
from homeassistant.components.alarm_control_panel 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,
@ -43,6 +40,11 @@ async def async_setup_entry(
class ProsegurAlarm(alarm.AlarmControlPanelEntity): class ProsegurAlarm(alarm.AlarmControlPanelEntity):
"""Representation of a Prosegur alarm status.""" """Representation of a Prosegur alarm status."""
_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_AWAY
| AlarmControlPanelEntityFeature.ARM_HOME
)
def __init__(self, contract: str, auth: Auth) -> None: def __init__(self, contract: str, auth: Auth) -> None:
"""Initialize the Prosegur alarm panel.""" """Initialize the Prosegur alarm panel."""
self._changed_by = None self._changed_by = None
@ -53,7 +55,6 @@ class ProsegurAlarm(alarm.AlarmControlPanelEntity):
self._attr_name = f"contract {self.contract}" self._attr_name = f"contract {self.contract}"
self._attr_unique_id = self.contract self._attr_unique_id = self.contract
self._attr_supported_features = SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_HOME
async def async_update(self): async def async_update(self):
"""Update alarm status.""" """Update alarm status."""

View file

@ -7,17 +7,15 @@ from pyps4_2ndscreen.errors import NotReady, PSDataIncomplete
from pyps4_2ndscreen.media_art import TYPE_APP as PS_TYPE_APP from pyps4_2ndscreen.media_art import TYPE_APP as PS_TYPE_APP
import pyps4_2ndscreen.ps4 as pyps4 import pyps4_2ndscreen.ps4 as pyps4
from homeassistant.components.media_player import MediaPlayerEntity from homeassistant.components.media_player import (
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import (
ATTR_MEDIA_CONTENT_TYPE, ATTR_MEDIA_CONTENT_TYPE,
ATTR_MEDIA_TITLE, ATTR_MEDIA_TITLE,
MEDIA_TYPE_APP, MEDIA_TYPE_APP,
MEDIA_TYPE_GAME, MEDIA_TYPE_GAME,
SUPPORT_PAUSE,
SUPPORT_SELECT_SOURCE,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -46,13 +44,6 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
SUPPORT_PS4 = (
SUPPORT_TURN_OFF
| SUPPORT_TURN_ON
| SUPPORT_PAUSE
| SUPPORT_STOP
| SUPPORT_SELECT_SOURCE
)
ICON = "mdi:sony-playstation" ICON = "mdi:sony-playstation"
MEDIA_IMAGE_DEFAULT = None MEDIA_IMAGE_DEFAULT = None
@ -81,6 +72,14 @@ async def async_setup_entry(
class PS4Device(MediaPlayerEntity): class PS4Device(MediaPlayerEntity):
"""Representation of a PS4.""" """Representation of a PS4."""
_attr_supported_features = (
MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.SELECT_SOURCE
)
def __init__(self, config, name, host, region, ps4, creds): def __init__(self, config, name, host, region, ps4, creds):
"""Initialize the ps4 device.""" """Initialize the ps4 device."""
self._entry_id = config.entry_id self._entry_id = config.entry_id
@ -430,11 +429,6 @@ class PS4Device(MediaPlayerEntity):
"""Title of current playing media.""" """Title of current playing media."""
return self._media_title return self._media_title
@property
def supported_features(self):
"""Media player features that are supported."""
return SUPPORT_PS4
@property @property
def source(self): def source(self):
"""Return the current input source.""" """Return the current input source."""