3232 SensorEntityDescription ,
3333 dataclass ,
3434)
35- from homeassistant .components .sensor .const import SensorDeviceClass , SensorStateClass
35+ from homeassistant .components .sensor .const import SensorDeviceClass
3636from homeassistant .helpers .device_registry import DeviceEntryType , DeviceInfo
3737from homeassistant .helpers .entity import EntityDescription
3838from homeassistant .helpers .update_coordinator import (
@@ -499,7 +499,6 @@ async def _async_update_avatar(self, url: str | None) -> None:
499499 PetAPI .NAME : pet .name ,
500500 PetAPI .SEX : pet .gender .value ,
501501 PetAPI .STERILIZATION : 1 if pet .sterilization else 2 ,
502- PetAPI .TODAY_EAT_AMOUNT : pet .todayEatNum ,
503502 "status" : pet ._data .get ("status" ),
504503 PetAPI .RFID : pet .rfid ,
505504 "mainPet" : pet ._data .get ("mainPet" ),
@@ -517,69 +516,6 @@ async def _async_update_avatar(self, url: str | None) -> None:
517516 translation_key = "breed_name" ,
518517 icon_fn = lambda pet : pet .type .icon ,
519518 ),
520- PL_PetSensorEntityDescription (
521- key = "todayFeedTimes" ,
522- translation_key = "today_feeding_times" ,
523- name = "Today's Feeding Times" ,
524- icon = "mdi:history" ,
525- state_class = SensorStateClass .TOTAL_INCREASING ,
526- ),
527- PL_PetSensorEntityDescription (
528- key = f"{ PetAPI .TODAY_EAT_AMOUNT } _weight" ,
529- translation_key = "today_feeding_quantity_weight" ,
530- name = "Today's Feeding Quantity (Weight)" ,
531- icon = "mdi:scale" ,
532- value_fn = lambda pet : Unit .convert_feed (
533- value = pet .todayEatNum ,
534- from_unit = None ,
535- to_unit = Unit .GRAMS ,
536- rounded = True ,
537- ),
538- native_unit_of_measurement = UnitOfMass .GRAMS ,
539- suggested_unit_of_measurement_fn = lambda member : getattr (
540- UnitOfMass , member .feedUnitType .name , None
541- ),
542- device_class = SensorDeviceClass .WEIGHT ,
543- state_class = SensorStateClass .TOTAL_INCREASING ,
544- extra_state_attributes_fn = lambda pet : {
545- unit .symbol : Unit .convert_feed (
546- value = pet .todayEatNum ,
547- from_unit = None ,
548- to_unit = unit ,
549- rounded = True ,
550- )
551- for unit in (Unit .GRAMS , Unit .OUNCES )
552- },
553- petlibro_unit = API .FEED_UNIT ,
554- ),
555- PL_PetSensorEntityDescription (
556- key = f"{ PetAPI .TODAY_EAT_AMOUNT } _volume" ,
557- translation_key = "today_feeding_quantity_volume" ,
558- name = "Today's Feeding Quantity (Volume)" ,
559- icon = "mdi:scale" ,
560- value_fn = lambda pet : Unit .convert_feed (
561- value = pet .todayEatNum ,
562- from_unit = None ,
563- to_unit = Unit .MILLILITERS ,
564- rounded = True ,
565- ),
566- native_unit_of_measurement = UnitOfVolume .MILLILITERS ,
567- suggested_unit_of_measurement_fn = lambda member : getattr (
568- UnitOfVolume , member .feedUnitType .name , None
569- ),
570- device_class = SensorDeviceClass .VOLUME ,
571- state_class = SensorStateClass .TOTAL_INCREASING ,
572- extra_state_attributes_fn = lambda pet : {
573- unit .symbol : Unit .convert_feed (
574- value = pet .todayEatNum ,
575- from_unit = None ,
576- to_unit = unit ,
577- rounded = True ,
578- )
579- for unit in (Unit .CUPS , Unit .MILLILITERS )
580- },
581- petlibro_unit = API .FEED_UNIT ,
582- ),
583519 PL_PetSensorEntityDescription (
584520 key = PetAPI .RFID ,
585521 name = "RFID Collar" ,
@@ -610,7 +546,7 @@ async def _async_update_avatar(self, url: str | None) -> None:
610546 key = "age" ,
611547 name = "Age" ,
612548 icon = "mdi:cake-variant" ,
613- value_fn = lambda pet : pet .age . years ,
549+ value_fn = lambda pet : getattr ( pet .age , " years" , None ) ,
614550 extra_state_attributes_fn = lambda pet : {
615551 "years" : pet .age .years ,
616552 "months" : pet .age .months ,
@@ -619,7 +555,7 @@ async def _async_update_avatar(self, url: str | None) -> None:
619555 if (bday := pet .birthday .replace (year = (today := date .today ()).year ))
620556 >= today
621557 else (bday .replace (year = today .year + 1 ) - today ).days ,
622- },
558+ } if pet . age else None ,
623559 ),
624560 ),
625561 PL_PetImageEntity : (
0 commit comments