1 """Support for Sure PetCare Flaps/Pets binary sensors."""
3 from __future__
import annotations
5 from typing
import cast
7 from surepy.entities
import SurepyEntity
8 from surepy.entities.pet
import Pet
as SurepyPet
9 from surepy.enums
import EntityType, Location
12 BinarySensorDeviceClass,
20 from .const
import DOMAIN
21 from .coordinator
import SurePetcareDataCoordinator
22 from .entity
import SurePetcareEntity
26 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
28 """Set up Sure PetCare Flaps binary sensors based on a config entry."""
30 entities: list[SurePetcareBinarySensor] = []
32 coordinator: SurePetcareDataCoordinator = hass.data[DOMAIN][entry.entry_id]
34 for surepy_entity
in coordinator.data.values():
36 if surepy_entity.type
in [
43 elif surepy_entity.type == EntityType.PET:
44 entities.append(
Pet(surepy_entity.id, coordinator))
45 elif surepy_entity.type == EntityType.HUB:
46 entities.append(
Hub(surepy_entity.id, coordinator))
52 """A binary sensor implementation for Sure Petcare Entities."""
57 coordinator: SurePetcareDataCoordinator,
59 """Initialize a Sure Petcare binary sensor."""
60 super().
__init__(surepetcare_id, coordinator)
67 """Sure Petcare Hub."""
69 _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
70 _attr_entity_category = EntityCategory.DIAGNOSTIC
74 """Return True if entity is available."""
79 """Get the latest data and update the state."""
80 state = surepy_entity.raw_data()[
"status"]
82 if surepy_entity.raw_data():
84 "led_mode":
int(surepy_entity.raw_data()[
"status"][
"led_mode"]),
86 surepy_entity.raw_data()[
"status"][
"pairing_mode"]
94 """Sure Petcare Pet."""
96 _attr_device_class = BinarySensorDeviceClass.PRESENCE
100 """Get the latest data and update the state."""
101 surepy_entity = cast(SurepyPet, surepy_entity)
102 state = surepy_entity.location
105 except (KeyError, TypeError):
109 "since": state.since,
110 "where": state.where,
117 """Sure Petcare Device."""
119 _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
120 _attr_entity_category = EntityCategory.DIAGNOSTIC
125 coordinator: SurePetcareDataCoordinator,
127 """Initialize a Sure Petcare Device."""
128 super().
__init__(surepetcare_id, coordinator)
134 state = surepy_entity.raw_data()[
"status"]
138 "device_rssi": f
'{state["signal"]["device_rssi"]:.2f}',
139 "hub_rssi": f
'{state["signal"]["hub_rssi"]:.2f}',
None __init__(self, int surepetcare_id, SurePetcareDataCoordinator coordinator)
_attr_extra_state_attributes
None _update_attr(self, SurepyEntity surepy_entity)
_attr_extra_state_attributes
None _update_attr(self, SurepyEntity surepy_entity)
_attr_extra_state_attributes
None _update_attr(self, SurepyEntity surepy_entity)
None __init__(self, int surepetcare_id, SurePetcareDataCoordinator coordinator)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)