Skip to content

Commit

Permalink
Use separate constants in slide cover (home-assistant#127852)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST authored Oct 8, 2024
1 parent 646f457 commit bff66db
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions homeassistant/components/slide/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand All @@ -15,6 +15,10 @@

_LOGGER = logging.getLogger(__name__)

CLOSED = "closed"
CLOSING = "closing"
OPENING = "opening"


async def async_setup_platform(
hass: HomeAssistant,
Expand Down Expand Up @@ -55,19 +59,19 @@ def __init__(self, api, slide):
@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:
Expand All @@ -87,12 +91,12 @@ def current_cover_position(self) -> int | None:

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:
Expand All @@ -107,8 +111,8 @@ async def async_set_cover_position(self, **kwargs: Any) -> None:

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)

0 comments on commit bff66db

Please sign in to comment.