Closed wsw70 closed 3 years ago
I went for solution 1.
Any comments welcome if this was the wrong choice.
The general idea is that "/scripts/" is for YOU, and "/apps/" is for things you've gotten from others or things you've written with the intent to reuse or share.
An "app" will not be loaded unless it has config in pyscript.apps.app_name_here (even if that config is empty). This is similar to Home Assistant in that, just because I have a custom_component code in my file system, that component is not loaded unless I have configuration (or via UI) saying to load it.
Also, apps can take on two naming conventions...
1) /apps/my_app_name/__init__.py
: this is useful if your app is big enough to warrant having multiple files. Because you can then include /apps/my_app_name/someotherfile.py
from inside of __init__.py
.
2) /apps/my_app_name.py
: this is useful if your app fits in a single file.
From what I can figure out by the naming you've used, "meross", "rf433", and "zigbee" are all likely separate apps. They are designed to be configured in YAML and perform certain tasks based on that configuration. Your "genius_app" is probably also an app. Not knowing enough about the "dash apps" I would guess these could go in scripts. The "automation apps" can probably also go in scripts.
You CAN, of course, use these features and directories any way you want. For me, "/scripts/" is used for things that wouldn't make any sense to share because they are specific automations that work in my home, and, while the overall design of the automation may be useful to others, they wouldn't be able to use the code in "/scripts/" as is, unless they happened to have rooms and sensors named exactly the same way I do. Anything that I have in "/apps/" is usable by anyone, since it's configured to your needs in YAML.
Put another way... "/apps/" is like a Home Assistant "custom_component". It probably needs to be configured and is useful to more than just you without modification. "/scripts/" is more like Home Assistant "automations", other people could use them, but not likely without modification. Home Assistant "scripts" can fall in either category depending on what it does.
https://hacs-pyscript.readthedocs.io/en/stable/reference.html#configuration explains how to structure code and which directories are automatically loaded.
My usecase is the following (today everything is under
<config>/pyscript/
):dash__app1.py
,dash__app2.py
etc.automation__app1.py
, etc.All the apps are independent, and only "grouped" together in these two groups.
The relevant
configuration.yaml
entries areThey are accessed by the apps via for instance
pyscript.config['meross']
(alist
in that case).I keep a git repo for all my HA configuration, that includes
pyscript
.I now have an extraordinary, groundbreaking app which I would like to share with the world :) - and this is an opportunity to redesign my directory structure.
First, my understanding is that the configuration variables discussed in the docs
are accessed as follows:
pyscript.config['apps']['my_app1']['hello']
. In other words, there is no link between the place a script is in the directories with its ability to reach for configuration variables (it cal get everything, even from other apps). This is OK, I just wanted to make sure.So back to what I would like to have, I am divided between two approaches:
approach 1
<config>/pyscript/scripts/dash/(all the dash apps together)
<config>/pyscript/scripts/automation/(all the automation apps together)
<config>/pyscript/scripts/automation/genius_app/genius_app.py
genius_app
is the one I would like to distribute, through a git repository in that directory that I would push to GitHub.approach 2
Similar to the approach one, except that I would have all the apps in
<config>/pyscript/apps/[dash|automation]/app_name/__init__.py
I have a hard time understanding the actual differences between these approaches, except that the second one has more boilerplate (and non-distinctive names for the apps (namely
__init__.py
))Is this just a matter of simplifying the distribution? (in approach 2 all the apps are truly separated). What disturbs me in the second case is really the non-distinctive name.
EDIT: ah, I see that my solution nr 2 will not work, there can be only one subdirectory under
apps
. So no<config>/pyscript/apps/dash/someapp/__init__.py