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

Numpy should be a dependency from core #114318

Closed
pascallj opened this issue Mar 27, 2024 · 24 comments · Fixed by #117270
Closed

Numpy should be a dependency from core #114318

pascallj opened this issue Mar 27, 2024 · 24 comments · Fixed by #117270

Comments

@pascallj
Copy link
Contributor

The problem

When using HASS Core without the default_config integration in configuration.yaml, there is still a dependency on Camera which depends on Stream which depends on numpy. However because the Stream integration isn't loaded, the numpy module is not automatically installed. This results in an error and you cannot use Home Assistant without numpy.

I am not sure if this happens in the Container versions as well, but probably only on Core in a virtual environment

I am aware that this is a particular niche situation, but it would be nice that even users with a minimal configuration automatically have the correct version of numpy installed (which complies with the package constraints too). I am not sure how and where this should be fixed though. Should numpy be a dependency when installing homeassistant with pip? Or a dependency of another module as well?

What version of Home Assistant Core has the issue?

core-2024.4.0.dev0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-03-27 15:56:43.783 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [137015304515136] Error handling message: Unknown error (unknown_error) test from 172.17.0.1 (Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0)
Traceback (most recent call last):
  File "/root/homeassistant/core/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/root/homeassistant/core/homeassistant/components/websocket_api/commands.py", line 485, in handle_get_services
    payload = await _async_get_all_descriptions_json(hass)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/components/websocket_api/commands.py", line 466, in _async_get_all_descriptions_json
    descriptions = await async_get_all_descriptions(hass)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/helpers/service.py", line 707, in async_get_all_descriptions
    contents = await hass.async_add_executor_job(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/helpers/service.py", line 651, in _load_services_files
    return [_load_services_file(hass, integration) for integration in integrations]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/helpers/service.py", line 629, in _load_services_file
    _SERVICES_SCHEMA(
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 274, in _exec
    return func(path, v)
           ^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 274, in _exec
    return func(path, v)
           ^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 353, in _exec
    v = func(path, v)
        ^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 636, in validate_sequence
    cval = validate(index_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 636, in validate_sequence
    cval = validate(index_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/validators.py", line 353, in _exec
    v = func(path, v)
        ^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/helpers/selector.py", line 161, in _validate_supported_features
    feature_mask |= _validate_supported_feature(supported_feature)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/helpers/selector.py", line 136, in _validate_supported_feature
    known_entity_features = _entity_features()
                            ^^^^^^^^^^^^^^^^^^
  File "/root/homeassistant/core/homeassistant/helpers/selector.py", line 92, in _entity_features
    from homeassistant.components.camera import CameraEntityFeature
  File "/root/homeassistant/core/homeassistant/components/camera/__init__.py", line 31, in <module>
    from homeassistant.components.stream import (
  File "/root/homeassistant/core/homeassistant/components/stream/__init__.py", line 64, in <module>
    from .core import (
  File "/root/homeassistant/core/homeassistant/components/stream/core.py", line 15, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

Additional information

No response

@home-assistant
Copy link

Hey there @hunterjm, @uvjustin, @allenporter, mind taking a look at this issue as it has been labeled with an integration (stream) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of stream can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign stream Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


stream documentation
stream source
(message by IssueLinks)

@allenporter
Copy link
Contributor

Not sure I agree. This is attempting to load stream as camera depends on stream.

@pascallj
Copy link
Contributor Author

pascallj commented Mar 27, 2024

What part don't you agree with? You are correct it tries to load stream via camera, but because the stream integration is in default_config, which is not loaded, the dependencies from Stream aren't installed.

@allenporter
Copy link
Contributor

I don't think there is well defined behavior when default config is disabled. You are loading a camera so you need to load stream. I suggest just enabling stream.

1 similar comment
@allenporter
Copy link
Contributor

I don't think there is well defined behavior when default config is disabled. You are loading a camera so you need to load stream. I suggest just enabling stream.

@pascallj
Copy link
Contributor Author

Ah alright, might be. I was under the impression that now that some core components have been moved into bootstrap (#105560), default_config can be safely omitted.

@allenporter
Copy link
Contributor

Ah alright, might be. I was under the impression that now that some core components have been moved into bootstrap (#105560), default_config can be safely omitted.

I think stream may be in the "has impact" category given the heavy dependencies on things like pyav and ffmpeg.

@pascallj
Copy link
Contributor Author

Which is exactly why I don't want it in my configuration if I don't have a need for it 😉

@allenporter
Copy link
Contributor

so camera is loaded, but you don't have a camera? (Therefore stream, etc...). I misunderstood and thought you were loading a camera. I see in the stack trace there is a selector that includes CameraEntityFeature which is pulling it in, so makes sense if this is unintentional and something we can look at.

2 similar comments
@allenporter
Copy link
Contributor

so camera is loaded, but you don't have a camera? (Therefore stream, etc...). I misunderstood and thought you were loading a camera. I see in the stack trace there is a selector that includes CameraEntityFeature which is pulling it in, so makes sense if this is unintentional and something we can look at.

@allenporter
Copy link
Contributor

so camera is loaded, but you don't have a camera? (Therefore stream, etc...). I misunderstood and thought you were loading a camera. I see in the stack trace there is a selector that includes CameraEntityFeature which is pulling it in, so makes sense if this is unintentional and something we can look at.

@pascallj
Copy link
Contributor Author

Correct! Maybe I should have mentioned that more clearly. This is just with an empty configuration out of the box. So nothing else besides the core components inside bootstrap. That's why I initially didn't tag the stream integration, as I didn't think it was the cause.

I tried to figure out why it was loading camera, but this was far beyond my understanding of the home assistant architecture.

@allenporter
Copy link
Contributor

Coincidentally, I just got the same error doing the following steps:

  1. rebuild devcontainer from head
  2. run pre-commit
$ pre-commit
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/codespell-project/codespell.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/adrienverge/yamllint.git.
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-prettier.
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-prettier:prettier@3.0.3.
[INFO] Initializing environment for https://github.com/cdce8p/python-typing-update.
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/codespell-project/codespell.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/adrienverge/yamllint.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/mirrors-prettier.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
ruff.................................................(no files to check)Skipped
ruff-format..........................................(no files to check)Skipped
codespell............................................(no files to check)Skipped
check json...............................................................Passed
don't commit to branch...................................................Passed
yamllint.............................................(no files to check)Skipped
prettier.................................................................Passed
mypy.................................................(no files to check)Skipped
pylint...............................................(no files to check)Skipped
gen_requirements_all.....................................................Failed
- hook id: gen_requirements_all
- files were modified by this hook

Warning: homeassistant/components/facebox/__init__.py and manifest.json missing, skipping directory. If this is your development environment, you can safely delete this folder.

hassfest.................................................................Failed
- hook id: hassfest
- exit code: 1

Warning: homeassistant/components/facebox/__init__.py and manifest.json missing, skipping directory. If this is your development environment, you can safely delete this folder.
Validating application_credentials... done in 0.03s
Validating bluetooth... done in 0.01s
Validating codeowners... done in 0.03s
Validating config_schema... done in 3.47s
Validating dependencies... done in 11.08s
Validating dhcp... done in 0.01s
Validating icons... done in 0.67s
Validating json... done in 0.00s
Validating manifest... done in 0.06s
Validating mqtt... done in 0.01s
Validating requirements... done in 0.01s
Validating services...Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/workspaces/home-assistant-core/script/hassfest/__main__.py", line 250, in <module>
    sys.exit(main())
             ^^^^^^
  File "/workspaces/home-assistant-core/script/hassfest/__main__.py", line 172, in main
    plugin.validate(integrations, config)
  File "/workspaces/home-assistant-core/script/hassfest/services.py", line 238, in validate
    validate_services(config, integration)
  File "/workspaces/home-assistant-core/script/hassfest/services.py", line 133, in validate_services
    services = CORE_INTEGRATION_SERVICES_SCHEMA(data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 274, in _exec
    return func(path, v)
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 274, in _exec
    return func(path, v)
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 353, in _exec
    v = func(path, v)
        ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 636, in validate_sequence
    cval = validate(index_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 636, in validate_sequence
    cval = validate(index_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 229, in _run
    return self._exec(self._compiled, value, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 353, in _exec
    v = func(path, v)
        ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/workspaces/home-assistant-core/homeassistant/helpers/selector.py", line 161, in _validate_supported_features
    feature_mask |= _validate_supported_feature(supported_feature)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/home-assistant-core/homeassistant/helpers/selector.py", line 136, in _validate_supported_feature
    known_entity_features = _entity_features()
                            ^^^^^^^^^^^^^^^^^^
  File "/workspaces/home-assistant-core/homeassistant/helpers/selector.py", line 92, in _entity_features
    from homeassistant.components.camera import CameraEntityFeature
  File "/workspaces/home-assistant-core/homeassistant/components/camera/__init__.py", line 31, in <module>
    from homeassistant.components.stream import (
  File "/workspaces/home-assistant-core/homeassistant/components/stream/__init__.py", line 64, in <module>
    from .core import (
  File "/workspaces/home-assistant-core/homeassistant/components/stream/core.py", line 15, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

hassfest-metadata....................................(no files to check)Skipped
hassfest-mypy-config.................................(no files to check)Skipped

@joostlek
Copy link
Member

There were some attempts to add this to the general dependencies, but they all got declined but i never saw the reason why they got declined

@allenporter
Copy link
Contributor

History:
#81790 - Attempted to import numpy late to work around this binding. Not a good solution due to added complexity and unpredictability
#81841 - Declares numpy as a requirement for stream
#102215 - pre-commit error: claims it only happens when environment is not setup properly
#108070 - on pre-commit error: "before the dev environment works completely, you need to start hass -c config once and the default_config entry has to be in the configuration.yaml, so that all dependencies get set up."

Generally, i don't think we try super hard to support non-default config, but it seems like given some things were moved to bootstrap and some where not that it still seems like something we're trying to keep working.

I think its fine to say default_config: is needed for local development.

It seems less clear what the solution is for non-dev environment given the selectors imports the camera entity which imports stream. We definitely don't want to add hacks for this, so it may need to stay as the status quo

@RogerSelwyn
Copy link
Contributor

I certainly get this in my dev config. And I'm actually trying to sort a different issue in dev and got the same error with a new build of HA

@Lucas-lyh
Copy link

I get same traceback when building dev container.

@allenporter
Copy link
Contributor

When building yourself in dev I recommend creating a config with default_config:

@RogerSelwyn
Copy link
Contributor

When building yourself in dev I recommend creating a config with default_config:

I think it happens when I add the mqtt integration. But yes I should include default_config, but I try to minimise what I load to reduce rebuild time.

@cetex
Copy link

cetex commented Apr 23, 2024

I guess modularity is a goal and then the solution should be to restore modularity by disconnecting things and making dependencies optional, not adding more. :)

Maybe one of these two alternatives?

  1. Only return entities for actually-loaded-components in selector.py
  2. Make CameraEntityFeature importable without pulling in the rest of the component (camera.py).

@allenporter
Copy link
Contributor

The selector logic is validating features and is pre-loading a map. Maybe that map does not need to exist and the feature enums can be imported only as needed.

@cetex
Copy link

cetex commented May 11, 2024

I modified those functions and made them "forgiving" by wrapping them in try / except statements:
homeassistant/helpers/selector.py:84 def _entity_features()
homeassistant/helpers/service.py:77 def _base_components()

I've been running it for two weeks and it works. Instead of failing, it just logs an exception and moves on without it. I've planned to make a proper PR but haven't gotten around to it yet.

The reason behind all this is that the node I'm running HA on is a relatively low-powered arm device. Compiling numpy, OpenCV etc takes a significant amount of time and HA is our main interface to manage our light-automation (24 shellys), heating+hot-water+ventilation (nibe), air conditioning (toshiba) and soon monitoring / managing solar + car-charger. Anything automatic which might break the functionality is unacceptable because there's no guarantee that I'm around or have time to spare to fix things when it breaks (and it has broken from time to time, not a great experience).

Maybe it would be best if the logic for these functions was 'flipped around'?
Instead of hard-coding dependencies and importing each component providing a dependency it could be changed so the component which provide a certain entity_feature would just register the feature to some registry when it's loaded.

@caraar12345

This comment was marked as duplicate.

@Sibert

This comment was marked as duplicate.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants