Skip to content

Commit

Permalink
🐛 fix litterstats data in pet container
Browse files Browse the repository at this point in the history
  • Loading branch information
Jezza34000 committed Feb 23, 2025
1 parent 2e7976a commit fd7ade2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion pypetkitapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ async def populate_pet_stats(self, stats_data: Litter) -> None:
"""Collect data from litter data to populate pet stats.
:param stats_data: Litter data.
"""

if not stats_data.device_nfo:
_LOGGER.warning(
"No device info for %s can't populate pet infos", stats_data
Expand All @@ -517,13 +516,26 @@ async def populate_pet_stats(self, stats_data: Litter) -> None:
stats_data.device_nfo.device_type in [T3, T4]
and stats_data.device_records
):
await self.init_pet_stats(pet)
await self._process_litter_no_camera(pet, stats_data)
elif (
stats_data.device_nfo.device_type in [T5, T6]
and stats_data.device_pet_graph_out
):
await self.init_pet_stats(pet)
await self._process_litter_camera(pet, stats_data)

@staticmethod
async def init_pet_stats(pet: Pet) -> None:
"""Initialize pet stats.
Allow pet stats to be displayed in HA even if no data is available.
:param pet: Pet data.
"""
pet.last_litter_usage = 0
pet.last_device_used = "Unknown"
pet.last_duration_usage = 0
pet.last_measured_weight = 0

async def _process_litter_no_camera(self, pet: Pet, device_records: Litter) -> None:
"""Process litter T3/T4 records (litter without camera).
:param pet: Pet data.
Expand Down
6 changes: 3 additions & 3 deletions pypetkitapi/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ class Pet(BaseModel):
device_nfo: Device | None = None # Device is now optional

# Litter stats
last_litter_usage: int = 0
last_litter_usage: int | None = None
last_device_used: str | None = None
last_duration_usage: int = 0
last_measured_weight: int = 0
last_duration_usage: int | None = None
last_measured_weight: int | None = None

def __init__(self, **data):
"""Initialize the Pet dataclass.
Expand Down

0 comments on commit fd7ade2

Please sign in to comment.