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
Implement external custom components installing from YAML #1630
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely simplify component sharing on the community. 🎉🎉
|
||
if config[CONF_COMPONENTS] == "all": | ||
num_components = len(list(components_dir.glob("*/__init__.py"))) | ||
if num_components > 100: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside this which mostly indicates an user entering wrong source url, I would add a check where it explicitly needs to indicate overriden ESPHome bundled components. So if you want a new fancy captive_portal
then you must indicate it here, otherwise ESPHome's is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. On the other hand, doing so would be a problem for some external integrations.
For example: I create an external repo for my fancy new display driver xyz9000
and publish that. Then I want to add another display like xyz9001
, but at some point I want to refactor some of the shared code into a new module xyz_base
.
In that case, if we force users to manually set the components, we would really limit external component repos - getting all users to change their config would be painful.
I don't think stuff like display drivers will overwrite some internal stuff like captive_portal
- or if it does end up being a problem we can create a policy where certain "core" components have to explicitly opted in. We can do that later too because requiring that would not be a big breaking change (I don't suspect many external integrations will overwrite core stuff)
return SOURCE_SCHEMA({CONF_TYPE: TYPE_LOCAL, CONF_PATH: value}) | ||
except cv.Invalid: | ||
pass | ||
# Regex for GitHub repo name with optional branch/tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a standard like the way platformio or GH actions names refers to github repos? its a bit magical as no mention to github is made on the string itself, like github://
etc. just an opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that syntax is based on GH actions'.
The reason I don't want a full URL like https://github.com/esphome/esphome@dev
is because then with the @dev
part it wouldn't be an actual URL (as in if you type it in your browser you'll get an error page)
github://
could be a good alternative though
I was thinking about this, one minor issue While this solves the issue, as you can use the I propose a default (always on) configuration for external_components:
- type: local
path: './custom_components'
components: 'all' So that configuration is default, and it will act as current default behavior of ESPHome, but can be overriden so you can: external_components: Will disable loading of external_components:
- type: local
path: './custom_components'
components: [ 'rtttl' ] This might also plain the path to make mandatory setting of the component to be overriden, allowing |
@glmnet I see what you mean with the Maybe we can do something like HA instead: Print a warning message for every component loaded through the |
…ome/esphome into importlib-custom-components
* Move components import loading to importlib MetaPathFinder and importlib.resources * Add external_components component * Fix * Fix * fix cv.url return * fix validate shorthand git * implement git refresh * Use finders from sys.path_hooks instead of looking for __init__.py * use github:// schema * error handling * add test * fix handling git output * revert file check handling * fix test * allow full component path be specified for local * fix test * fix path handling * lint Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
@glmnet Thank you so much for finishing this PR and the docs! Really appreciated! |
What does this implement/fix?
A prototype for #1554
This implements a new system for downloading and including custom components straight from YAML. Note: early PoC - syntax will change.
Important: This also changes the python requirement to 3.7 (previously was 3.6). Now that the docker base image is running 3.7 and most distributions have 3.7+ already, that should not be a major problem.
Types of changes
Related issue or feature (if applicable): fixes TODO
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#1107
Test Environment
Example entry for
config.yaml
:Explain your changes
This PR is split in two (large) commits:
The expected format for the repository is:
<REPO_ROOT>/components/my_custom_component/*
(this directory must include at least a__init__.py
file); this is how I expect custom component creators to present the code.<REPO_ROOT>/esphome/components/my_custom_component/*
(this directory must include at least a__init__.py
file); this format is used mainly for being able to import certain components from a specific esphome branch/versionFor now, only git and local sources are supported, others can be added later.
Future work includes refreshing the repository every so often.
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: