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
8 changes: 8 additions & 0 deletions custom_components/petlibro/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,14 @@ def extra_state_attributes(self):
should_report=lambda device: device.light_switch is not None,
name="Indicator"
),
PetLibroBinarySensorEntityDescription[DockstreamSmartFountain](
key="weight_calibration_error",
translation_key="weight_calibration_error",
icon="mdi:alert",
device_class=BinarySensorDeviceClass.PROBLEM,
should_report=lambda device: device.weight_calibration_error is not None,
name="Weight Calibration Error"
),
],
DockstreamSmartRFIDFountain: [
PetLibroBinarySensorEntityDescription[DockstreamSmartRFIDFountain](
Expand Down
9 changes: 8 additions & 1 deletion custom_components/petlibro/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,14 @@ class PetLibroButtonEntityDescription(ButtonEntityDescription, PetLibroEntityDes
translation_key="filter_reset",
set_fn=lambda device: device.set_filter_reset(),
name="Filter Reset"
)
),
PetLibroButtonEntityDescription[DockstreamSmartFountain](
key="calibrate_weight",
translation_key="calibrate_weight",
icon="mdi:scale",
set_fn=lambda device: device.calibrate_weight(),
name="Calibrate Weight Sensor"
),
],
DockstreamSmartRFIDFountain: [
PetLibroButtonEntityDescription[DockstreamSmartRFIDFountain](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from ..device import Device
from typing import cast
from logging import getLogger

_LOGGER = getLogger(__name__)

class DockstreamSmartFountain(Device):
Expand Down Expand Up @@ -356,3 +355,19 @@ def update_progress(self) -> float:

progress = upgrade_data.get("progress")
return float(progress) if progress is not None else 0.0

@property
def weight_calibration_error(self) -> bool | None:
exception = self._data.get("dataRealInfo", {}).get("exceptionMessage")
if exception is None:
return None
return "calibration" in exception.lower() or "weight" in exception.lower()

async def calibrate_weight(self) -> None:
_LOGGER.debug(f"Calibrating weight sensor for {self.serial}")
try:
await self.api.exec_device_command(self.serial, "CALIBRATE")
await self.refresh()
except (aiohttp.ClientError, PetLibroAPIError) as err:
_LOGGER.error(f"Failed to calibrate weight sensor for {self.serial}: {err}")
raise PetLibroAPIError(f"Error calibrating weight sensor: {err}")