From fbea950eb0ff45992a940ff9ff140e9fa40ba442 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 7 Apr 2022 08:21:31 +0200 Subject: [PATCH] Use EntityFeature enum in components (z**) (#69471) * Use EntityFeature enum in zha * Use EntityFeature enum in zhong_hong * Use EntityFeature enum in ziggo_mediabox_xl * Use EntityFeature enum in zwave_js * Use EntityFeature enum in zwave_me --- .../components/zha/alarm_control_panel.py | 22 ++++------- homeassistant/components/zha/climate.py | 20 ++++------ homeassistant/components/zha/fan.py | 9 ++--- .../components/zhong_hong/climate.py | 17 +++++---- .../ziggo_mediabox_xl/media_player.py | 38 +++++++------------ homeassistant/components/zwave_js/climate.py | 22 ++++------- homeassistant/components/zwave_js/cover.py | 24 +++++------- homeassistant/components/zwave_js/fan.py | 16 +++----- homeassistant/components/zwave_me/climate.py | 14 ++----- homeassistant/components/zwave_me/cover.py | 15 ++++---- 10 files changed, 76 insertions(+), 121 deletions(-) diff --git a/homeassistant/components/zha/alarm_control_panel.py b/homeassistant/components/zha/alarm_control_panel.py index 17dc47ebefa..bccc75958eb 100644 --- a/homeassistant/components/zha/alarm_control_panel.py +++ b/homeassistant/components/zha/alarm_control_panel.py @@ -5,11 +5,8 @@ from zigpy.zcl.clusters.security import IasAce from homeassistant.components.alarm_control_panel import ( FORMAT_TEXT, - SUPPORT_ALARM_ARM_AWAY, - SUPPORT_ALARM_ARM_HOME, - SUPPORT_ALARM_ARM_NIGHT, - SUPPORT_ALARM_TRIGGER, AlarmControlPanelEntity, + AlarmControlPanelEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -79,6 +76,13 @@ async def async_setup_entry( class ZHAAlarmControlPanel(ZhaEntity, AlarmControlPanelEntity): """Entity for ZHA alarm control devices.""" + _attr_supported_features = ( + AlarmControlPanelEntityFeature.ARM_HOME + | AlarmControlPanelEntityFeature.ARM_AWAY + | AlarmControlPanelEntityFeature.ARM_NIGHT + | AlarmControlPanelEntityFeature.TRIGGER + ) + def __init__(self, unique_id, zha_device: ZhaDeviceType, channels, **kwargs): """Initialize the ZHA alarm control device.""" super().__init__(unique_id, zha_device, channels, **kwargs) @@ -148,16 +152,6 @@ class ZHAAlarmControlPanel(ZhaEntity, AlarmControlPanelEntity): """Send alarm trigger command.""" self.async_write_ha_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 def state(self): """Return the state of the entity.""" diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index 06b1e8a47d8..7cce0732902 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -12,7 +12,7 @@ from random import randint from zigpy.zcl.clusters.hvac import Fan as F, Thermostat as T -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, ATTR_TARGET_TEMP_HIGH, @@ -35,10 +35,6 @@ from homeassistant.components.climate.const import ( PRESET_COMFORT, PRESET_ECO, PRESET_NONE, - SUPPORT_FAN_MODE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, - SUPPORT_TARGET_TEMPERATURE_RANGE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -155,7 +151,7 @@ class Thermostat(ZhaEntity, ClimateEntity): self._thrm = self.cluster_channels.get(CHANNEL_THERMOSTAT) self._preset = PRESET_NONE self._presets = [] - self._supported_flags = SUPPORT_TARGET_TEMPERATURE + self._supported_flags = ClimateEntityFeature.TARGET_TEMPERATURE self._fan = self.cluster_channels.get(CHANNEL_FAN) @property @@ -294,9 +290,9 @@ class Thermostat(ZhaEntity, ClimateEntity): """Return the list of supported features.""" features = self._supported_flags if HVAC_MODE_HEAT_COOL in self.hvac_modes: - features |= SUPPORT_TARGET_TEMPERATURE_RANGE + features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE if self._fan is not None: - self._supported_flags |= SUPPORT_FAN_MODE + self._supported_flags |= ClimateEntityFeature.FAN_MODE return features @property @@ -513,7 +509,7 @@ class SinopeTechnologiesThermostat(Thermostat): """Initialize ZHA Thermostat instance.""" super().__init__(unique_id, zha_device, channels, **kwargs) self._presets = [PRESET_AWAY, PRESET_NONE] - self._supported_flags |= SUPPORT_PRESET_MODE + self._supported_flags |= ClimateEntityFeature.PRESET_MODE self._manufacturer_ch = self.cluster_channels["sinope_manufacturer_specific"] @property @@ -624,7 +620,7 @@ class MoesThermostat(Thermostat): PRESET_BOOST, PRESET_COMPLEX, ] - self._supported_flags |= SUPPORT_PRESET_MODE + self._supported_flags |= ClimateEntityFeature.PRESET_MODE @property def hvac_modes(self) -> tuple[str, ...]: @@ -705,7 +701,7 @@ class BecaThermostat(Thermostat): PRESET_BOOST, PRESET_TEMP_MANUAL, ] - self._supported_flags |= SUPPORT_PRESET_MODE + self._supported_flags |= ClimateEntityFeature.PRESET_MODE @property def hvac_modes(self) -> tuple[str, ...]: @@ -804,7 +800,7 @@ class ZONNSMARTThermostat(Thermostat): PRESET_SCHEDULE, self.PRESET_FROST, ] - self._supported_flags |= SUPPORT_PRESET_MODE + self._supported_flags |= ClimateEntityFeature.PRESET_MODE async def async_attribute_updated(self, record): """Handle attribute update from device.""" diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index e6f28935d10..bad1d8e94f1 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -11,8 +11,8 @@ from zigpy.zcl.clusters import hvac from homeassistant.components.fan import ( ATTR_PERCENTAGE, ATTR_PRESET_MODE, - SUPPORT_SET_SPEED, FanEntity, + FanEntityFeature, NotValidPresetModeError, ) from homeassistant.config_entries import ConfigEntry @@ -76,16 +76,13 @@ async def async_setup_entry( class BaseFan(FanEntity): """Base representation of a ZHA fan.""" + _attr_supported_features = FanEntityFeature.SET_SPEED + @property def preset_modes(self) -> list[str]: """Return the available preset modes.""" return PRESET_MODES - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_SET_SPEED - @property def speed_count(self) -> int: """Return the number of speeds the fan supports.""" diff --git a/homeassistant/components/zhong_hong/climate.py b/homeassistant/components/zhong_hong/climate.py index 6c04775d233..46fbce9db33 100644 --- a/homeassistant/components/zhong_hong/climate.py +++ b/homeassistant/components/zhong_hong/climate.py @@ -7,7 +7,11 @@ import voluptuous as vol from zhong_hong_hvac.hub import ZhongHongGateway from zhong_hong_hvac.hvac import HVAC as ZhongHongHVAC -from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity +from homeassistant.components.climate import ( + PLATFORM_SCHEMA, + ClimateEntity, + ClimateEntityFeature, +) from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, HVAC_MODE_COOL, @@ -15,8 +19,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_FAN_MODE, - SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.const import ( ATTR_TEMPERATURE, @@ -130,6 +132,10 @@ def setup_platform( class ZhongHongClimate(ClimateEntity): """Representation of a ZhongHong controller support HVAC.""" + _attr_supported_features = ( + ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE + ) + def __init__(self, hub, addr_out, addr_in): """Set up the ZhongHong climate devices.""" @@ -177,11 +183,6 @@ class ZhongHongClimate(ClimateEntity): """Return the unique ID of the HVAC.""" return f"zhong_hong_hvac_{self._device.addr_out}_{self._device.addr_in}" - @property - def supported_features(self): - """Return the list of supported features.""" - return SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE - @property def temperature_unit(self): """Return the unit of measurement used by the platform.""" diff --git a/homeassistant/components/ziggo_mediabox_xl/media_player.py b/homeassistant/components/ziggo_mediabox_xl/media_player.py index 59e6e56e2c5..42c86020d2e 100644 --- a/homeassistant/components/ziggo_mediabox_xl/media_player.py +++ b/homeassistant/components/ziggo_mediabox_xl/media_player.py @@ -7,15 +7,10 @@ import socket import voluptuous as vol from ziggo_mediabox_xl import ZiggoMediaboxXL -from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity -from homeassistant.components.media_player.const import ( - SUPPORT_NEXT_TRACK, - SUPPORT_PAUSE, - SUPPORT_PLAY, - SUPPORT_PREVIOUS_TRACK, - SUPPORT_SELECT_SOURCE, - SUPPORT_TURN_OFF, - SUPPORT_TURN_ON, +from homeassistant.components.media_player import ( + PLATFORM_SCHEMA, + MediaPlayerEntity, + MediaPlayerEntityFeature, ) from homeassistant.const import ( CONF_HOST, @@ -33,16 +28,6 @@ _LOGGER = logging.getLogger(__name__) DATA_KNOWN_DEVICES = "ziggo_mediabox_xl_known_devices" -SUPPORT_ZIGGO = ( - SUPPORT_TURN_ON - | SUPPORT_TURN_OFF - | SUPPORT_NEXT_TRACK - | SUPPORT_PAUSE - | SUPPORT_PREVIOUS_TRACK - | SUPPORT_SELECT_SOURCE - | SUPPORT_PLAY -) - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME): cv.string} ) @@ -104,6 +89,16 @@ def setup_platform( class ZiggoMediaboxXLDevice(MediaPlayerEntity): """Representation of a Ziggo Mediabox XL Device.""" + _attr_supported_features = ( + MediaPlayerEntityFeature.TURN_ON + | MediaPlayerEntityFeature.TURN_OFF + | MediaPlayerEntityFeature.NEXT_TRACK + | MediaPlayerEntityFeature.PAUSE + | MediaPlayerEntityFeature.PREVIOUS_TRACK + | MediaPlayerEntityFeature.SELECT_SOURCE + | MediaPlayerEntityFeature.PLAY + ) + def __init__(self, mediabox, host, name, available): """Initialize the device.""" self._mediabox = mediabox @@ -158,11 +153,6 @@ class ZiggoMediaboxXLDevice(MediaPlayerEntity): for c in sorted(self._mediabox.channels().keys()) ] - @property - def supported_features(self): - """Flag media player features that are supported.""" - return SUPPORT_ZIGGO - def turn_on(self): """Turn the media player on.""" self.send_keys(["POWER"]) diff --git a/homeassistant/components/zwave_js/climate.py b/homeassistant/components/zwave_js/climate.py index 88c96feea88..5d62f746490 100644 --- a/homeassistant/components/zwave_js/climate.py +++ b/homeassistant/components/zwave_js/climate.py @@ -23,6 +23,7 @@ from homeassistant.components.climate import ( DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, ClimateEntity, + ClimateEntityFeature, ) from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, @@ -40,10 +41,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF, PRESET_NONE, - SUPPORT_FAN_MODE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, - SUPPORT_TARGET_TEMPERATURE_RANGE, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -193,17 +190,19 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): check_all_endpoints=True, ) self._set_modes_and_presets() - self._supported_features = 0 + self._attr_supported_features = 0 if len(self._hvac_presets) > 1: - self._supported_features |= SUPPORT_PRESET_MODE + self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE # If any setpoint value exists, we can assume temperature # can be set if any(self._setpoint_values.values()): - self._supported_features |= SUPPORT_TARGET_TEMPERATURE + self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE if HVAC_MODE_HEAT_COOL in self.hvac_modes: - self._supported_features |= SUPPORT_TARGET_TEMPERATURE_RANGE + self._attr_supported_features |= ( + ClimateEntityFeature.TARGET_TEMPERATURE_RANGE + ) if self._fan_mode: - self._supported_features |= SUPPORT_FAN_MODE + self._attr_supported_features |= ClimateEntityFeature.FAN_MODE def _setpoint_value(self, setpoint_type: ThermostatSetpointType) -> ZwaveValue: """Optionally return a ZwaveValue for a setpoint.""" @@ -382,11 +381,6 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): return None - @property - def supported_features(self) -> int: - """Return the list of supported features.""" - return self._supported_features - @property def min_temp(self) -> float: """Return the minimum temperature.""" diff --git a/homeassistant/components/zwave_js/cover.py b/homeassistant/components/zwave_js/cover.py index dc72b545396..9281f0bc21c 100644 --- a/homeassistant/components/zwave_js/cover.py +++ b/homeassistant/components/zwave_js/cover.py @@ -21,15 +21,9 @@ from homeassistant.components.cover import ( ATTR_POSITION, ATTR_TILT_POSITION, DOMAIN as COVER_DOMAIN, - SUPPORT_CLOSE, - SUPPORT_CLOSE_TILT, - SUPPORT_OPEN, - SUPPORT_OPEN_TILT, - SUPPORT_SET_POSITION, - SUPPORT_SET_TILT_POSITION, - SUPPORT_STOP, CoverDeviceClass, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -180,13 +174,13 @@ class ZWaveTiltCover(ZWaveCover): """Representation of a Z-Wave Cover device with tilt.""" _attr_supported_features = ( - SUPPORT_OPEN - | SUPPORT_CLOSE - | SUPPORT_STOP - | SUPPORT_SET_POSITION - | SUPPORT_OPEN_TILT - | SUPPORT_CLOSE_TILT - | SUPPORT_SET_TILT_POSITION + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.STOP + | CoverEntityFeature.SET_POSITION + | CoverEntityFeature.OPEN_TILT + | CoverEntityFeature.CLOSE_TILT + | CoverEntityFeature.SET_TILT_POSITION ) def __init__( @@ -231,7 +225,7 @@ class ZWaveTiltCover(ZWaveCover): class ZwaveMotorizedBarrier(ZWaveBaseEntity, CoverEntity): """Representation of a Z-Wave motorized barrier device.""" - _attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE + _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE _attr_device_class = CoverDeviceClass.GARAGE def __init__( diff --git a/homeassistant/components/zwave_js/fan.py b/homeassistant/components/zwave_js/fan.py index 21c45bbbf42..623ee072f3a 100644 --- a/homeassistant/components/zwave_js/fan.py +++ b/homeassistant/components/zwave_js/fan.py @@ -14,9 +14,8 @@ from zwave_js_server.model.value import Value as ZwaveValue from homeassistant.components.fan import ( DOMAIN as FAN_DOMAIN, - SUPPORT_PRESET_MODE, - SUPPORT_SET_SPEED, FanEntity, + FanEntityFeature, NotValidPresetModeError, ) from homeassistant.config_entries import ConfigEntry @@ -74,6 +73,8 @@ async def async_setup_entry( class ZwaveFan(ZWaveBaseEntity, FanEntity): """Representation of a Z-Wave fan.""" + _attr_supported_features = FanEntityFeature.SET_SPEED + def __init__( self, config_entry: ConfigEntry, client: ZwaveClient, info: ZwaveDiscoveryInfo ) -> None: @@ -139,11 +140,6 @@ class ZwaveFan(ZWaveBaseEntity, FanEntity): """Return the number of speeds the fan supports.""" return int_states_in_range(DEFAULT_SPEED_RANGE) - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_SET_SPEED - class ValueMappingZwaveFan(ZwaveFan): """A Zwave fan with a value mapping data (e.g., 1-24 is low).""" @@ -239,9 +235,9 @@ class ValueMappingZwaveFan(ZwaveFan): @property def supported_features(self) -> int: """Flag supported features.""" - flags = SUPPORT_SET_SPEED + flags: int = FanEntityFeature.SET_SPEED if self.has_fan_value_mapping and self.fan_value_mapping.presets: - flags |= SUPPORT_PRESET_MODE + flags |= FanEntityFeature.PRESET_MODE return flags @@ -376,7 +372,7 @@ class ZwaveThermostatFan(ZWaveBaseEntity, FanEntity): @property def supported_features(self) -> int: """Flag supported features.""" - return SUPPORT_PRESET_MODE + return FanEntityFeature.PRESET_MODE @property def fan_state(self) -> str | None: diff --git a/homeassistant/components/zwave_me/climate.py b/homeassistant/components/zwave_me/climate.py index 140c397ecde..cb00da170a4 100644 --- a/homeassistant/components/zwave_me/climate.py +++ b/homeassistant/components/zwave_me/climate.py @@ -3,11 +3,8 @@ from __future__ import annotations from zwave_me_ws import ZWaveMeData -from homeassistant.components.climate import ClimateEntity -from homeassistant.components.climate.const import ( - HVAC_MODE_HEAT, - SUPPORT_TARGET_TEMPERATURE, -) +from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature +from homeassistant.components.climate.const import HVAC_MODE_HEAT from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE from homeassistant.core import HomeAssistant, callback @@ -51,6 +48,8 @@ async def async_setup_entry( class ZWaveMeClimate(ZWaveMeEntity, ClimateEntity): """Representation of a ZWaveMe sensor.""" + _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE + def set_temperature(self, **kwargs) -> None: """Set new target temperature.""" if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: @@ -90,11 +89,6 @@ class ZWaveMeClimate(ZWaveMeEntity, ClimateEntity): """Return the current mode.""" return HVAC_MODE_HEAT - @property - def supported_features(self) -> int: - """Return the supported features.""" - return SUPPORT_TARGET_TEMPERATURE - @property def target_temperature_step(self) -> float: """Return the supported step of target temperature.""" diff --git a/homeassistant/components/zwave_me/cover.py b/homeassistant/components/zwave_me/cover.py index 161033aad7c..63aa7342cbe 100644 --- a/homeassistant/components/zwave_me/cover.py +++ b/homeassistant/components/zwave_me/cover.py @@ -5,10 +5,8 @@ from typing import Any from homeassistant.components.cover import ( ATTR_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, CoverEntity, + CoverEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -49,6 +47,12 @@ async def async_setup_entry( class ZWaveMeCover(ZWaveMeEntity, CoverEntity): """Representation of a ZWaveMe Multilevel Cover.""" + _attr_supported_features = ( + CoverEntityFeature.OPEN + | CoverEntityFeature.CLOSE + | CoverEntityFeature.SET_POSITION + ) + def close_cover(self, **kwargs): """Close cover.""" self.controller.zwave_api.send_command(self.device.id, "exact?level=0") @@ -71,8 +75,3 @@ class ZWaveMeCover(ZWaveMeEntity, CoverEntity): None is unknown, 0 is closed, 100 is fully open. """ return self.device.level - - @property - def supported_features(self) -> int: - """Return the supported features.""" - return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION