replace lock with button
This commit is contained in:
parent
d709e78a0e
commit
957c33251d
|
@ -39,5 +39,5 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
hass.data[DOMAIN][username] = api
|
||||
|
||||
await hass.config_entries.async_forward_entry_setup(entry, "lock")
|
||||
await hass.config_entries.async_forward_entry_setup(entry, "button")
|
||||
return True
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.lock import LockEntity, LockEntityFeature
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -14,33 +14,20 @@ 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())
|
||||
async_add_entities(ReosDoorButton(lock) for lock in await api.get_locks())
|
||||
|
||||
class ReosLock(LockEntity):
|
||||
class ReosDoorButton(ButtonEntity):
|
||||
|
||||
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
|
||||
def press(self, **kwargs) -> None:
|
||||
self.hass.create_task(self._model.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
|
||||
|
Loading…
Reference in New Issue