Use shorthanded attributes for MQTT cover (#100230)

pull/100241/head
Jan Bouwhuis 2023-09-12 20:46:43 +02:00 committed by GitHub
parent 51576b7214
commit 5fcb69e004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 26 deletions

View File

@ -13,7 +13,6 @@ from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DEVICE_CLASSES_SCHEMA,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
)
@ -335,6 +334,25 @@ class MqttCover(MqttEntity, CoverEntity):
config_attributes=template_config_attributes,
).async_render_with_possible_json_value
self._attr_device_class = self._config.get(CONF_DEVICE_CLASS)
supported_features = CoverEntityFeature(0)
if self._config.get(CONF_COMMAND_TOPIC) is not None:
if self._config.get(CONF_PAYLOAD_OPEN) is not None:
supported_features |= CoverEntityFeature.OPEN
if self._config.get(CONF_PAYLOAD_CLOSE) is not None:
supported_features |= CoverEntityFeature.CLOSE
if self._config.get(CONF_PAYLOAD_STOP) is not None:
supported_features |= CoverEntityFeature.STOP
if self._config.get(CONF_SET_POSITION_TOPIC) is not None:
supported_features |= CoverEntityFeature.SET_POSITION
if self._config.get(CONF_TILT_COMMAND_TOPIC) is not None:
supported_features |= TILT_FEATURES
self._attr_supported_features = supported_features
def _prepare_subscribe_topics(self) -> None:
"""(Re)Subscribe to topics."""
topics = {}
@ -506,31 +524,6 @@ class MqttCover(MqttEntity, CoverEntity):
"""Return current position of cover tilt."""
return self._tilt_value
@property
def device_class(self) -> CoverDeviceClass | None:
"""Return the class of this sensor."""
return self._config.get(CONF_DEVICE_CLASS)
@property
def supported_features(self) -> CoverEntityFeature:
"""Flag supported features."""
supported_features = CoverEntityFeature(0)
if self._config.get(CONF_COMMAND_TOPIC) is not None:
if self._config.get(CONF_PAYLOAD_OPEN) is not None:
supported_features |= CoverEntityFeature.OPEN
if self._config.get(CONF_PAYLOAD_CLOSE) is not None:
supported_features |= CoverEntityFeature.CLOSE
if self._config.get(CONF_PAYLOAD_STOP) is not None:
supported_features |= CoverEntityFeature.STOP
if self._config.get(CONF_SET_POSITION_TOPIC) is not None:
supported_features |= CoverEntityFeature.SET_POSITION
if self._config.get(CONF_TILT_COMMAND_TOPIC) is not None:
supported_features |= TILT_FEATURES
return supported_features
async def async_open_cover(self, **kwargs: Any) -> None:
"""Move the cover up.