mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use shorthanded attributes for MQTT cover (#100230)
This commit is contained in:
parent
51576b7214
commit
5fcb69e004
@ -13,7 +13,6 @@ from homeassistant.components.cover import (
|
|||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
DEVICE_CLASSES_SCHEMA,
|
DEVICE_CLASSES_SCHEMA,
|
||||||
CoverDeviceClass,
|
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
@ -335,6 +334,25 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||||||
config_attributes=template_config_attributes,
|
config_attributes=template_config_attributes,
|
||||||
).async_render_with_possible_json_value
|
).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:
|
def _prepare_subscribe_topics(self) -> None:
|
||||||
"""(Re)Subscribe to topics."""
|
"""(Re)Subscribe to topics."""
|
||||||
topics = {}
|
topics = {}
|
||||||
@ -506,31 +524,6 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||||||
"""Return current position of cover tilt."""
|
"""Return current position of cover tilt."""
|
||||||
return self._tilt_value
|
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:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Move the cover up.
|
"""Move the cover up.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user