1 """The surepetcare integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from surepy.enums
import Location
9 from surepy.exceptions
import SurePetcareAuthenticationError, SurePetcareError
10 import voluptuous
as vol
24 SERVICE_SET_LOCK_STATE,
25 SERVICE_SET_PET_LOCATION,
27 from .coordinator
import SurePetcareDataCoordinator
29 _LOGGER = logging.getLogger(__name__)
31 PLATFORMS = [Platform.BINARY_SENSOR, Platform.LOCK, Platform.SENSOR]
36 """Set up Sure Petcare from a config entry."""
37 hass.data.setdefault(DOMAIN, {})
44 except SurePetcareAuthenticationError
as error:
45 _LOGGER.error(
"Unable to connect to surepetcare.io: Wrong credentials!")
46 raise ConfigEntryAuthFailed
from error
47 except SurePetcareError
as error:
48 raise ConfigEntryNotReady
from error
50 await coordinator.async_config_entry_first_refresh()
52 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
54 lock_state_service_schema = vol.Schema(
56 vol.Required(ATTR_FLAP_ID): vol.All(
57 cv.positive_int, vol.In(coordinator.data.keys())
59 vol.Required(ATTR_LOCK_STATE): vol.All(
62 vol.In(coordinator.lock_states_callbacks.keys()),
66 hass.services.async_register(
68 SERVICE_SET_LOCK_STATE,
69 coordinator.handle_set_lock_state,
70 schema=lock_state_service_schema,
73 set_pet_location_schema = vol.Schema(
75 vol.Required(ATTR_PET_NAME): vol.In(coordinator.get_pets().keys()),
76 vol.Required(ATTR_LOCATION): vol.In(
78 Location.INSIDE.name.title(),
79 Location.OUTSIDE.name.title(),
84 hass.services.async_register(
86 SERVICE_SET_PET_LOCATION,
87 coordinator.handle_set_pet_location,
88 schema=set_pet_location_schema,
95 """Unload a config entry."""
96 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
98 hass.data[DOMAIN].pop(entry.entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)