jcgoette / baby_buddy_homeassistant

This custom integration provides sensors for Baby Buddy API endpoints.
MIT License
64 stars 30 forks source link

All data populating except feedings #76

Closed poldim closed 2 years ago

poldim commented 2 years ago

Hey there, I'm running the latest HA and baby buddy via docker. We're about a week in with the kid and have been using the bb UI. But I'd like to integrate it better into HA. For some reason, my last_feeding is not updating.

TLD/api/feedings/ shows a lot of data and I've tried a manual putt from within the container (``curl -X GET "TLD/api/feedings/" -H "Authorization: Token XXXXX") and it returns a lot of data

Any idea what I can check?

jcgoette commented 2 years ago

last_feeding returns volume from last feed. If null, would be Unknown.

poldim commented 2 years ago

last_feeding returns volume from last feed. If null, would be Unknown.

So it's the volume of the last feeding not the time of the last feeding like the other sensors?

Just noticed this log error:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/babybuddy/sensor.py:480
Integration: Baby Buddy (documentation, issues)
First occurred: September 14, 2022 at 12:44:13 AM (1 occurrences)
Last logged: September 14, 2022 at 12:44:13 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 151, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 110, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 348, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 388, in state
    value = self.native_value
  File "/config/custom_components/babybuddy/sensor.py", line 480, in native_value
    data: dict[str, str] = self.coordinator.data[1][self.child[ATTR_ID]][
KeyError: 'feedings'
poldim commented 2 years ago

Confirmed. Might be good to update the name to default to last feeding amount or last feeding volume.

Are you open to adding more sensors to the integration if I submit a pr or should I just make those for my end?

image

jcgoette commented 2 years ago

https://github.com/jcgoette/baby_buddy_homeassistant/issues/45#issuecomment-965972097

I've been meaning to make more sensors to handle both types of data, but I've been stuck/distracted on how to do it without a breaking release.

poldim commented 2 years ago

I completely agree with the practice of having more sensors that are disabled by default - so that comment compeltely resonates with me. However, I'm not a good enough programmer to be able to figure out a way to not have a breaking change. I thought since HA went to UI configured integrations it's able to change things like entity names on the back end without having to have the user change things. Although any other things that rely on it will have to be updated.