geertmeersman / robonect

Home Assistant integration for Robonect
MIT License
36 stars 4 forks source link

Unable to place mowing job #180

Closed jstaro closed 2 months ago

jstaro commented 3 months ago

Describe the bug

I am unable to place a mowing job using the service, including via the debug service helper. No error is bubbled up to the user; the service call is successful as far as the UI (or service call via node-red for instance) is concerned.

Log information

2024-07-08 06:03:22.555 WARNING (SyncWorker_41) [homeassistant.helpers.frame] Detected that custom integration 'robonect' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/robonect/entity.py, line 127: self.async_write_ha_state(), please report it to the author of the 'robonect' custom integration
2024-07-08 06:03:22.562 WARNING (SyncWorker_33) [homeassistant.helpers.frame] Detected that custom integration 'robonect' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/robonect/entity.py, line 127: self.async_write_ha_state(), please report it to the author of the 'robonect' custom integration
2024-07-08 06:03:22.557 ERROR (SyncWorker_41) [homeassistant] Error doing job: Future exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/robonect/sensor.py", line 369, in update_busevent
    self.update_ha_state()
  File "/config/custom_components/robonect/entity.py", line 127, in update_ha_state
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1006, in async_write_ha_state
    report_non_thread_safe_operation("async_write_ha_state")
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
    report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'robonect' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/robonect/entity.py, line 127: self.async_write_ha_state(). Please report it to the author of the 'robonect' custom integration.
2024-07-08 06:03:22.588 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/robonect/sensor.py", line 369, in update_busevent
    self.update_ha_state()
  File "/config/custom_components/robonect/entity.py", line 127, in update_ha_state
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1006, in async_write_ha_state
    report_non_thread_safe_operation("async_write_ha_state")
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
    report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'robonect' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/robonect/entity.py, line 127: self.async_write_ha_state(). Please report it to the author of the 'robonect' custom integration.

Additional context

Version: v1.7.1 I cannot say if this used to work because this is the first version I use. Other commands work fine, from what I can see. I am using both MQTT and REST communication.

geertmeersman commented 3 months ago

Thanks, will check it out

jstaro commented 2 months ago

I have also found some time to look a bit deeper.

I cannot get the set timer command to work either. The original error that gets swallowed by the async issue (lacking await? I don't really know Python) seems to be auth-related. image

I took that URL and curl'd it:

* Connected to 10.2.0.252 (10.2.0.252) port 80
> GET /json?cmd=timer&enable=1&timer=1&start=09%3A30&end=18%3A00&mo=1&tu=1&we=1&th=1&fr=1&sa=1&su=1 HTTP/1.1
> Host: 10.2.0.252
> User-Agent: curl/8.4.0
> Accept: */*
> Authorization: Basic <base64 encoded user:pass redacted>
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Server: FHDR
< Connection: close
< Cache-Control: no-cache
< Authorization: Basic <base64 encoded user:pass redacted>
<
{"timer": {"id": 1, "enabled": true, "start": "09:30", "end": "18:00", "weekdays": {"mo": true, "tu": true, "we": true, "th": true, "fr": true, "sa": true, "su": true}}, "successful": true}

And the timer is created just fine.

Maybe this helps, but when I first set up the integration, I didn't understand why I needed to set up REST in the setup flow since I thought "I'll just use MQTT" and thus unchecked the REST checkbox, so I just entered garbage credentials because I couldn't finish the setup flow without entering something for the REST config.

I have however since tried resetting my user/pass in the integration configuration, and even deleted and re-added the whole hub, but no go. FWIW, when I press configure now, the username field will still have my old, garbage username pre-filled, if that has anything to do with it, but I don't get an error when I set it to the correct user/pass and finish.

I don't see that REST doesn't work though, but it's a bit hard to see which parts of the integration are REST based and which are MQTT based.

Is there a way to set the REST credentials outside of the UI?

geertmeersman commented 2 months ago

Hi, normally you should be able to change it through the configuration. But if that really doesn't work, you could delete the integration config, restart HA (required), and add it again with the good rest credentials

jstaro commented 2 months ago

Deleting the config, then restarting HA indeed did the trick! Thanks! Now I do see a few more entities/sensors that are reporting via REST.

The thing I missed was of course restarting HA... when will I ever learn?

Still strange that I could not change the credentials, and being forced through the REST credentials flow even if when I unchecked REST communication earlier. Perhaps adding a short explanation as to why it's a good idea to set up both protocols (either in the UI or in the README) would've prevented me from doing stupid things.

Oh, and the error swallowing I suppose. That was the big thing that tripped me up.

I'll let you decide if you want to do something about some of the abovementioned things, but I'd be totally fine if you want to close the issue since, after all, they are different problems.

geertmeersman commented 2 months ago

We will keep it open (as a reminder for me to check it). It should normally update the configuration, so have to make some tests 👍 Thanks for reporting anyway! Always possible there is a bug somewhere!

geertmeersman commented 2 months ago

There was indeed a bug since I changed the connection library for robonect from 'requests' to 'httpx'! So correction will come! Now it shows correctly the good error

image