diff --git a/homeassistant/components/mqtt/cover.py b/homeassistant/components/mqtt/cover.py index c11cf2dfb85..ae22eb675ac 100644 --- a/homeassistant/components/mqtt/cover.py +++ b/homeassistant/components/mqtt/cover.py @@ -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.