mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 13:17:53 +00:00
Use separate constants in slide cover (#127852)
This commit is contained in:
parent
646f457637
commit
bff66dbbd3
@ -6,7 +6,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.cover import ATTR_POSITION, CoverDeviceClass, CoverEntity
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
@ -15,6 +15,10 @@ from .const import API, DEFAULT_OFFSET, DOMAIN, SLIDES
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CLOSED = "closed"
|
||||||
|
CLOSING = "closing"
|
||||||
|
OPENING = "opening"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -55,19 +59,19 @@ class SlideCover(CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def is_opening(self) -> bool:
|
def is_opening(self) -> bool:
|
||||||
"""Return if the cover is opening or not."""
|
"""Return if the cover is opening or not."""
|
||||||
return self._slide["state"] == STATE_OPENING
|
return self._slide["state"] == OPENING
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closing(self) -> bool:
|
def is_closing(self) -> bool:
|
||||||
"""Return if the cover is closing or not."""
|
"""Return if the cover is closing or not."""
|
||||||
return self._slide["state"] == STATE_CLOSING
|
return self._slide["state"] == CLOSING
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self) -> bool | None:
|
def is_closed(self) -> bool | None:
|
||||||
"""Return None if status is unknown, True if closed, else False."""
|
"""Return None if status is unknown, True if closed, else False."""
|
||||||
if self._slide["state"] is None:
|
if self._slide["state"] is None:
|
||||||
return None
|
return None
|
||||||
return self._slide["state"] == STATE_CLOSED
|
return self._slide["state"] == CLOSED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@ -87,12 +91,12 @@ class SlideCover(CoverEntity):
|
|||||||
|
|
||||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
self._slide["state"] = STATE_OPENING
|
self._slide["state"] = OPENING
|
||||||
await self._api.slide_open(self._id)
|
await self._api.slide_open(self._id)
|
||||||
|
|
||||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
"""Close the cover."""
|
"""Close the cover."""
|
||||||
self._slide["state"] = STATE_CLOSING
|
self._slide["state"] = CLOSING
|
||||||
await self._api.slide_close(self._id)
|
await self._api.slide_close(self._id)
|
||||||
|
|
||||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||||
@ -107,8 +111,8 @@ class SlideCover(CoverEntity):
|
|||||||
|
|
||||||
if self._slide["pos"] is not None:
|
if self._slide["pos"] is not None:
|
||||||
if position > self._slide["pos"]:
|
if position > self._slide["pos"]:
|
||||||
self._slide["state"] = STATE_CLOSING
|
self._slide["state"] = CLOSING
|
||||||
else:
|
else:
|
||||||
self._slide["state"] = STATE_OPENING
|
self._slide["state"] = OPENING
|
||||||
|
|
||||||
await self._api.slide_set_position(self._id, position)
|
await self._api.slide_set_position(self._id, position)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user