Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/huckleberry_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
DiaperAmount = Literal["little", "medium", "big"]
PooColor = Literal["yellow", "brown", "black", "green", "red", "gray"]
PooConsistency = Literal["solid", "loose", "runny", "mucousy", "hard", "pebbles", "diarrhea"]
PottyHowItHappened = Literal["wentPotty", "accident", "satButDry"]
MeasurementUnits = Literal["metric", "imperial"]

# Union type for all document data types used in listeners
Expand Down Expand Up @@ -1078,7 +1079,8 @@ def stop_all_listeners(self) -> None:
def log_diaper(self, child_uid: str, mode: DiaperMode,
pee_amount: DiaperAmount | None = None, poo_amount: DiaperAmount | None = None,
color: PooColor | None = None, consistency: PooConsistency | None = None,
diaper_rash: bool = False, notes: str | None = None) -> None:
diaper_rash: bool = False, is_potty: bool = False,
how_it_happened: PottyHowItHappened | None = None, notes: str | None = None) -> None:
"""
Log a diaper change.

Expand All @@ -1090,6 +1092,8 @@ def log_diaper(self, child_uid: str, mode: DiaperMode,
color: Poo color - 'yellow', 'brown', 'black', 'green', 'red', 'gray'
consistency: Poo consistency - 'solid', 'loose', 'runny', 'mucousy', 'hard', 'pebbles', 'diarrhea'
diaper_rash: Whether baby has diaper rash
is_potty: Whether to log as potty or diaper
how_it_happened: How potty happened: "wentPotty", "accident", "satButDry"
notes: Optional notes about this diaper change
"""
_LOGGER.info("Logging diaper change for child %s: mode=%s", child_uid, mode)
Expand Down Expand Up @@ -1130,6 +1134,12 @@ def log_diaper(self, child_uid: str, mode: DiaperMode,
interval_data["consistency"] = consistency
if diaper_rash:
interval_data["diaperRash"] = True # type: ignore # Not in TypedDict yet
if is_potty:
interval_data["isPotty"] = True # type: ignore # Not in TypedDict yet
if how_it_happened is None:
interval_data["howItHappened"] = "wentPotty" # type: ignore # Not in TypedDict yet
if how_it_happened:
interval_data["howItHappened"] = how_it_happened
if notes:
interval_data["notes"] = notes # type: ignore # Not in TypedDict yet

Expand Down Expand Up @@ -1587,7 +1597,8 @@ def get_diaper_intervals(
end_timestamp: End of range (Unix timestamp in seconds)

Returns:
List of diaper interval dicts with 'start', 'mode', and optional details
List of diaper interval dicts with 'start', 'mode', optional details,
and 'isPotty' flag.
"""
events = []
client = self._get_firestore_client()
Expand All @@ -1610,6 +1621,7 @@ def get_diaper_intervals(
event = {
"start": data["start"],
"mode": data.get("mode", "unknown"),
"isPotty": data.get("isPotty", False),
}
# Add optional fields if present
if "pooColor" in data:
Expand Down Expand Up @@ -1642,6 +1654,7 @@ def get_diaper_intervals(
event = {
"start": entry_start,
"mode": entry.get("mode", "unknown"),
"isPotty": entry.get("isPotty", False),
}
# Add optional fields if present
if "pooColor" in entry:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_diaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ def test_log_diaper_dry(self, api: HuckleberryAPI, child_uid: str) -> None:
data = diaper_doc.to_dict()
assert data is not None
assert data["prefs"]["lastDiaper"]["mode"] == "dry"

def test_log_potty_pee(self, api: HuckleberryAPI, child_uid: str) -> None:
"""Test logging potty event with default how_it_happened."""
api.log_diaper(child_uid, mode="pee", pee_amount="little", is_potty=True)
time.sleep(1)

diaper_doc = api._get_firestore_client().collection("diaper").document(child_uid).get()
data = diaper_doc.to_dict()

assert data is not None
assert data["prefs"]["lastPotty"]["mode"] == "pee"