Skip to content

Commit 5da02a2

Browse files
feat(#170): add calibrate weight button and weight calibration error sensor for DockstreamSmartFountain (#254)
Co-authored-by: Jamie Jones <29973406+jjjonesjr33@users.noreply.github.com>
1 parent 4505b90 commit 5da02a2

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

custom_components/petlibro/binary_sensor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,14 @@ def extra_state_attributes(self):
629629
should_report=lambda device: device.light_switch is not None,
630630
name="Indicator"
631631
),
632+
PetLibroBinarySensorEntityDescription[DockstreamSmartFountain](
633+
key="weight_calibration_error",
634+
translation_key="weight_calibration_error",
635+
icon="mdi:alert",
636+
device_class=BinarySensorDeviceClass.PROBLEM,
637+
should_report=lambda device: device.weight_calibration_error is not None,
638+
name="Weight Calibration Error"
639+
),
632640
],
633641
DockstreamSmartRFIDFountain: [
634642
PetLibroBinarySensorEntityDescription[DockstreamSmartRFIDFountain](

custom_components/petlibro/button.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,14 @@ class PetLibroButtonEntityDescription(ButtonEntityDescription, PetLibroEntityDes
657657
translation_key="filter_reset",
658658
set_fn=lambda device: device.set_filter_reset(),
659659
name="Filter Reset"
660-
)
660+
),
661+
PetLibroButtonEntityDescription[DockstreamSmartFountain](
662+
key="calibrate_weight",
663+
translation_key="calibrate_weight",
664+
icon="mdi:scale",
665+
set_fn=lambda device: device.calibrate_weight(),
666+
name="Calibrate Weight Sensor"
667+
),
661668
],
662669
DockstreamSmartRFIDFountain: [
663670
PetLibroButtonEntityDescription[DockstreamSmartRFIDFountain](

custom_components/petlibro/devices/fountains/dockstream_smart_fountain.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ..device import Device
77
from typing import cast
88
from logging import getLogger
9-
109
_LOGGER = getLogger(__name__)
1110

1211
class DockstreamSmartFountain(Device):
@@ -356,3 +355,19 @@ def update_progress(self) -> float:
356355

357356
progress = upgrade_data.get("progress")
358357
return float(progress) if progress is not None else 0.0
358+
359+
@property
360+
def weight_calibration_error(self) -> bool | None:
361+
exception = self._data.get("dataRealInfo", {}).get("exceptionMessage")
362+
if exception is None:
363+
return None
364+
return "calibration" in exception.lower() or "weight" in exception.lower()
365+
366+
async def calibrate_weight(self) -> None:
367+
_LOGGER.debug(f"Calibrating weight sensor for {self.serial}")
368+
try:
369+
await self.api.exec_device_command(self.serial, "CALIBRATE")
370+
await self.refresh()
371+
except (aiohttp.ClientError, PetLibroAPIError) as err:
372+
_LOGGER.error(f"Failed to calibrate weight sensor for {self.serial}: {err}")
373+
raise PetLibroAPIError(f"Error calibrating weight sensor: {err}")

0 commit comments

Comments
 (0)