custom-components / grocy

Custom Grocy integration for Home Assistant
Apache License 2.0
162 stars 50 forks source link

Lovelace not accessible #118

Closed razvanmdobre closed 3 years ago

razvanmdobre commented 3 years ago

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.

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 mobiole 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.

isabellaalstrom commented 3 years ago

This bug belongs in pygrocy I'd say. Please provide the information in a new issue over at that repo, here.

trunks403 commented 3 years ago

I have almost the same problem all my integrations sensors where broken. I also created a blog on https://community.home-assistant.io/t/lots-of-entity-not-available-after-restore-snapshot/286281/8

razvanmdobre commented 3 years ago

This bug belongs in pygrocy I'd say. Please provide the information in a new issue over at that repo, here.

Thanks. I opened the issue https://github.com/SebRut/pygrocy/issues/158

jofotoo commented 3 years ago

Any progress on this? I only have 2 barcodes in my install at the moment.... if i delete them will that cure it for the time being?

isabellaalstrom commented 3 years ago

I don't have the time to look at this at this moment, but I'd say that if you remove the bar codes it should work. My install is working fine, and I don't have any bar codes at all.

razvanmdobre commented 3 years ago

Hi I removed all the barcodes and I enabled back Grocy integration. Now, the issue doesn't reproduce but, when I call grocy.consume_product_from_stock, it doesn't change the stock and I have the following errors in home-assistant.log:

2021-04-09 09:35:12 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 1.463 seconds 2021-04-09 09:35:18 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2021-04-09 09:35:18 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocketapi script: Executing step call service 2021-04-09 09:35:18 WARNING (MainThread) [homeassistant.util.async] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for grocy doing I/O at custom_components/grocy/services.py, line 176: coordinator.api.consume_product( 2021-04-09 09:35:18 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: I/O must be done in the executor; Use await hass.async_add_executor_job() at custom_components/grocy/services.py, line 176: coordinator.api.consume_product( Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service await handler.job.target(service_call) File "/config/custom_components/grocy/services.py", line 96, in async_call_grocy_service await async_consume_product_service(hass, coordinator, service_data) File "/config/custom_components/grocy/services.py", line 176, in async_consume_product_service coordinator.api.consume_product( File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy.py", line 123, in consume_product return self._api_client.consume_product( File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 651, in consume_product self._do_post_request(f"stock/products/{product_id}/consume", data) File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 557, in _do_post_request resp = requests.post( File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 119, in post return request('post', url, data=data, json=json, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request conn.request(method, url, httplib_request_kw) File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 234, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "/usr/local/lib/python3.8/http/client.py", line 1255, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.8/http/client.py", line 1266, in _send_request self.putrequest(method, url, skips) File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 214, in putrequest return HTTPConnection.putrequest(self, method, url, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/util/async.py", line 150, in protected_loop_func checkloop() File "/usr/src/homeassistant/homeassistant/util/async.py", line 139, in check_loop raise RuntimeError( RuntimeError: I/O must be done in the executor; Use await hass.async_add_executor_job() at custom_components/grocy/services.py, line 176: coordinator.api.consume_product( 2021-04-09 09:35:18 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [2760416968] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 18, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 439, in handle_execute_script await script_obj.async_run(context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1195, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 341, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service await handler.job.target(service_call) File "/config/custom_components/grocy/services.py", line 96, in async_call_grocy_service await async_consume_product_service(hass, coordinator, service_data) File "/config/custom_components/grocy/services.py", line 176, in async_consume_product_service coordinator.api.consume_product( File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy.py", line 123, in consume_product return self._api_client.consume_product( File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 651, in consume_product self._do_post_request(f"stock/products/{product_id}/consume", data) File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 557, in _do_post_request resp = requests.post( File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 119, in post return request('post', url, data=data, json=json, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, kwargs) File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request conn.request(method, url, httplib_request_kw) File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 234, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "/usr/local/lib/python3.8/http/client.py", line 1255, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.8/http/client.py", line 1266, in _send_request self.putrequest(method, url, skips) File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 214, in putrequest return HTTPConnection.putrequest(self, method, url, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/util/async.py", line 150, in protected_loop_func checkloop() File "/usr/src/homeassistant/homeassistant/util/async.py", line 139, in check_loop raise RuntimeError( RuntimeError: I/O must be done in the executor; Use await hass.async_add_executor_job() at custom_components/grocy/services.py, line 176: coordinator.api.consume_product( 2021-04-09 09:35:43 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 1.477 seconds 2021-04-09 09:35:51 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'consumer_overload' when rendering '{{ value_json.consumer_overload }}' 2021-04-09 09:35:51 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'consumer_connected' when rendering '{{ value_json.consumer_connected }}'

Home Assistant core-2021.4.0 Grocy v3.0.1 Grocy integration v3.0.1

Surgical71 commented 3 years ago

@isabellaalstrom Is it possible to just update the integration to exclude the Barcodes as a HotFix? I know removing them from my Grocy install will fix the issue but then I can't use my Barcode Scanners setup. Maybe do this until you can find a permanent fix?

isabellaalstrom commented 3 years ago

@Surgical71 @razvanmdobre Could you please try the latest beta?

razvanmdobre commented 3 years ago

@Surgical71 @razvanmdobre Could you please try the latest beta?

I install it and it works fine with and without barcodes. Thanks!

Surgical71 commented 3 years ago

Everything is working correctly. Thank you for the effort :)

isabellaalstrom commented 3 years ago

Thank @ludeeus :)