Use EntityFeature enum in components (f**) (#69389)

This commit is contained in:
epenet 2022-04-06 10:55:25 +02:00 committed by GitHub
parent 1fe5b1e68a
commit 9ab9fcfc56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 104 deletions

View file

@ -3,7 +3,11 @@ from __future__ import annotations
import logging
from homeassistant.components.climate import ENTITY_ID_FORMAT, ClimateEntity
from homeassistant.components.climate import (
ENTITY_ID_FORMAT,
ClimateEntity,
ClimateEntityFeature,
)
from homeassistant.components.climate.const import (
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
@ -13,9 +17,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_BOOST,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
@ -157,16 +158,16 @@ class FibaroThermostat(FibaroDevice, ClimateEntity):
or "setHeatingThermostatSetpoint" in device.actions
):
self._target_temp_device = FibaroDevice(device)
self._support_flags |= SUPPORT_TARGET_TEMPERATURE
self._support_flags |= ClimateEntityFeature.TARGET_TEMPERATURE
tempunit = device.properties.unit
if "setMode" in device.actions or "setOperatingMode" in device.actions:
self._op_mode_device = FibaroDevice(device)
self._support_flags |= SUPPORT_PRESET_MODE
self._support_flags |= ClimateEntityFeature.PRESET_MODE
if "setFanMode" in device.actions:
self._fan_mode_device = FibaroDevice(device)
self._support_flags |= SUPPORT_FAN_MODE
self._support_flags |= ClimateEntityFeature.FAN_MODE
if tempunit == "F":
self._unit_of_temp = TEMP_FAHRENHEIT
@ -286,7 +287,7 @@ class FibaroThermostat(FibaroDevice, ClimateEntity):
def preset_mode(self):
"""Return the current preset mode, e.g., home, away, temp.
Requires SUPPORT_PRESET_MODE.
Requires ClimateEntityFeature.PRESET_MODE.
"""
if not self._op_mode_device:
return None
@ -304,7 +305,7 @@ class FibaroThermostat(FibaroDevice, ClimateEntity):
def preset_modes(self):
"""Return a list of available preset modes.
Requires SUPPORT_PRESET_MODE.
Requires ClimateEntityFeature.PRESET_MODE.
"""
if not self._op_mode_device:
return None

View file

@ -10,11 +10,7 @@ from fjaraskupan import (
State,
)
from homeassistant.components.fan import (
SUPPORT_PRESET_MODE,
SUPPORT_SET_SPEED,
FanEntity,
)
from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
@ -73,6 +69,8 @@ async def async_setup_entry(
class Fan(CoordinatorEntity[DataUpdateCoordinator[State]], FanEntity):
"""Fan entity."""
_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
def __init__(
self,
coordinator: DataUpdateCoordinator[State],
@ -155,11 +153,6 @@ class Fan(CoordinatorEntity[DataUpdateCoordinator[State]], FanEntity):
"""Return the current speed."""
return self._percentage
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_SET_SPEED | SUPPORT_PRESET_MODE
@property
def is_on(self) -> bool:
"""Return true if fan is on."""

View file

@ -5,12 +5,12 @@ import logging
import voluptuous as vol
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
from homeassistant.components.climate.const import (
HVAC_MODE_COOL,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
from homeassistant.components.climate import (
PLATFORM_SCHEMA,
ClimateEntity,
ClimateEntityFeature,
)
from homeassistant.components.climate.const import HVAC_MODE_COOL
from homeassistant.components.modbus import get_hub
from homeassistant.components.modbus.const import (
CALL_TYPE_REGISTER_HOLDING,
@ -42,8 +42,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
_LOGGER = logging.getLogger(__name__)
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
async def async_setup_platform(
hass: HomeAssistant,
@ -61,6 +59,10 @@ async def async_setup_platform(
class Flexit(ClimateEntity):
"""Representation of a Flexit AC unit."""
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
)
def __init__(
self, hub: ModbusHub, modbus_slave: int | None, name: str | None
) -> None:
@ -83,11 +85,6 @@ class Flexit(ClimateEntity):
self._alarm = False
self._outdoor_air_temp = None
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS
async def async_update(self):
"""Update unit attributes."""
self._target_temperature = await self._async_read_temp_from_register(

View file

@ -19,9 +19,8 @@ from homeassistant.components.light import (
ATTR_RGBW_COLOR,
ATTR_RGBWW_COLOR,
ATTR_WHITE,
SUPPORT_EFFECT,
SUPPORT_TRANSITION,
LightEntity,
LightEntityFeature,
)
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant, callback
@ -192,7 +191,7 @@ class FluxLight(
):
"""Representation of a Flux light."""
_attr_supported_features = SUPPORT_TRANSITION | SUPPORT_EFFECT
_attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT
def __init__(
self,

View file

@ -6,7 +6,7 @@ import asyncio
from libpyfoscam import FoscamCamera
import voluptuous as vol
from homeassistant.components.camera import SUPPORT_STREAM, Camera
from homeassistant.components.camera import Camera, CameraEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
from homeassistant.core import HomeAssistant
@ -106,6 +106,8 @@ class HassFoscamCamera(Camera):
self._unique_id = config_entry.entry_id
self._rtsp_port = config_entry.data[CONF_RTSP_PORT]
self._motion_status = False
if self._rtsp_port:
self._attr_supported_features = CameraEntityFeature.STREAM
async def async_added_to_hass(self):
"""Handle entity addition to hass."""
@ -145,14 +147,6 @@ class HassFoscamCamera(Camera):
return response
@property
def supported_features(self):
"""Return supported features."""
if self._rtsp_port:
return SUPPORT_STREAM
return None
async def stream_source(self):
"""Return the stream source."""
if self._rtsp_port:

View file

@ -4,13 +4,12 @@ import logging
from pyfreedompro import put_state
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, CONF_API_KEY, TEMP_CELSIUS
@ -72,7 +71,7 @@ class Device(CoordinatorEntity, ClimateEntity):
model=device["type"],
name=self.name,
)
self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
self._attr_current_temperature = 0
self._attr_target_temperature = 0
self._attr_hvac_mode = HVAC_MODE_OFF

View file

@ -5,11 +5,9 @@ from pyfreedompro import put_state
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.const import CONF_API_KEY
@ -66,7 +64,9 @@ class Device(CoordinatorEntity, CoverEntity):
self._attr_current_cover_position = 0
self._attr_is_closed = True
self._attr_supported_features = (
SUPPORT_CLOSE | SUPPORT_OPEN | SUPPORT_SET_POSITION
CoverEntityFeature.CLOSE
| CoverEntityFeature.OPEN
| CoverEntityFeature.SET_POSITION
)
self._attr_device_class = DEVICE_CLASS_MAP[device["type"]]

View file

@ -5,7 +5,7 @@ import json
from pyfreedompro import put_state
from homeassistant.components.fan import SUPPORT_SET_SPEED, FanEntity
from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant, callback
@ -51,6 +51,8 @@ class FreedomproFan(CoordinatorEntity, FanEntity):
)
self._attr_is_on = False
self._attr_percentage = 0
if "rotationSpeed" in self._characteristics:
self._attr_supported_features = FanEntityFeature.SET_SPEED
@property
def is_on(self) -> bool | None:
@ -62,13 +64,6 @@ class FreedomproFan(CoordinatorEntity, FanEntity):
"""Return the current speed percentage."""
return self._attr_percentage
@property
def supported_features(self):
"""Flag supported features."""
if "rotationSpeed" in self._characteristics:
return SUPPORT_SET_SPEED
return 0
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""

View file

@ -3,15 +3,13 @@ from __future__ import annotations
from typing import Any
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_COMFORT,
PRESET_ECO,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
@ -34,8 +32,6 @@ from .const import (
)
from .model import ClimateExtraAttributes
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
OPERATION_LIST = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
MIN_TEMPERATURE = 8
@ -68,10 +64,9 @@ async def async_setup_entry(
class FritzboxThermostat(FritzBoxEntity, ClimateEntity):
"""The thermostat class for FRITZ!SmartHome thermostats."""
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_FLAGS
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
@property
def temperature_unit(self) -> str:

View file

@ -7,23 +7,12 @@ from afsapi import AFSAPI
import requests
import voluptuous as vol
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SEEK,
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 import (
PLATFORM_SCHEMA,
MediaPlayerEntity,
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
@ -42,22 +31,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__)
SUPPORT_FRONTIER_SILICON = (
SUPPORT_PAUSE
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_STEP
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_SEEK
| SUPPORT_PLAY_MEDIA
| SUPPORT_PLAY
| SUPPORT_STOP
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_SELECT_SOURCE
)
DEFAULT_PORT = 80
DEFAULT_PASSWORD = "1234"
@ -104,6 +77,22 @@ async def async_setup_platform(
class AFSAPIDevice(MediaPlayerEntity):
"""Representation of a Frontier Silicon device on the network."""
_attr_supported_features = (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.SEEK
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.SELECT_SOURCE
)
def __init__(self, device_url, password, name):
"""Initialize the Frontier Silicon API device."""
self._device_url = device_url
@ -158,11 +147,6 @@ class AFSAPIDevice(MediaPlayerEntity):
"""Content type of current playing media."""
return MEDIA_TYPE_MUSIC
@property
def supported_features(self):
"""Flag of media commands that are supported."""
return SUPPORT_FRONTIER_SILICON
@property
def state(self):
"""Return the state of the player."""