Use EntityFeature enum in mqtt (#69416)
This commit is contained in:
parent
4592583988
commit
3e426c0fa6
6 changed files with 32 additions and 53 deletions
|
@ -8,14 +8,7 @@ import re
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
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_CUSTOM_BYPASS,
|
|
||||||
SUPPORT_ALARM_ARM_HOME,
|
|
||||||
SUPPORT_ALARM_ARM_NIGHT,
|
|
||||||
SUPPORT_ALARM_ARM_VACATION,
|
|
||||||
SUPPORT_ALARM_TRIGGER,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_CODE,
|
CONF_CODE,
|
||||||
|
@ -228,12 +221,12 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
return (
|
return (
|
||||||
SUPPORT_ALARM_ARM_HOME
|
AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
| SUPPORT_ALARM_ARM_AWAY
|
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
| SUPPORT_ALARM_ARM_NIGHT
|
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||||
| SUPPORT_ALARM_ARM_VACATION
|
| AlarmControlPanelEntityFeature.ARM_VACATION
|
||||||
| SUPPORT_ALARM_ARM_CUSTOM_BYPASS
|
| AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
||||||
| SUPPORT_ALARM_TRIGGER
|
| AlarmControlPanelEntityFeature.TRIGGER
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant.components import climate
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA,
|
||||||
ClimateEntity,
|
ClimateEntity,
|
||||||
|
ClimateEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
|
@ -30,12 +31,6 @@ from homeassistant.components.climate.const import (
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
SUPPORT_AUX_HEAT,
|
|
||||||
SUPPORT_FAN_MODE,
|
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_SWING_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 (
|
||||||
|
@ -1040,27 +1035,27 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
||||||
if (self._topic[CONF_TEMP_STATE_TOPIC] is not None) or (
|
if (self._topic[CONF_TEMP_STATE_TOPIC] is not None) or (
|
||||||
self._topic[CONF_TEMP_COMMAND_TOPIC] is not None
|
self._topic[CONF_TEMP_COMMAND_TOPIC] is not None
|
||||||
):
|
):
|
||||||
support |= SUPPORT_TARGET_TEMPERATURE
|
support |= ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
|
|
||||||
if (self._topic[CONF_TEMP_LOW_STATE_TOPIC] is not None) or (
|
if (self._topic[CONF_TEMP_LOW_STATE_TOPIC] is not None) or (
|
||||||
self._topic[CONF_TEMP_LOW_COMMAND_TOPIC] is not None
|
self._topic[CONF_TEMP_LOW_COMMAND_TOPIC] is not None
|
||||||
):
|
):
|
||||||
support |= SUPPORT_TARGET_TEMPERATURE_RANGE
|
support |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
|
|
||||||
if (self._topic[CONF_TEMP_HIGH_STATE_TOPIC] is not None) or (
|
if (self._topic[CONF_TEMP_HIGH_STATE_TOPIC] is not None) or (
|
||||||
self._topic[CONF_TEMP_HIGH_COMMAND_TOPIC] is not None
|
self._topic[CONF_TEMP_HIGH_COMMAND_TOPIC] is not None
|
||||||
):
|
):
|
||||||
support |= SUPPORT_TARGET_TEMPERATURE_RANGE
|
support |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
|
|
||||||
if (self._topic[CONF_FAN_MODE_STATE_TOPIC] is not None) or (
|
if (self._topic[CONF_FAN_MODE_STATE_TOPIC] is not None) or (
|
||||||
self._topic[CONF_FAN_MODE_COMMAND_TOPIC] is not None
|
self._topic[CONF_FAN_MODE_COMMAND_TOPIC] is not None
|
||||||
):
|
):
|
||||||
support |= SUPPORT_FAN_MODE
|
support |= ClimateEntityFeature.FAN_MODE
|
||||||
|
|
||||||
if (self._topic[CONF_SWING_MODE_STATE_TOPIC] is not None) or (
|
if (self._topic[CONF_SWING_MODE_STATE_TOPIC] is not None) or (
|
||||||
self._topic[CONF_SWING_MODE_COMMAND_TOPIC] is not None
|
self._topic[CONF_SWING_MODE_COMMAND_TOPIC] is not None
|
||||||
):
|
):
|
||||||
support |= SUPPORT_SWING_MODE
|
support |= ClimateEntityFeature.SWING_MODE
|
||||||
|
|
||||||
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
||||||
if (
|
if (
|
||||||
|
@ -1070,12 +1065,12 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
||||||
or (self._topic[CONF_HOLD_STATE_TOPIC] is not None)
|
or (self._topic[CONF_HOLD_STATE_TOPIC] is not None)
|
||||||
or (self._topic[CONF_HOLD_COMMAND_TOPIC] is not None)
|
or (self._topic[CONF_HOLD_COMMAND_TOPIC] is not None)
|
||||||
):
|
):
|
||||||
support |= SUPPORT_PRESET_MODE
|
support |= ClimateEntityFeature.PRESET_MODE
|
||||||
|
|
||||||
if (self._topic[CONF_AUX_STATE_TOPIC] is not None) or (
|
if (self._topic[CONF_AUX_STATE_TOPIC] is not None) or (
|
||||||
self._topic[CONF_AUX_COMMAND_TOPIC] is not None
|
self._topic[CONF_AUX_COMMAND_TOPIC] is not None
|
||||||
):
|
):
|
||||||
support |= SUPPORT_AUX_HEAT
|
support |= ClimateEntityFeature.AUX_HEAT
|
||||||
|
|
||||||
return support
|
return support
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,8 @@ from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
DEVICE_CLASSES_SCHEMA,
|
DEVICE_CLASSES_SCHEMA,
|
||||||
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.const import (
|
from homeassistant.const import (
|
||||||
|
@ -102,10 +95,10 @@ DEFAULT_TILT_OPEN_POSITION = 100
|
||||||
DEFAULT_TILT_OPTIMISTIC = False
|
DEFAULT_TILT_OPTIMISTIC = False
|
||||||
|
|
||||||
TILT_FEATURES = (
|
TILT_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
|
||||||
)
|
)
|
||||||
|
|
||||||
MQTT_COVER_ATTRIBUTES_BLOCKED = frozenset(
|
MQTT_COVER_ATTRIBUTES_BLOCKED = frozenset(
|
||||||
|
@ -519,14 +512,14 @@ class MqttCover(MqttEntity, CoverEntity):
|
||||||
supported_features = 0
|
supported_features = 0
|
||||||
if self._config.get(CONF_COMMAND_TOPIC) is not None:
|
if self._config.get(CONF_COMMAND_TOPIC) is not None:
|
||||||
if self._config.get(CONF_PAYLOAD_OPEN) is not None:
|
if self._config.get(CONF_PAYLOAD_OPEN) is not None:
|
||||||
supported_features |= SUPPORT_OPEN
|
supported_features |= CoverEntityFeature.OPEN
|
||||||
if self._config.get(CONF_PAYLOAD_CLOSE) is not None:
|
if self._config.get(CONF_PAYLOAD_CLOSE) is not None:
|
||||||
supported_features |= SUPPORT_CLOSE
|
supported_features |= CoverEntityFeature.CLOSE
|
||||||
if self._config.get(CONF_PAYLOAD_STOP) is not None:
|
if self._config.get(CONF_PAYLOAD_STOP) is not None:
|
||||||
supported_features |= SUPPORT_STOP
|
supported_features |= CoverEntityFeature.STOP
|
||||||
|
|
||||||
if self._config.get(CONF_SET_POSITION_TOPIC) is not None:
|
if self._config.get(CONF_SET_POSITION_TOPIC) is not None:
|
||||||
supported_features |= SUPPORT_SET_POSITION
|
supported_features |= CoverEntityFeature.SET_POSITION
|
||||||
|
|
||||||
if self._config.get(CONF_TILT_COMMAND_TOPIC) is not None:
|
if self._config.get(CONF_TILT_COMMAND_TOPIC) is not None:
|
||||||
supported_features |= TILT_FEATURES
|
supported_features |= TILT_FEATURES
|
||||||
|
|
|
@ -12,10 +12,8 @@ from homeassistant.components.fan import (
|
||||||
ATTR_OSCILLATING,
|
ATTR_OSCILLATING,
|
||||||
ATTR_PERCENTAGE,
|
ATTR_PERCENTAGE,
|
||||||
ATTR_PRESET_MODE,
|
ATTR_PRESET_MODE,
|
||||||
SUPPORT_OSCILLATE,
|
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_SET_SPEED,
|
|
||||||
FanEntity,
|
FanEntity,
|
||||||
|
FanEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -326,12 +324,12 @@ class MqttFan(MqttEntity, FanEntity):
|
||||||
self._supported_features = 0
|
self._supported_features = 0
|
||||||
self._supported_features |= (
|
self._supported_features |= (
|
||||||
self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
|
self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
|
||||||
and SUPPORT_OSCILLATE
|
and FanEntityFeature.OSCILLATE
|
||||||
)
|
)
|
||||||
if self._feature_percentage:
|
if self._feature_percentage:
|
||||||
self._supported_features |= SUPPORT_SET_SPEED
|
self._supported_features |= FanEntityFeature.SET_SPEED
|
||||||
if self._feature_preset_mode:
|
if self._feature_preset_mode:
|
||||||
self._supported_features |= SUPPORT_PRESET_MODE
|
self._supported_features |= FanEntityFeature.PRESET_MODE
|
||||||
|
|
||||||
for key, tpl in self._command_templates.items():
|
for key, tpl in self._command_templates.items():
|
||||||
self._command_templates[key] = MqttCommandTemplate(
|
self._command_templates[key] = MqttCommandTemplate(
|
||||||
|
|
|
@ -12,9 +12,9 @@ from homeassistant.components.humidifier import (
|
||||||
ATTR_MODE,
|
ATTR_MODE,
|
||||||
DEFAULT_MAX_HUMIDITY,
|
DEFAULT_MAX_HUMIDITY,
|
||||||
DEFAULT_MIN_HUMIDITY,
|
DEFAULT_MIN_HUMIDITY,
|
||||||
SUPPORT_MODES,
|
|
||||||
HumidifierDeviceClass,
|
HumidifierDeviceClass,
|
||||||
HumidifierEntity,
|
HumidifierEntity,
|
||||||
|
HumidifierEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -250,7 +250,7 @@ class MqttHumidifier(MqttEntity, HumidifierEntity):
|
||||||
else:
|
else:
|
||||||
self._available_modes = []
|
self._available_modes = []
|
||||||
if self._available_modes:
|
if self._available_modes:
|
||||||
self._attr_supported_features = SUPPORT_MODES
|
self._attr_supported_features = HumidifierEntityFeature.MODES
|
||||||
else:
|
else:
|
||||||
self._attr_supported_features = 0
|
self._attr_supported_features = 0
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import functools
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import lock
|
from homeassistant.components import lock
|
||||||
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
|
from homeassistant.components.lock import LockEntity, LockEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_VALUE_TEMPLATE
|
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_VALUE_TEMPLATE
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
@ -176,7 +176,7 @@ class MqttLock(MqttEntity, LockEntity):
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return SUPPORT_OPEN if CONF_PAYLOAD_OPEN in self._config else 0
|
return LockEntityFeature.OPEN if CONF_PAYLOAD_OPEN in self._config else 0
|
||||||
|
|
||||||
async def async_lock(self, **kwargs):
|
async def async_lock(self, **kwargs):
|
||||||
"""Lock the device.
|
"""Lock the device.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue