Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@service crashs homeassistant #517

Open
littleyoda opened this issue Aug 20, 2023 · 6 comments
Open

@service crashs homeassistant #517

littleyoda opened this issue Aug 20, 2023 · 6 comments

Comments

@littleyoda
Copy link

After updating HA to the latest version (2023.8.3) from 2023.7, HA did not start.
I had to disable all pyscripts to get it to run at all.
After a lot of testing, it turns out that the @service statement is the problem.

The following statement runed from jupyter, leads to HA being unstable. HA seems to run, but no longer accepts new browser connections. I've to restart HA.

@service("halloworldtest.run")
def myTestTrigger():
    print("Hallo World")
2023-08-20 19:33:50.097 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140134801655744] Error handling message: Unknown error (unknown_error) <NAME REMOVED> from <IP REMOVED> (Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 417, in handle_get_services
    payload = await _async_get_all_descriptions_json(hass)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 398, in _async_get_all_descriptions_json
    descriptions = await async_get_all_descriptions(hass)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 612, in async_get_all_descriptions
    translations = await translation.async_get_translations(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/translation.py", line 318, in async_get_translations
    cached = await cache.async_fetch(language, category, components)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/translation.py", line 209, in async_fetch
    await self._async_load(language, components_to_load)
  File "/usr/src/homeassistant/homeassistant/helpers/translation.py", line 230, in _async_load
    raise int_or_exc
homeassistant.loader.IntegrationNotFound: Integration 'halloworldtest' not found.
@craigbarratt
Copy link
Member

I tried 2023.8.3 with your service example and it works fine for me. I'm not sure why it is crashing in your case.

@Kaptensanders
Copy link

Kaptensanders commented Aug 23, 2023

Same problem for me. HA 2023.8.3, core install on venv - Python 3.11.4
Exact same error as @littleyoda

EDIT:
Seems the error only occurs when assigning a name to the service definition.

@service  # <- WORKS, assigned service name is pyscript.sunlight_set
@service(f"sunlight.set") # <- ERROR,  homeassistant.loader.IntegrationNotFound: Integration 'sunlight' not found.
def sunlight_set (newval:str):
    input_select.select_option(entity_id="input_select.sunlight", option=newval)

@littleyoda
Copy link
Author

littleyoda commented Aug 23, 2023

can confirm the workaround from Kaptensanders.
@service works
@service("xxyz"), however, does not works.

@Kaptensanders thanks for the workaround

@craigbarratt
Copy link
Member

craigbarratt commented Aug 24, 2023

I've confirmed that this code works in 2023.7.3, but fails in 2023.8.3 when there is a service defined in pyscript that doesn't have a corresponding integration of the same name.

from homeassistant.helpers.service import async_get_all_descriptions

descriptions = async_get_all_descriptions(hass)

From the error message, it fails trying to load translations. Is anyone familiar with any recent HASS service description/translation changes?

@craigbarratt
Copy link
Member

craigbarratt commented Aug 24, 2023

The issue is this code homeassistant/helpers/service.py got added in in 2023.8.0. HASS now loads all translations for all services. When an arbitrary service name isn't part of an associated integration, the loading of translations fails. That causes async_get_all_descriptions() to fail.

I can't see a work around for this. Perhaps it's a breaking change, and you can only create services in pyscript that are part of an existing integration (ie, top-level name)?

@Kaptensanders
Copy link

Kaptensanders commented Aug 25, 2023

Breaking change maybe but an ok one. When you think about it it's is maybe bad practice to refer to non-existing integrations. Not surprising that could lead to problems with HA.

@service("pyscript.service_name") # works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants