MvdDonk / brewfather

Brewfather integration for Home Assistant
16 stars 3 forks source link

No longer works #4

Closed Scales82 closed 1 year ago

Scales82 commented 1 year ago

This integration no longer works with my brewfather. Tried recreating it with a new API key and no luck. Stuck on retrying setup constantly.

MvdDonk commented 1 year ago

@Scales82 Sorry to hear the integration setup is failing. I have just tested it myself and both an existing integration and adding a new one seems to work without issues. Which version of Home Assistant are you running? Was the integration working before? Did it perhaps stopped working after a Home Assistant upgrade?

Maybe there is some information in the logs: https://my.home-assistant.io/redirect/logs/

Any more information can be helpfull, thanks!

jeroenterheerdt commented 1 year ago

I have the same issue. Stuck on initializing after initial setup. I just installed it. Here's the log:

This error originated from a custom integration.

Logger: custom_components.brewfather.coordinator
Source: custom_components/brewfather/models/batch_item.py:35
Integration: Brewfather (documentation, issues)
First occurred: 7:08:19 AM (3 occurrences)
Last logged: 7:08:37 AM

Unexpected error fetching brewfather data:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 53, in _async_update_data
    data = await self.update()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 64, in update
    readings = await self.connection.get_readings(batch.id, DRY_RUN)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/connection.py", line 78, in get_readings
    return readings_item_from_dict(json.loads(jsonText))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batch_item.py", line 370, in readings_item_from_dict
    return from_list(Reading.from_dict, s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batch_item.py", line 60, in from_list
    return [f(y) for y in x]
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batch_item.py", line 60, in <listcomp>
    return [f(y) for y in x]
            ^^^^
  File "/config/custom_components/brewfather/models/batch_item.py", line 252, in from_dict
    temp = from_union([from_int, from_none], obj.get("temp"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batch_item.py", line 35, in from_union
    assert False
AssertionError

Happy to help troubleshoot!

psychopenguin commented 1 year ago

I'm getting the same errors. Home Assistant version: 2023.9.3 (official docker image) Python Version: 3.11.5

2023-10-02 10:48:27.010 ERROR (MainThread) [custom_components.brewfather.coordinator] Unexpected error fetching brewfather data:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 53, in _async_update_data
    data = await self.update()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 59, in update
    allBatches = await self.connection.get_batches(DRY_RUN)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/connection.py", line 45, in get_batches
    return batches_item_from_dict(json.loads(jsonText))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batches_item.py", line 114, in batches_item_from_dict
    return from_list(BatchesItemElement.from_dict, s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batches_item.py", line 54, in from_list
    return [f(y) for y in x]
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batches_item.py", line 54, in <listcomp>
    return [f(y) for y in x]
            ^^^^
  File "/config/custom_components/brewfather/models/batches_item.py", line 91, in from_dict
    name = from_union([Name, from_none], obj.get("name"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/models/batches_item.py", line 34, in from_union
    assert False
AssertionError
MvdDonk commented 1 year ago

I finally found some time to look into the errors. Probably it has to do with some specific json response you are getting which I'm unable to reproduce. So for now I've added extra logging so hopefully I can reproduce the error and fix the problems. I've create a new version of the Brewfather integration so please update. If you can enable debug logging for the Brewfather integration, restart home assistant, disable debug logging and sent me the file I might be able to get more info on the issue. image

Please make sure you see some message like the following in the log file:

DEBUG (MainThread) [custom_components.brewfather.connection] get_batches https://api.brewfather.app/v2/batches/?status=Fermenting (False)
DEBUG (MainThread) [custom_components.brewfather.connection] get_batch https://api.brewfather.app/v2/batches/dpMXZzseP8PqbjG2VJjkC4p3LQwZ6S?include=recipe.fermentation,notes,measuredOg (False)
DEBUG (MainThread) [custom_components.brewfather.connection] get_readings https://api.brewfather.app/v2/batches/dpMXZzseP8PqbjG2VJjkC4p3LQwZ6S/readings (False)

If the log file does not have these lines in it you can try adding a new connection/running the setup: image

psychopenguin commented 1 year ago

Hi! Thanks for the update. I've tried with the new version and also noticed that you update to API v2. :)

But it still not working. Here are the debug logs:

2023-10-03 11:30:00.138 ERROR (MainThread) [custom_components.brewfather.connection] Unable to create batches from json
2023-10-03 11:30:00.153 ERROR (MainThread) [custom_components.brewfather.coordinator] Unexpected error fetching brewfather data: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 53, in _async_update_data
    data = await self.update()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 62, in update
    for batch in allBatches:
TypeError: 'NoneType' object is not iterable
2023-10-03 11:31:01.167 DEBUG (MainThread) [custom_components.brewfather.coordinator] BrewfatherCoordinator._async_update_data!
2023-10-03 11:31:01.167 DEBUG (MainThread) [custom_components.brewfather.coordinator] BrewfatherCoordinator.update!
2023-10-03 11:31:01.167 DEBUG (MainThread) [custom_components.brewfather.connection] get_batches https://api.brewfather.app/v2/batches/?status=Fermenting (False)
2023-10-03 11:31:01.657 DEBUG (MainThread) [custom_components.brewfather.connection] json response: [{"_id":"wSpRtwMIrOmmGfuWFS1IdquwE0P1gE","batchNo":1,"brewDate":1696302000000,"brewer":"Fabio Brito d'Araujo e Oliveira","name":"Lote","recipe":{"name":"Summer Ale"},"status":"Fermenting"}]
2023-10-03 11:31:01.657 ERROR (MainThread) [custom_components.brewfather.connection] Unable to create batches from json
2023-10-03 11:31:01.676 ERROR (MainThread) [custom_components.brewfather.coordinator] Unexpected error fetching brewfather data: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 53, in _async_update_data
    data = await self.update()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 62, in update
    for batch in allBatches:
TypeError: 'NoneType' object is not iterable
2023-10-03 11:31:01.698 DEBUG (MainThread) [custom_components.brewfather.coordinator] Finished fetching brewfather data in 0.531 seconds (success: False)
2023-10-03 11:31:01.698 WARNING (MainThread) [homeassistant.config_entries] Config entry 'brewfather' for brewfather integration not ready yet: None; Retrying in background
MvdDonk commented 1 year ago

@psychopenguin thanks, that was very useful! It appears the Brewfather api returned a translated value for the word "Batch", which is "Lote" in Italian I assume? ;) My code wasn't expecting that to happen and I wasn't having the issue because my Brewfather is running in English.

Anyway, I released a new version (v1.1.2) which hopefully fixes your issue!

MvdDonk commented 1 year ago

@jeroenterheerdt can you update the Brewfather integration to the latest version (v1.1.2) and test again? If it's still not working please send me the logs.

psychopenguin commented 1 year ago

It appears the Brewfather api returned a translated value for the word "Batch", which is "Lote" in Italian I assume? ;)

Actually, it's Portuguese :)

Well, I tried with v1.1.2 (and also the main branch) and it still doesn't work. I also put my BrewFather settings in English and create a new batch, without success. the logs are almost the same from previous version:

2023-10-03 14:46:27.568 WARNING (MainThread) [homeassistant.config_entries] Config entry 'brewfather' for brewfather integration not ready yet: None; Retrying in background
2023-10-03 14:46:32.897 DEBUG (MainThread) [custom_components.brewfather.coordinator] BrewfatherCoordinator._async_update_data!
2023-10-03 14:46:32.897 DEBUG (MainThread) [custom_components.brewfather.coordinator] BrewfatherCoordinator.update!
2023-10-03 14:46:32.897 DEBUG (MainThread) [custom_components.brewfather.connection] get_batches https://api.brewfather.app/v2/batches/?status=Fermenting (False)
2023-10-03 14:46:33.300 DEBUG (MainThread) [custom_components.brewfather.connection] json response: [{"_id":"3686bqe8RyyPPhF5wwURS6sKZdZgg7","batchNo":1,"brewDate":1696302000000,"brewer":"Fabio Brito d'Araujo e Oliveira","name":"Batch","recipe":{"name":"Summer Ale"},"status":"Fermenting"}]
2023-10-03 14:46:33.300 DEBUG (MainThread) [custom_components.brewfather.connection] get_batch https://api.brewfather.app/v2/batches/3686bqe8RyyPPhF5wwURS6sKZdZgg7?include=recipe.fermentation,notes,measuredOg (False)
2023-10-03 14:46:33.667 DEBUG (MainThread) [custom_components.brewfather.connection] json response: {"_id":"3686bqe8RyyPPhF5wwURS6sKZdZgg7","name":"Batch","batchNo":1,"status":"Fermenting","brewer":"Fabio","brewDate":1696302000000,"recipe":{"name":"Summer Ale","fermentation":{"hidden":false,"_created":{"_seconds":1696254715,"_nanoseconds":77000000},"_rev":"yxO8idPnNB5TPMEKPuRt9u56D4UFFj","name":"Summer Ale","_timestamp_ms":1696260544889,"_id":"iRLupEnvdiiF2UEE3VeBmGuLDyPMgB","_timestamp":{"_seconds":1696260544,"_nanoseconds":889000000},"steps":[{"actualTime":1696302000000,"stepTemp":20,"displayPressure":null,"ramp":null,"name":"Fermentacao","pressure":null,"displayStepTemp":20,"stepTime":7,"type":"Primary"},{"actualTime":1696906800000,"stepTemp":5,"displayPressure":null,"ramp":null,"name":"Maturacao","displayStepTemp":5,"pressure":null,"type":"Primary","stepTime":8},{"actualTime":1697598000000,"stepTemp":5,"displayPressure":null,"ramp":null,"name":"Clareamento","displayStepTemp":5,"pressure":null,"type":"Primary","stepTime":10},{"actualTime":1698462000000,"stepTemp":20,"displayPressure":null,"ramp":null,"name":"Envase","pressure":null,"displayStepTemp":20,"type":"Conditioning","stepTime":0.1},{"actualTime":1698462000000,"stepTemp":20,"displayPressure":null,"ramp":null,"name":"Carbonatacao","pressure":null,"displayStepTemp":20,"stepTime":10,"type":"Carbonation"}],"_version":"2.9.1"}},"notes":[{"note":"","type":"statusChanged","timestamp":1696337343524,"status":"Fermenting"}]}
2023-10-03 14:46:33.668 ERROR (MainThread) [custom_components.brewfather.connection] Unable to create batch from json
2023-10-03 14:46:33.688 DEBUG (MainThread) [custom_components.brewfather.connection] get_readings https://api.brewfather.app/v2/batches/3686bqe8RyyPPhF5wwURS6sKZdZgg7/readings (False)
2023-10-03 14:46:34.103 DEBUG (MainThread) [custom_components.brewfather.connection] json response: [{"temp":20,"sg":1.044,"comment":"","time":1696337345982,"id":"manual","type":"manual"},{"temp":20,"sg":1.04,"comment":"","time":1696337559802,"id":"manual","type":"manual"},{"temp":18,"sg":1.04,"comment":"","time":1696338085950,"id":"manual","type":"manual"}]
2023-10-03 14:46:34.104 ERROR (MainThread) [custom_components.brewfather.coordinator] Unexpected error fetching brewfather data: 'NoneType' object has no attribute 'readings'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 53, in _async_update_data
    data = await self.update()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/brewfather/coordinator.py", line 65, in update
    fermentingBatch.readings = readings
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'readings'
2023-10-03 14:46:34.138 DEBUG (MainThread) [custom_components.brewfather.coordinator] Finished fetching brewfather data in 1.242 seconds (success: False)
psychopenguin commented 1 year ago

Hey hey @MvdDonk

I finally made it work. I found the issue was the wrong type for step_time parameter, as my recipes use some steps with decimal value, for example I put bottle as 0.1day. So I changed the type from int to float. I've opened a pull request with the fix.

Let me know when you merge and tag it then I can switch my HACS configuration to use your repo again. :)

@jeroenterheerdt can you also see if this fix your issue?

Thanks!

MvdDonk commented 1 year ago

Hi @psychopenguin , thanks for helping with the issue. I actually just published a new version (v1.1.4) which contains the same fix (and other stuff) but I rewrote quite a bit of code. Can you try the latest version and let me know if that one works? I have added the translations, thanks for your work!!

psychopenguin commented 1 year ago

hi @MvdDonk thanks to accept the translation :)

~i've tried this new version, but despite logs says the data was fetched successfully, sensors aren't being updated.~

Never mind - I just noticed in the logs the json response was empty. I though that I had an active batch - it was showing on UI (so I guess it was a browser cache issue), but when I query the API with curl it was empty. I've added a new batch and it's working now :D

Thanks for the effort!

image

MvdDonk commented 1 year ago

Closing issue due to no response