Beispiel #1
0
 def activity(self) -> PetActivity:
     """Last Activity of the Pet."""
     activity = self._data.get("status", {}).get("activity", {})
     return PetActivity(
         where=Location(activity.get("where", Location.UNKNOWN.value)),
         since=activity.get("since", None),
     )
Beispiel #2
0
 def location(self) -> PetLocation:
     """Location of the Pet."""
     position = self._data.get("position", {})
     return PetLocation(
         where=Location(position.get("where", Location.UNKNOWN.value)),
         since=position.get("since", None),
     )
 def _update_attr(self, surepy_entity: SurepyEntity) -> None:
     """Get the latest data and update the state."""
     surepy_entity = cast(SurepyPet, surepy_entity)
     state = surepy_entity.location
     try:
         self._attr_is_on = bool(Location(state.where) == Location.INSIDE)
     except (KeyError, TypeError):
         self._attr_is_on = False
     if state:
         self._attr_extra_state_attributes = {
             "since": state.since,
             "where": state.where,
         }
     else:
         self._attr_extra_state_attributes = {}
Beispiel #4
0
 def _async_update(self) -> None:
     """Get the latest data and update the state."""
     surepy_entity = self._spc.states[self._id]
     state = surepy_entity.location
     try:
         self._attr_is_on = bool(Location(state.where) == Location.INSIDE)
     except (KeyError, TypeError):
         self._attr_is_on = False
     if state:
         self._attr_extra_state_attributes = {
             "since": state.since,
             "where": state.where,
         }
     else:
         self._attr_extra_state_attributes = None
     _LOGGER.debug("%s -> state: %s", self._name, state)
     self.async_write_ha_state()
Beispiel #5
0
 def is_on(self) -> bool:
     """Return true if entity is at home."""
     try:
         return bool(Location(self._state.where) == Location.INSIDE)
     except (KeyError, TypeError):
         return False
Beispiel #6
0
 def __init__(self, state: dict[str, Any]):
     self.device_id = state.get("device_id")
     self.tag_id = state.get("tag_id")
     self.since: datetime = (datetime.fromisoformat(
         state["at"]) if isinstance(state.get("at", None), str) else None)
     self.where: Location = Location(state["where"])