1 """Coordinator for the surepetcare integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from surepy
import Surepy, SurepyEntity
9 from surepy.enums
import EntityType, Location, LockState
10 from surepy.exceptions
import SurePetcareAuthenticationError, SurePetcareError
28 _LOGGER = logging.getLogger(__name__)
34 """Handle Surepetcare data."""
36 def __init__(self, entry: ConfigEntry, hass: HomeAssistant) ->
None:
37 """Initialize the data handler."""
39 entry.data[CONF_USERNAME],
40 entry.data[CONF_PASSWORD],
41 auth_token=entry.data[CONF_TOKEN],
42 api_timeout=SURE_API_TIMEOUT,
46 LockState.UNLOCKED.name.lower(): self.
surepysurepy.sac.unlock,
47 LockState.LOCKED_IN.name.lower(): self.
surepysurepy.sac.lock_in,
48 LockState.LOCKED_OUT.name.lower(): self.
surepysurepy.sac.lock_out,
49 LockState.LOCKED_ALL.name.lower(): self.
surepysurepy.sac.lock,
55 update_interval=SCAN_INTERVAL,
59 """Get the latest data from Sure Petcare."""
62 except SurePetcareAuthenticationError
as err:
64 except SurePetcareError
as err:
65 raise UpdateFailed(f
"Unable to fetch data: {err}")
from err
68 """Call when setting the lock state."""
69 flap_id = call.data[ATTR_FLAP_ID]
70 state = call.data[ATTR_LOCK_STATE]
77 for surepy_entity
in self.
datadata.values():
78 if surepy_entity.type == EntityType.PET
and surepy_entity.name:
79 pets[surepy_entity.name] = surepy_entity.id
83 """Call when setting the pet location."""
84 pet_name = call.data[ATTR_PET_NAME]
85 location = call.data[ATTR_LOCATION]
86 device_id = self.
get_petsget_pets()[pet_name]
87 await self.
surepysurepy.sac.set_pet_location(device_id, Location[location.upper()])
None handle_set_lock_state(self, ServiceCall call)
dict[int, SurepyEntity] _async_update_data(self)
dict[str, int] get_pets(self)
None handle_set_pet_location(self, ServiceCall call)
None __init__(self, ConfigEntry entry, HomeAssistant hass)
None async_request_refresh(self)
list[BaseAprilaireSensor] get_entities(type[BaseAprilaireSensor] entity_class, AprilaireCoordinator coordinator, str unique_id, tuple[AprilaireSensorDescription,...] descriptions)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)