1 """Support for the KIWI.KI lock platform."""
3 from __future__
import annotations
8 from kiwiki
import KiwiClient, KiwiException
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as LOCK_PLATFORM_SCHEMA,
29 _LOGGER = logging.getLogger(__name__)
31 ATTR_TYPE =
"hardware_type"
32 ATTR_PERMISSION =
"permission"
33 ATTR_CAN_INVITE =
"can_invite_others"
35 UNLOCK_MAINTAIN_TIME = 5
37 PLATFORM_SCHEMA = LOCK_PLATFORM_SCHEMA.extend(
38 {vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string}
45 add_entities: AddEntitiesCallback,
46 discovery_info: DiscoveryInfoType |
None =
None,
48 """Set up the KIWI lock platform."""
51 kiwi = KiwiClient(config[CONF_USERNAME], config[CONF_PASSWORD])
52 except KiwiException
as exc:
55 if not (available_locks := kiwi.get_locks()):
57 _LOGGER.debug(
"No KIWI locks found in your account")
63 """Representation of a Kiwi lock."""
66 """Initialize the lock."""
69 self.
lock_idlock_id = kiwi_lock[
"sensor_id"]
72 address = kiwi_lock.get(
"address")
75 ATTR_LATITUDE: address.pop(
"lat",
None),
76 ATTR_LONGITUDE: address.pop(
"lng",
None),
82 ATTR_TYPE: kiwi_lock.get(
"hardware_type"),
83 ATTR_PERMISSION: kiwi_lock.get(
"highest_permission"),
84 ATTR_CAN_INVITE: kiwi_lock.get(
"can_invite"),
89 def name(self) -> str | None:
90 """Return the name of the lock."""
92 specifier = self.
_sensor_sensor[
"address"].
get(
"specifier")
93 return name
or specifier
97 """Return true if lock is locked."""
98 return self.
_state_state == LockState.LOCKED
102 """Return the device specific state attributes."""
107 """Clear unlock state automatically."""
108 self.
_state_state = LockState.LOCKED
112 """Unlock the device."""
116 except KiwiException:
117 _LOGGER.error(
"Failed to open door")
119 self.
_state_state = LockState.UNLOCKED
120 self.
hasshass.add_job(
123 UNLOCK_MAINTAIN_TIME,
def __init__(self, kiwi_lock, client)
def clear_unlock_state(self, _)
dict[str, Any] extra_state_attributes(self)
None unlock(self, **Any kwargs)
None async_write_ha_state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
web.Response get(self, web.Request request, str config_key)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)