hass-reos-integration/custom_components/reos_integration/lock.py

47 lines
1.5 KiB
Python

from __future__ import annotations
from homeassistant.components.lock import LockEntity, LockEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .reos_api import ReosApi, ReosLockModel
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
api: ReosApi = hass.data[DOMAIN][config_entry.data["username"]]
async_add_entities(ReosLock(lock) for lock in await api.get_locks())
class ReosLock(LockEntity):
def __init__(self, model: ReosLockModel) -> None:
self._model = model
self._attr_unique_id = f"reos_lock_{self._model.lock_id}"
self._attr_name = self._model.display
self._attr_is_locked = False
self._attr_device_class = "door"
self._attr_icon = "mdi:door"
@property
def supported_features(self):
"""Flag supported features."""
return LockEntityFeature.OPEN
@property
def device_info(self) -> DeviceInfo | None:
return None
async def async_open(self, **kwargs) -> None:
self.hass.async_create_task(self._model.open())
def unlock(self, **kwargs: cv.Any) -> None:
pass
def lock(self, **kwargs: cv.Any) -> None:
pass