Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Lovelace not accessible #158

Closed
razvanmdobre opened this issue Mar 8, 2021 · 10 comments
Closed

Lovelace not accessible #158

razvanmdobre opened this issue Mar 8, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@razvanmdobre
Copy link

Describe the bug
I cannot access the UI of Home Assistant.
In the home-assistant.log I found lots of errors like this:

2021-03-08 12:21:42 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.event(event: state_changed).data.new_state(state: binary_sensor.grocy_missing_products).attributes.missing[0].product_barcodes[0]=<pygrocy.grocy_api_client.ProductBarcode object at 0xa7bcac40>(<class 'pygrocy.grocy_api_client.ProductBarcode'>
2021-03-08 12:21:42 WARNING (Recorder) [homeassistant.components.recorder] State is not JSON serializable: <state binary_sensor.grocy_missing_products=on; missing=[{'name': 'My product name', 'id': 5, 'product_group_id': None, 'available_amount': None, 'best_before_date': None, 'barcodes': ['20456887'], 'product_barcodes': [<pygrocy.grocy_api_client.ProductBarcode object at 0xa7bcac40>], 'amount_missing': 1.0, 'is_partly_in_stock': False}], friendly_name=Grocy missing products, icon=GrocyEntityIcon.MISSING_PRODUCTS @ 2021-03-08T12:21:42.740123+02:00>
2021-03-08 12:21:47 ERROR (MainThread) [homeassistant.components.http.view] Unable to serialize to JSON: Object of type ProductBarcode is not JSON serializable

The log file grows to 1GB and maybe more.

Expected behavior
Being able to use the lovelace UI as before.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the main URL of Home Assistant OR open the Home Assistant mobile app
  2. A blank page is displayed forever with the message "loading data"

What is your installed versions of Home Assistant, Grocy and this integration?
Home Assistant core-2021.3.2
Grocy v3.0.1
Grocy integration v3.0.1

How do you have Grocy installed? Add-on or external?
add-on
Have you added debugging to the log, and what does the log say?
no
JSON service data (if related to using a service)
n/a

Additional context
I had to hard reboot my Raspberry Pi and then disable quickly the Grocy integration add-on.
If not doing that quickly after reboot, I have the same issue.

@SebRut SebRut added the bug Something isn't working label Mar 9, 2021
@renarena
Copy link

same here, the only way to get lovelace loaded is to restart hassio while webpage is loading and not reload it before you have disabled grocy integration.

@isabellaalstrom
Copy link
Contributor

Do you guys have barcodes associated with your products?

@trunks403
Copy link

trunks403 commented Mar 12, 2021

I have the same problems and yes i do use barcodes with my products

@razvanmdobre
Copy link
Author

yes, I have barcodes.

@SebRut
Copy link
Owner

SebRut commented Mar 21, 2021

Hey! I finally got the time to look into this, but it seems that this cant be fixed in pygrocy. The issue is that python doesn't know how to serialize the ProductBarcode object, but AFAIK it isn't possible to make objects serializable in python without changing the call to json.dumps. This call is located in homeassistant so the only way to fix this would be to change the data provided to HA in the custom component. I'm not sure how to do this, but other components had similar problems in the past (https://github.com/home-assistant/core/pull/34540/files).

I'm closing this for now, as I think this has to be fixed in the custom component unfortunately (@isabellaalstrom).

@SebRut SebRut closed this as completed Mar 21, 2021
@isabellaalstrom
Copy link
Contributor

Thanks, I will try to fix.

@ludeeus
Copy link

ludeeus commented Apr 11, 2021

@SebRut The default JSON decoder works with custom objects, if they have str as a parent object, I do that here https://github.com/ludeeus/awesomeversion/blob/main/awesomeversion/awesomeversion.py#L21

Test to prove it: https://github.com/ludeeus/awesomeversion/blob/main/tests/test_awesomeversion.py#L53

@SebRut
Copy link
Owner

SebRut commented Apr 12, 2021

@ludeeus thank you for the hint, that sounds like a way to fix this. But I'm not sure if I like this solution because it leads to pygrocy being altered to be specifically compatible with HA by implementing a workaround.

@ludeeus
Copy link

ludeeus commented Apr 12, 2021

Not really, that would enable the serialization of theses objects without creating and passing in a custom encoder to the dumper.
Everyone that uses this lib and JSON would benefit

@ludeeus
Copy link

ludeeus commented Apr 12, 2021

Another option that will be easier to implement is to implement a custom encoder in this lib, and use that for the toJson() in https://github.com/SebRut/pygrocy/blob/develop/pygrocy/base.py#L13
json.dumps(self.as_dict(), cls: GrocyJSONEncoder)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants