From b6eb3af1bdeea2198f1b222be1c1b98793d71bbb Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 6 Mar 2026 11:46:18 +0100 Subject: [PATCH 1/3] feat: add potty (part of diaper) --- src/huckleberry_api/api.py | 15 +++++++++++++-- tests/test_diaper.py | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/huckleberry_api/api.py b/src/huckleberry_api/api.py index 5d49ae4..73b1bfe 100644 --- a/src/huckleberry_api/api.py +++ b/src/huckleberry_api/api.py @@ -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 @@ -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. @@ -1090,6 +1092,7 @@ 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 notes: Optional notes about this diaper change """ _LOGGER.info("Logging diaper change for child %s: mode=%s", child_uid, mode) @@ -1130,6 +1133,11 @@ 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: + how_it_happened = "wentPotty" + interval_data["howItHappened"] = how_it_happened # type: ignore # Not in TypedDict yet if notes: interval_data["notes"] = notes # type: ignore # Not in TypedDict yet @@ -1587,7 +1595,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() @@ -1610,6 +1619,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: @@ -1642,6 +1652,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: diff --git a/tests/test_diaper.py b/tests/test_diaper.py index a462781..2b2f4a6 100644 --- a/tests/test_diaper.py +++ b/tests/test_diaper.py @@ -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" \ No newline at end of file From 570c5f971ef124ad4efc893052e0dd1395fb746c Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 6 Mar 2026 15:41:48 +0100 Subject: [PATCH 2/3] fix: added docstring --- src/huckleberry_api/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/huckleberry_api/api.py b/src/huckleberry_api/api.py index 73b1bfe..0b2213b 100644 --- a/src/huckleberry_api/api.py +++ b/src/huckleberry_api/api.py @@ -1093,6 +1093,7 @@ def log_diaper(self, child_uid: str, mode: DiaperMode, 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) From 6b113c9135e9d5dffdf6d9ca9dea03021b6efed5 Mon Sep 17 00:00:00 2001 From: tom Date: Tue, 24 Mar 2026 13:56:05 +0100 Subject: [PATCH 3/3] fix: added support for howItHappened --- src/huckleberry_api/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/huckleberry_api/api.py b/src/huckleberry_api/api.py index 0b2213b..a0367ab 100644 --- a/src/huckleberry_api/api.py +++ b/src/huckleberry_api/api.py @@ -1137,8 +1137,9 @@ def log_diaper(self, child_uid: str, mode: DiaperMode, if is_potty: interval_data["isPotty"] = True # type: ignore # Not in TypedDict yet if how_it_happened is None: - how_it_happened = "wentPotty" - interval_data["howItHappened"] = how_it_happened # type: ignore # Not in TypedDict yet + 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