Use separate constants in slide cover (#127852)

pull/127915/head
G Johansson 2024-10-08 09:03:43 +02:00 committed by GitHub
parent 646f457637
commit bff66dbbd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import logging
from typing import Any
from homeassistant.components.cover import ATTR_POSITION, CoverDeviceClass, CoverEntity
from homeassistant.const import ATTR_ID, STATE_CLOSED, STATE_CLOSING, STATE_OPENING
from homeassistant.const import ATTR_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -15,6 +15,10 @@ from .const import API, DEFAULT_OFFSET, DOMAIN, SLIDES
_LOGGER = logging.getLogger(__name__)
CLOSED = "closed"
CLOSING = "closing"
OPENING = "opening"
async def async_setup_platform(
hass: HomeAssistant,
@ -55,19 +59,19 @@ class SlideCover(CoverEntity):
@property
def is_opening(self) -> bool:
"""Return if the cover is opening or not."""
return self._slide["state"] == STATE_OPENING
return self._slide["state"] == OPENING
@property
def is_closing(self) -> bool:
"""Return if the cover is closing or not."""
return self._slide["state"] == STATE_CLOSING
return self._slide["state"] == CLOSING
@property
def is_closed(self) -> bool | None:
"""Return None if status is unknown, True if closed, else False."""
if self._slide["state"] is None:
return None
return self._slide["state"] == STATE_CLOSED
return self._slide["state"] == CLOSED
@property
def available(self) -> bool:
@ -87,12 +91,12 @@ class SlideCover(CoverEntity):
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
self._slide["state"] = STATE_OPENING
self._slide["state"] = OPENING
await self._api.slide_open(self._id)
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
self._slide["state"] = STATE_CLOSING
self._slide["state"] = CLOSING
await self._api.slide_close(self._id)
async def async_stop_cover(self, **kwargs: Any) -> None:
@ -107,8 +111,8 @@ class SlideCover(CoverEntity):
if self._slide["pos"] is not None:
if position > self._slide["pos"]:
self._slide["state"] = STATE_CLOSING
self._slide["state"] = CLOSING
else:
self._slide["state"] = STATE_OPENING
self._slide["state"] = OPENING
await self._api.slide_set_position(self._id, position)