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

Added support for Home Assistant #178

Closed
wants to merge 0 commits into from

Conversation

gensyn
Copy link

@gensyn gensyn commented Feb 20, 2024

A while ago I added support for Home Assistant to the original repository, which was pretty much dead by that time. So I did it mainly for myself - until I found this fork and thought others might also want to control their Home Assistant instance with a Stream Deck.
I have now adapted my code to the changes in the new repository and it's more or less working as it did with the old version. Here are some notes on my changes:

  • You need to have websockets installed for this to work as a well as websocket_api enabled in your Home Assistant configuration.
  • I am really unhappy with how the information for Home Assistant is stored. For now, the information is in the Stream Deck settings. So in theory you could enter different Home Assistant instances per Stream Deck but I don't think that many people would have a use case for that. I would much rather save this stuff as global information outside the scope of each Stream Deck, but for that I would have had to change the structure of the state object and the config file, which I was not yet willing to tackle. In it's current state, the Home Assistant info is pulled from the first registered Stream Deck - anything else is ignored.
  • When the connection to Home Assistant is lost (e.g. Home Assistant is restarted), the connection will not automatically be restored. You will however be implicitly reconnected the next time you try to call a service.
  • Two websocket connections are created; one for sending commands to Home Assistant, one that perpetually listens for changes to entities that you are controlling with your Stream Deck. It is possible to put sensor values on a button and the value will be updated, if it changes in Home Assistant.
    • This does not work after the connection to Home Assistant is lost. I was not yet successful in restoring this listening websocket.
  • A lot of my code feels hacky and I hope together we can clean this up and iron out some bugs. I also hope, that many of you find this addition useful - I love being able to control Home Assistant through my Stream Deck.

@gensyn
Copy link
Author

gensyn commented Feb 20, 2024

If anyone can tell me why tests fail with "ModuleNotFoundError: No module named 'websockets'", I would really appreciate it. I understand the error, but I don't know how to fix it for testing purposes.

@coolapso
Copy link
Member

coolapso commented Feb 20, 2024

Hi! thanks a lot!

Even though I really like the concept, I have my doubts about this being part of the main application or not 🤔

The way I see it, the application should not be opinionated and should not be responsible for the integrations ...

This should be done either by scripts that interact with streamdeckc and commands you execute thru the buttons

OR probably the better option, plugins!!

I see here a really valid use case for it. The thread linked doesn't have much as initial talks have been taken in the background, however in the current state of the code base its very hard to implement a plugin solution.

@rkmax @ajbucci what do you think about this?

As for why the tests are failing, for now the answer is simple ...

You introduced new dependencies ,
The CI Environment starts clean, therefore you need to add the new dependency to the dependency for it to be installed :)

Some hints for you:

@ajbucci
Copy link
Member

ajbucci commented Feb 20, 2024

This would be great as a plugin, if we only had plugin support! I am leaning towards not including this at the moment. I think we should wait until we either:

  1. Decide we're comfortable continuing with Python and add plugin support to the current Python implementation
  2. Decide to commence a rewrite with plugin support as a main goal

Then I think this would be a great addition to the plugin ecosystem.

@coolapso
Copy link
Member

Then I think this would be a great addition to the plugin ecosystem.

Strongly agree would love to have the streamdeck making some great magic with my homeassistant!

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Attention: 443 lines in your changes are missing coverage. Please review.

Comparison is base (1797803) 61.47% compared to head (5ecb0ea) 54.67%.
Report is 10 commits behind head on main.

Files Patch % Lines
streamdeck_ui/homeassistant.py 16.84% 316 Missing ⚠️
streamdeck_ui/api.py 34.57% 70 Missing ⚠️
streamdeck_ui/gui.py 43.02% 49 Missing ⚠️
streamdeck_ui/display/image_filter.py 79.48% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
- Coverage   61.47%   54.67%   -6.80%     
==========================================
  Files          24       25       +1     
  Lines        2676     3294     +618     
==========================================
+ Hits         1645     1801     +156     
- Misses       1031     1493     +462     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

None yet

3 participants