Use shorthand attrs in template integration (#100301)
This commit is contained in:
parent
d17957ac1a
commit
0d33cba823
8 changed files with 42 additions and 87 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue