Skip to content

Commit 6722e3f

Browse files
Fix/Pet age error & removed pet eating amounts (#210)
* Fixed pet age & removed pet eating amounts * Fixed age entity --------- Co-authored-by: Jamie Jones <29973406+jjjonesjr33@users.noreply.github.com>
1 parent dc700b3 commit 6722e3f

2 files changed

Lines changed: 3 additions & 81 deletions

File tree

custom_components/petlibro/pets/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ def type(self) -> PetType:
199199
try:
200200
pet_type = PetType(self._data.get(API.PET_TYPE) or 0)
201201
return pet_type
202-
203-
# return self.breedName.lower() or ""
204202
except ValueError:
205203
_LOGGER.error("Unknown pet type value: %s", self._data.get(API.PET_TYPE))
206204
return PetType.CUSTOM
@@ -300,15 +298,3 @@ def trainingGoal(self) -> float:
300298
def walkingGoal(self) -> float:
301299
"""Walking goal of pet in minutes per day."""
302300
return self._data.get("walkingGoal") or 0
303-
304-
# --- Activity
305-
306-
@property
307-
def todayFeedTimes(self) -> int:
308-
"""Number of times the pet ate today."""
309-
return self._data.get("todayFeedTimes") or 0
310-
311-
@property
312-
def todayEatNum(self) -> float:
313-
"""Amount pet ate today in portions."""
314-
return self._data.get(API.TODAY_EAT_AMOUNT) or 0

custom_components/petlibro/pets/entity.py

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
SensorEntityDescription,
3333
dataclass,
3434
)
35-
from homeassistant.components.sensor.const import SensorDeviceClass, SensorStateClass
35+
from homeassistant.components.sensor.const import SensorDeviceClass
3636
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
3737
from homeassistant.helpers.entity import EntityDescription
3838
from 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

Comments
 (0)