jhansche / ha-birdbuddy

Home Assistant integration for Bird Buddy smart bird feeders
MIT License
41 stars 2 forks source link

Unable to update to version 1.1.1 #36

Closed b0ddu closed 1 year ago

b0ddu commented 1 year ago

Have the latest HA with Supervised install.

Have Birdbuddy Addon from HACS - Installed version 1.1.0 and trying to update to Latest version 1.1.1

I keep getting error - Failed to call service update/install. Update Installation already in progress for Firmware Update.

jhansche commented 1 year ago

What version of the integration do you have installed? You'll see it in the top left corner when you go to HACS -> Bird Buddy.

There was a bug #28 that was fixed in v0.0.10, which is in pre-release right now, so it requires enabling the "show beta versions" option in HACS.

Also note the current state of your feeder. Is it Sleeping? If you try to start the firmware update while it's sleeping, it won't wake up to perform the update. The new version has a check for that and will refuse to start if it's sleeping. To make that worse, if the update was initiated while it's sleeping, then you can't start the update again, because BB servers already have the update queued and it's waiting for the feeder to wake up.

But given the error you're seeing, I'm pretty sure you are on v0.0.9, and it hasn't actually attempted to start the update yet, because of how it checks for an ongoing installation.

To enable beta versions in HACS, go to the screen mentioned above, then click the 3-dots menu in the to right, and click "redownload". Toggle the show beta versions option, and select version 0.0.10. After it updates and you restart HA, then try the firmware update again. If it's currently sleeping, you can wake it up by taking it out of the feeder and plugging it in.

b0ddu commented 1 year ago

@jhansche thanks for the quick reply. Yes, I'm on v0.0.9 and updated to beta v0.0.10 now and my feeder is sleeping now and not this morning when I first tired.

I didn't realize the Addon was trying to update the Birdbuddy Firmware directly itself. Though it's a neat feature, I definitely feel the option to update the feeder shouldn't be highlighted in Settings > Updates. I would like a binary_sensor showing update_available ON or OFF. I've seen birdbuddy firmware update process rather clunky and needs to be connected to charger. We can close this issue as the update version is for feeder itself and not the addon.

Thanks for great work, will look through this and see if i can help as well.

jhansche commented 1 year ago

In settings is just how HA surfaces available updates, including add-ons, HA updates, and device firmware updates. If you'd rather not be notified you can use the skip button, or disable the entity. There's also an option to set the entity hidden, if you still want to be able to see it in some cases, but I'm not sure if that will also hide it from appearing in settings or not.

I also agree it can be confusing, because it has the same icon, whether it's for the HACS integration update (like to v0.0.10), a "repair" option to restart HA after the integration update, or the feeder firmware update (1.1.1). When it's a firmware update, the title will be "[Feeder Name] Firmware Update".

I'll see if we can change the icon for a firmware update to try to disambiguate that from the integration updates.

When you are ready to perform the update of your BB, I would be interested in your feedback, if you do it through the integration. I tried it on mine but that's when I discovered the issues that I tried to fix in #29, but by then it was too late to see it actually work on mine, because it was already started on the server side. I did see that it completed successfully in the logs, but I didn't get to see it update through the HA Updates UI

b0ddu commented 1 year ago

@jhansche Got it. So, I tired the Feeder Firmware Update when it was awake and this time, felt like it took the input and didn't see anything live happening with update. After a while, i got a message from BirdBuddy App that the update is completed and i do see it on newer version and the notification in HA is gone as well.

One more question, why are these entities grayed out other than battery. How are you using this Addon.

image

jhansche commented 1 year ago

Some of the entities are disabled by default, which is likely what you're seeing when they're grayed out. If you click on it you can enable the ones you want to see and use. This is a fairly typical trend in HA integrations, where entities that you don't need or use could be disabled to avoid using the db storage.

When you say after a while, how long was that? The entity polls for firmware update progress every 15 seconds, and should notify the UI of those progress changes. But if the progress is slow, and if you closed the update dialog, then you might not see that progress. The app says it might take up to 30 minutes to complete.

I'll do some testing with a fake progress to see if there's anything more I should be doing. And I'll check if I have the actual logs showing the progress number changing. It's possible that the API isn't actually giving us an accurate progress percentage.

And minor correction (I don't mind, but HACS and HA would make a big deal out of it 😛), this is an integration, not an add-on. I use it primarily to graph battery levels over time, especially seeing the changes in trend based on status and whether the solar panel is charging it. And also with automations to auto-collect new postcards as they arrive to remove the tedium of having to do it in the BB app.

You can get some ideas of how other users are using it, in the HA community thread.

b0ddu commented 1 year ago

Enabled the entities and created quick card. Thanks. Would definitely like to see the auto-collect automation and being able to directly browse the media browser birdbuddy photos from the card. The BB battery has come a long way with the recent updates coupled with Solar, didn't need me to charge it for a while. The convenience of this integration (thanks for the correction ;)) helped me update the device without getting it inside.

Regarding the feeder firmware update, I have manually selected Update last night and since it was sleeping - it skipped it with log DEEP_SLEEP. It took it as a async_call for later. I believe it automatically updated the feeder when it came online this morning and i got the alert in Birdbuddy App and also HA reported firmwareupdate entity state changed to OFF at 9.06AM. (curious to see when feeder gets into sleeping on and off ).

-------------------
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/birdbuddy/update.py:99
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: January 17, 2023 at 10:09:28 PM (1 occurrences)
Last logged: January 17, 2023 at 10:09:28 PM
Cannot perform update when in state DEEP_SLEEP
  File "/config/custom_components/birdbuddy/update.py", line 99, in async_install
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Cannot perform update when in state DEEP_SLEEP
--------------------
2023-01-19 08:55:42.148 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall update.install (c:): entity_id=['update.birdbuddy_firmware_update'], backup=False>
File "/config/custom_components/birdbuddy/update.py", line 130, in async_install
File "/usr/local/lib/python3.10/site-packages/birdbuddy/client.py", line 610, in update_firmware_check
File "/usr/local/lib/python3.10/site-packages/birdbuddy/client.py", line 174, in _make_request
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('https://graphql.app-api.prod.aws.mybirdbuddy.com/graphql')
--------------------
Logger: homeassistant.core
Source: custom_components/birdbuddy/update.py:130
Integration: Bird Buddy (documentation, issues)
First occurred: 8:55:42 AM (1 occurrences)
Last logged: 8:55:42 AM

Error executing service: <ServiceCall update.install (c:): entity_id=['update.birdbuddy_firmware_update'], backup=False>
  File "/config/custom_components/birdbuddy/update.py", line 130, in async_install
    result = await self.coordinator.client.update_firmware_check(self.feeder)
  File "/usr/local/lib/python3.10/site-packages/birdbuddy/client.py", line 610, in update_firmware_check
    data = await self._make_request(
  File "/usr/local/lib/python3.10/site-packages/birdbuddy/client.py", line 174, in _make_request
    response = await self.graphql.execute_async(
  File "/usr/local/lib/python3.10/site-packages/python_graphql_client/graphql_client.py", line 75, in execute_async
    return await response.json()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('https://graphql.app-api.prod.aws.mybirdbuddy.com/graphql')
jhansche commented 1 year ago

The DEEP_SLEEP log is expected. Since the firmware update won't actually be done until it's awake, I decided to reject the request. We could have made the API request to start the update, but then it would just be in a pending state until the next time the feeder wakes up, and by then it might be in a bad battery state or something like that. I thought it would be better to reject the request at this point.

It also rejects the request if the battery level is too low (BB says ~30-40% iirc, but my check is 10%).

I did make some changes in #29 to better handle errors when first starting the update, as well as suppressing transient errors throughout the update process (up to 4 times in a row).

The 2nd error you see here (Attempt to decode JSON with unexpected mimetype: text/html) means the Bird Buddy server did not respond with the correct type of data, and there isn't anything we can do on our end to fix that. It just means there was an error on their end. This kind of error typically resolves itself, so the transient-error handling should help with that.