Skip to content

Commit c4df5e0

Browse files
feat(#214): add dual-tray (PLAF103-DT) food level sensors for GranarySmartFeeder (#257)
Co-authored-by: Jamie Jones <29973406+jjjonesjr33@users.noreply.github.com>
1 parent 5da02a2 commit c4df5e0

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

custom_components/petlibro/binary_sensor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,22 @@ def extra_state_attributes(self):
302302
value_fn=lambda device: device.feeding_plan_state,
303303
name="Feeding Schedule"
304304
),
305+
PetLibroBinarySensorEntityDescription[GranarySmartFeeder](
306+
key="left_food_low",
307+
translation_key="left_food_low",
308+
icon="mdi:bowl-mix-outline",
309+
device_class=BinarySensorDeviceClass.PROBLEM,
310+
should_report=lambda device: device.left_food_low is not None,
311+
name="Left Food Status"
312+
),
313+
PetLibroBinarySensorEntityDescription[GranarySmartFeeder](
314+
key="right_food_low",
315+
translation_key="right_food_low",
316+
icon="mdi:bowl-mix-outline",
317+
device_class=BinarySensorDeviceClass.PROBLEM,
318+
should_report=lambda device: device.right_food_low is not None,
319+
name="Right Food Status"
320+
),
305321
],
306322
GranarySmartCameraFeeder: [
307323
PetLibroBinarySensorEntityDescription[GranarySmartCameraFeeder](

custom_components/petlibro/devices/feeders/granary_smart_feeder.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,34 @@ def battery_state(self) -> str:
8484
def food_dispenser_state(self) -> bool:
8585
return not bool(self._data.get("realInfo", {}).get("grainOutletState", True))
8686

87+
@property
88+
def bowl_mode(self) -> str:
89+
return self._data.get("realInfo", {}).get("bowlMode", "SINGLE_BOWL")
90+
8791
@property
8892
def food_low(self) -> bool:
89-
return not bool(self._data.get("realInfo", {}).get("surplusGrain", True))
93+
surplus = self._data.get("realInfo", {}).get("surplusGrain")
94+
if surplus is not None:
95+
return not bool(surplus)
96+
left = self._data.get("realInfo", {}).get("leftWarehouseSurplusGrain")
97+
right = self._data.get("realInfo", {}).get("rightWarehouseSurplusGrain")
98+
if left is not None and right is not None:
99+
return not bool(left) or not bool(right)
100+
return True
101+
102+
@property
103+
def left_food_low(self) -> bool | None:
104+
value = self._data.get("realInfo", {}).get("leftWarehouseSurplusGrain")
105+
if value is None:
106+
return None
107+
return not bool(value)
108+
109+
@property
110+
def right_food_low(self) -> bool | None:
111+
value = self._data.get("realInfo", {}).get("rightWarehouseSurplusGrain")
112+
if value is None:
113+
return None
114+
return not bool(value)
90115

91116
@property
92117
def unit_type(self) -> int:

0 commit comments

Comments
 (0)