1 """Support for Sure PetCare Flaps locks."""
3 from __future__
import annotations
7 from surepy.entities
import SurepyEntity
8 from surepy.enums
import EntityType, LockState
as SurepyLockState
15 from .const
import DOMAIN
16 from .coordinator
import SurePetcareDataCoordinator
17 from .entity
import SurePetcareEntity
21 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
23 """Set up Sure PetCare locks on a config entry."""
25 coordinator: SurePetcareDataCoordinator = hass.data[DOMAIN][entry.entry_id]
29 for surepy_entity
in coordinator.data.values()
30 if surepy_entity.type
in [EntityType.CAT_FLAP, EntityType.PET_FLAP]
32 SurepyLockState.LOCKED_IN,
33 SurepyLockState.LOCKED_OUT,
34 SurepyLockState.LOCKED_ALL,
40 """A lock implementation for Sure Petcare Entities."""
45 coordinator: SurePetcareDataCoordinator,
46 lock_state: SurepyLockState,
48 """Initialize a Sure Petcare lock."""
52 super().
__init__(surepetcare_id, coordinator)
54 self.
_attr_name_attr_name = f
"{self._device_name} {self._lock_state.replace('_', ' ')}"
59 """Return true if entity is available."""
60 return self.
_available_available
and super().available
64 """Update the state."""
65 status = surepy_entity.raw_data()[
"status"]
68 SurepyLockState(status[
"locking"][
"mode"]).name.lower() == self.
_lock_state_lock_state
81 await self.coordinator.lock_states_callbacks[self.
_lock_state_lock_state](self.
_id_id)
88 """Unlock the lock."""
95 await self.coordinator.surepy.sac.unlock(self.
_id_id)
None _update_attr(self, SurepyEntity surepy_entity)
None __init__(self, int surepetcare_id, SurePetcareDataCoordinator coordinator, SurepyLockState lock_state)
None async_lock(self, **Any kwargs)
None async_unlock(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)