コード例 #1
0
ファイル: pet.py プロジェクト: paxcodes/surepy
 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),
     )
コード例 #2
0
ファイル: pet.py プロジェクト: paxcodes/surepy
 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),
     )
コード例 #3
0
 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 = {}
コード例 #4
0
ファイル: binary_sensor.py プロジェクト: MatthiasLohr/core
 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()
コード例 #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
コード例 #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"])