Use separate constants in template cover (#127853)

This commit is contained in:
G Johansson 2024-10-08 08:06:44 +02:00 committed by GitHub
parent 00ee2b4478
commit 1613b3c0df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,10 +24,6 @@ from homeassistant.const import (
CONF_OPTIMISTIC, CONF_OPTIMISTIC,
CONF_UNIQUE_ID, CONF_UNIQUE_ID,
CONF_VALUE_TEMPLATE, CONF_VALUE_TEMPLATE,
STATE_CLOSED,
STATE_CLOSING,
STATE_OPEN,
STATE_OPENING,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
@ -45,11 +41,17 @@ from .template_entity import (
) )
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
OPEN_STATE = "open"
OPENING_STATE = "opening"
CLOSED_STATE = "closed"
CLOSING_STATE = "closing"
_VALID_STATES = [ _VALID_STATES = [
STATE_OPEN, OPEN_STATE,
STATE_OPENING, OPENING_STATE,
STATE_CLOSED, CLOSED_STATE,
STATE_CLOSING, CLOSING_STATE,
"true", "true",
"false", "false",
"none", "none",
@ -227,13 +229,13 @@ class CoverTemplate(TemplateEntity, CoverEntity):
if state in _VALID_STATES: if state in _VALID_STATES:
if not self._position_template: if not self._position_template:
if state in ("true", STATE_OPEN): if state in ("true", OPEN_STATE):
self._position = 100 self._position = 100
else: else:
self._position = 0 self._position = 0
self._is_opening = state == STATE_OPENING self._is_opening = state == OPENING_STATE
self._is_closing = state == STATE_CLOSING self._is_closing = state == CLOSING_STATE
else: else:
_LOGGER.error( _LOGGER.error(
"Received invalid cover is_on state: %s for entity %s. Expected: %s", "Received invalid cover is_on state: %s for entity %s. Expected: %s",