jbergler / hass-ttlock

Home Assistant integration for TTLock locks
69 stars 13 forks source link

Issue after updating to HA Core 2024.5 #107

Closed cloudbr34k84 closed 7 months ago

cloudbr34k84 commented 7 months ago

Hey there, i just updated to HA Core 2024.5.0b0 and got this notification in my logs

Logger: homeassistant.setup
Source: setup.py:404
First occurred: 7:10:05 am (1 occurrences)
Last logged: 7:10:05 am

Error during setup of component ttlock
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 404, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  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/ttlock/__init__.py", line 53, in setup
    Services(hass).register()
  File "/config/custom_components/ttlock/services.py", line 77, in register
    self.hass.services.async_register(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2489, in async_register
    self._hass.verify_event_loop_thread("async_register")
  File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
    frame.report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'ttlock' calls async_register from a thread at custom_components/ttlock/services.py, line 77: self.hass.services.async_register(. Please report it to the author of the 'ttlock' custom integration.
Wheemer commented 7 months ago

Seeing the same issue. Integration is no longer functioning.

jbergler commented 7 months ago

Looks like there's some info on how to fix this in this thread: https://community.home-assistant.io/t/error-async-get-registry-after-core-2023-5-0/567951/8 I'm away for the next few days, so I'm not sure if I'll get to this before the beta see's wider adoption.

If someone has time to test the solution in the discussion I linked I'd be very happy to accept a PR, otherwise I'll try and get to it sometime in the next two weeks.

jbergler commented 7 months ago

Nevermind, that's unrelated.

It looks like the underlying change is this one: https://github.com/home-assistant/core/pull/116077 That PR doesn't help me understand what the integration is doing wrong unfortunately.

@frenck any chance you can point me to something with more context?

cloudbr34k84 commented 7 months ago

Looks like there's some info on how to fix this in this thread: https://community.home-assistant.io/t/error-async-get-registry-after-core-2023-5-0/567951/8 I'm away for the next few days, so I'm not sure if I'll get to this before the beta see's wider adoption.

If someone has time to test the solution in the discussion I linked I'd be very happy to accept a PR, otherwise I'll try and get to it sometime in the next two weeks.

No worries, thanks for acknowledging. I dont have coding experience so im happy to just wait

chris4824 commented 7 months ago

Need to change

self.hass.services.async_register( To self.hass.services._async_register(

On line 77 in services.py

Worked for me.

jbergler commented 7 months ago

@chris4824 appreciate the enthusiasm. FYI that's not a great fix because it just bypasses a check that was added to deal with crashes in home assistant.

Turns out the problem is much easier to fix properly than I imagined by just dropping the async_ per https://developers.home-assistant.io/docs/asyncio_working_with_async/?_highlight=async

jbergler commented 7 months ago

If someone is running the beta, could you please test the fix before I release a new version. You can do this by going to the integration in HACS, selecting re-download and choosing develop from the version drop down.

jbergler commented 7 months ago

Looks like HACS might be broken and not allowing installing from a branch at the moment, so I went ahead and released v0.6.2 with this fix.

cloudbr34k84 commented 7 months ago

Ok I was just Bout switch to beta version