Skip to content

Commit af74214

Browse files
fix(#73): add rotor stuck error binary sensor for OneRFIDSmartFeeder (#252)
Co-authored-by: Jamie Jones <29973406+jjjonesjr33@users.noreply.github.com>
1 parent 0e4bd43 commit af74214

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

custom_components/petlibro/binary_sensor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ def extra_state_attributes(self):
453453
value_fn=lambda device: device.feeding_plan_state,
454454
name="Feeding Schedule"
455455
),
456+
PetLibroBinarySensorEntityDescription[OneRFIDSmartFeeder](
457+
key="rotor_stuck",
458+
translation_key="rotor_stuck",
459+
icon="mdi:alert",
460+
device_class=BinarySensorDeviceClass.PROBLEM,
461+
should_report=lambda device: device.rotor_stuck is not None,
462+
name="Rotor Status"
463+
),
456464
],
457465
PolarWetFoodFeeder: [
458466
PetLibroBinarySensorEntityDescription[PolarWetFoodFeeder](

custom_components/petlibro/devices/feeders/one_rfid_smart_feeder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ async def refresh(self):
3434
get_feeding_plan_today = await self.api.device_feeding_plan_today_new(self.serial)
3535
feeding_plan_list = (await self.api.device_feeding_plan_list(self.serial)
3636
if self._data.get("enableFeedingPlan") else [])
37+
data_real_info = await self.api.device_data_real_info(self.serial)
3738
# Update internal data with fetched API data
3839
self.update_data({
3940
"grainStatus": grain_status or {},
4041
"realInfo": real_info or {},
42+
"dataRealInfo": data_real_info or {},
4143
"getUpgrade": get_upgrade or {},
4244
"getAttributeSetting": attribute_settings or {},
4345
"getDefaultMatrix": get_default_matrix or {},
@@ -128,6 +130,13 @@ def online(self) -> bool:
128130
def running_state(self) -> bool:
129131
return self._data.get("realInfo", {}).get("runningState", "IDLE") == "RUNNING"
130132

133+
@property
134+
def rotor_stuck(self) -> bool | None:
135+
exception = self._data.get("dataRealInfo", {}).get("exceptionMessage")
136+
if exception is None:
137+
return None
138+
return "rotor" in exception.lower() or "stuck" in exception.lower()
139+
131140
@property
132141
def whether_in_sleep_mode(self) -> bool:
133142
return bool(self._data.get("getAttributeSetting", {}).get("enableSleepMode", False))

0 commit comments

Comments
 (0)