jcgoette / baby_buddy_homeassistant

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

Using active timer for add service, doesn't delete timer #94

Closed hockey6611 closed 1 year ago

hockey6611 commented 1 year ago

When the timer switch is turned off, the timer is deleted.

However, when an 'add' service is used, the timer is stopped but not deleted. This leads to a build up of stopped timers. The below is the button I used for adding the current timer to tummy time.

cards:
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: babybuddy.add_tummy_time
      data:
        timer: true
        end: '00:00:00'
      target:
        entity_id: switch.test_tester_timer

Am I misunderstanding the use case for service: babybuddy.add_tummy_time? Or is there a way delete the time using these add services as well?

jcgoette commented 1 year ago

Do you mean in the BB database? I don't think the timer is supposed to be deleted after being consumed.

I guess you could call something like this after the first service call, but not sure how that would behave in BB itself:

service: babybuddy.delete_last_entry
data: {}
target:
  entity_id: sensor.***_last_timer
hockey6611 commented 1 year ago

Thank you for the quick response! And thank you for this great integration!

Do you mean in the BB database? I don't think the timer is supposed to be deleted after being consumed.

Yes, I am referring to the BB database. turning the switch on adds and starts a timer, turning the switch off deletes the timer in BB. This follows the documentation here, "Turning off the switch deletes the timer."

Consuming a timer in BB doesn't delete the timer either. However, interestingly, stopping a timer in BB doesn't delete it, like it does using the HA switch entity.

service: babybuddy.add_tummy_time stops the timer in BB, however, it is not removed (like when switch.turn_off is run).

So continued use of service: switch.turn_on followed by service: babybuddy.add_tummy_time (as I believe is the intended use case?) leads to a build up of stopped timers in BB:

image

jcgoette commented 1 year ago

Yea, that's completely normal behavior AFAIK. I think that's why @cdubz included the Delete Inactive Timers button.

hockey6611 commented 1 year ago

Under stood - Thank you!

Do you know of a way to interact with this other than the BB interface? Not a huge deal but it would be nice to run an HA automation to clean these up. I didn't see this as part of the REST API docs either so I'd imagine not?

jcgoette commented 1 year ago

Could probably just repeatedly call babybuddy.delete_last_entry. But I did think about maybe doing a PR to add API endpoint for that Delete Inactive Timers action.