Use separate constants in template cover (#127853)

pull/127906/head
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
1 changed files with 13 additions and 11 deletions

View File

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