Skip to content

Commit 4505b90

Browse files
feat(#84): add power_connected binary sensor for AirSmartFeeder (#253)
Co-authored-by: Jamie Jones <29973406+jjjonesjr33@users.noreply.github.com>
1 parent af74214 commit 4505b90

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

custom_components/petlibro/binary_sensor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ def extra_state_attributes(self):
230230
value_fn=lambda device: device.feeding_plan_state,
231231
name="Feeding Schedule"
232232
),
233+
PetLibroBinarySensorEntityDescription[AirSmartFeeder](
234+
key="power_connected",
235+
translation_key="power_connected",
236+
icon="mdi:power-plug",
237+
device_class=BinarySensorDeviceClass.PLUG,
238+
should_report=lambda device: device.power_connected is not None,
239+
name="Power Connected"
240+
),
233241
],
234242
GranarySmartFeeder: [
235243
PetLibroBinarySensorEntityDescription[GranarySmartFeeder](

custom_components/petlibro/devices/feeders/air_smart_feeder.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ async def refresh(self):
3434
get_work_record = await self.api.get_device_work_record(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

38-
# Update internal data with fetched API data
3939
self.update_data({
4040
"grainStatus": grain_status or {},
4141
"realInfo": real_info or {},
42+
"dataRealInfo": data_real_info or {},
4243
"getUpgrade": get_upgrade or {},
4344
"getAttributeSetting": attribute_settings or {},
4445
"getfeedingplantoday": get_feeding_plan_today or {},
@@ -150,6 +151,13 @@ def electric_quantity(self) -> float:
150151
quantity = self._data.get("realInfo", {}).get("electricQuantity")
151152
return quantity if isinstance(quantity, (float, int)) else 0
152153

154+
@property
155+
def power_connected(self) -> bool | None:
156+
power_type = self._data.get("dataRealInfo", {}).get("powerType")
157+
if power_type is None:
158+
return None
159+
return power_type == 3
160+
153161
@property
154162
def enable_feeding_plan(self) -> bool:
155163
return self._data.get("realInfo", {}).get("enableFeedingPlan", False)

0 commit comments

Comments
 (0)