bob1de / hass-apps

Some useful apps and snippets to empower Home Assistant and AppDaemon even more.
Apache License 2.0
86 stars 23 forks source link

Add HACS Support #45

Open niemyjski opened 4 years ago

niemyjski commented 4 years ago

It would be great if we supported installation and updates via HACS. It basically comes down to moving the source into a known folder. https://hacs.xyz/docs/publish/appdaemon

bob1de commented 4 years ago

Hi,

Thanks for the idea.

However, I don't think it's that simple. Hass-apps not only consists of files to place in the apps directory, it's rather a Python package you install from PyPi. Hass-apps consists of multiple modules and packages with sub-packages, and it has dependencies that need to be installed alongside. Since AppDaemon doesn't support specifying a fully qualified module name to use for an app (like hass_apps.loader - note the dot) and it messes around with sys.path to get it's importing working the way it does, this is probably not possible.

So I'll let this issue open for now until I have time to inspect the internals in more detail.

Best regards Robert

xaviml commented 4 years ago

Hi @efficiosoft,

I have an AppDaemon app in HACS and I just checked the way your project works. I think this project is easy to publish on HACS and it would be a great idea. In order to publish it on HACS, you will just need to place the hass_apps_loader.py in apps/<any name you want to put>/hass_apps_loader.py in the root of your project. Then, you will need to state in the documentation that hass-apps package needs to be added in the python_packages in the case of the appdaemon addon 4.x. Otherwise, follow the instructions you have in here.

When installing an appdaemon app from HACS, it just copies the content from apps in the repository to the local apps folder and that is all, so basically it does what you describe in here.

The only difference that this app will have from the others is that the logic is on the hass-apps package instead of having it inside the appdaemon folder (as usual). This means that if you upgrade the package, we will just need to restart appdaemon server so it fetches the latest version. This is the only downside to consider if publishing it to HACS or not.

Anyway, I just wanted to mention how you could publish this to HACS.

P.S. This is an amazing project, I am about to set up a bunch of thermostats around the house and this will come in handy to schedule the times. Thank you!

bob1de commented 4 years ago

Hi,

In order to publish it on HACS, you will just need to place the hass_apps_loader.py in apps//hass_apps_loader.py in the root of your project. Then, you will need to state in the documentation that hass-apps package needs to be added in the python_packages in the case of the appdaemon addon 4.x.

That's the point. It seems to bring more confusion than benefit if people need to ensure the hass_apps package is installed and at the version they want it to be while HACS shows them all the releases and updates which, in fact, are not related to the installed hass_apps package.

This could be supported properly if AppDaemon didn't try to import app modules from subdirectories at all and people could just specify the module to import in normal import notation, aka package.subpackage.module instead of just module and then hoping that no second module.py does exist somewhere else. Then, the whole hass_apps package directory could cleanly be published via HACS.

bob1de commented 4 years ago

Ah, and HACS provides no way of defining requirements that need to be installed from PyPi... which is another showstopper, at least for AppDaemon apps since they cannot use HA's dependency installation mechanism.

xaviml commented 4 years ago

This could be supported properly if AppDaemon didn't try to import app modules from subdirectories at all and people could just specify the module to import in normal import notation, aka package.subpackage.module instead of just module and then hoping that no second module.py does exist somewhere else. Then, the whole hass_apps package directory could cleanly be published via HACS.

I agree with this. This would be very handy. The other option you would have is to pack all your repository inside apps/hass-apps/*. This way everything would be in the appdaemon folder, but it would not be used as a package, which is a downside.

bob1de commented 4 years ago

The other option you would have is to pack all your repository inside apps/hass-apps/*. This way everything would be in the appdaemon folder, but it would not be used as a package, which is a downside.

That won't work because then, all relative intra-package imports will fail and, even worse, you are not allowed to have two files with same name anywhere.

IMHO, the import mechanism is a fundamental design flaw that can't be corrected easily without loosing backwards compatibility.

xaviml commented 4 years ago

That won't work because then, all relative intra-package imports will fail

This is true, it does not accept relative paths, just absolute paths (from apps/app_folder/)

you are not allowed to have two files with same name anywhere.

I don't think this is true. You can take a look at my app, I have several __init__.py and as long as they are in different folders, they can be called with the same name. At least, I haven't had any issues with it.

xaviml commented 4 years ago

Anyhow, thanks for considering it. Even though this is not in HACS, I will use it anyway, thank you!