Skip to content

Commit 5407b18

Browse files
committed
Update Volume and Weight Sensors #173
1 parent f7ed3d9 commit 5407b18

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

custom_components/petlibro/sensor.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,23 @@ def extra_state_attributes(self):
257257
}
258258
case key if key in (
259259
"today_feeding_quantity_weight",
260+
"last_feed_quantity_weight",
261+
"next_feed_quantity_weight",
262+
):
263+
portion = getattr(self.device, key.removesuffix("_weight"), 0)
264+
return {
265+
unit.symbol: Unit.convert_feed(portion * self.device.feed_conv_factor, None, unit, True)
266+
for unit in (Unit.GRAMS, Unit.OUNCES)
267+
}
268+
case key if key in (
260269
"today_feeding_quantity_volume",
261-
"last_feed_quantity_weight",
262270
"last_feed_quantity_volume",
263-
"next_feed_quantity_weight",
264271
"next_feed_quantity_volume"
265272
):
266-
portion = getattr(self.device, key.removesuffix(f"_{self.device_class}"), 0)
267-
return {"portion": portion} | {
273+
portion = getattr(self.device, key.removesuffix("_volume"), 0)
274+
return {
268275
unit.symbol: Unit.convert_feed(portion * self.device.feed_conv_factor, None, unit, True)
269-
for unit in VALID_UNIT_TYPES[API.FEED_UNIT] if unit
276+
for unit in (Unit.CUPS, Unit.MILLILITERS)
270277
}
271278
case key if key in (
272279
"remaining_water",

0 commit comments

Comments
 (0)