Use shorthand attrs in template integration (#100301)

This commit is contained in:
Jan Bouwhuis 2023-09-13 19:30:43 +02:00 committed by GitHub
parent d17957ac1a
commit 0d33cba823
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 87 deletions

View file

@ -12,7 +12,6 @@ from homeassistant.components.cover import (
DEVICE_CLASSES_SCHEMA,
ENTITY_ID_FORMAT,
PLATFORM_SCHEMA,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
)
@ -155,7 +154,7 @@ class CoverTemplate(TemplateEntity, CoverEntity):
self._template = config.get(CONF_VALUE_TEMPLATE)
self._position_template = config.get(CONF_POSITION_TEMPLATE)
self._tilt_template = config.get(CONF_TILT_TEMPLATE)
self._device_class: CoverDeviceClass | None = config.get(CONF_DEVICE_CLASS)
self._attr_device_class = config.get(CONF_DEVICE_CLASS)
self._open_script = None
if (open_action := config.get(OPEN_ACTION)) is not None:
self._open_script = Script(hass, open_action, friendly_name, DOMAIN)
@ -182,6 +181,15 @@ class CoverTemplate(TemplateEntity, CoverEntity):
self._is_closing = False
self._tilt_value = None
supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
if self._stop_script is not None:
supported_features |= CoverEntityFeature.STOP
if self._position_script is not None:
supported_features |= CoverEntityFeature.SET_POSITION
if self._tilt_script is not None:
supported_features |= TILT_FEATURES
self._attr_supported_features = supported_features
@callback
def _async_setup_templates(self) -> None:
"""Set up templates."""
@ -318,27 +326,6 @@ class CoverTemplate(TemplateEntity, CoverEntity):
"""
return self._tilt_value
@property
def device_class(self) -> CoverDeviceClass | None:
"""Return the device class of the cover."""
return self._device_class
@property
def supported_features(self) -> CoverEntityFeature:
"""Flag supported features."""
supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
if self._stop_script is not None:
supported_features |= CoverEntityFeature.STOP
if self._position_script is not None:
supported_features |= CoverEntityFeature.SET_POSITION
if self._tilt_script is not None:
supported_features |= TILT_FEATURES
return supported_features
async def async_open_cover(self, **kwargs: Any) -> None:
"""Move the cover up."""
if self._open_script: