lawtancool / pyControl4

Python 3 asyncio package for interacting with Control4 systems
https://lawtancool.github.io/pyControl4
Apache License 2.0
38 stars 16 forks source link

Websockets support #14

Closed lorddaren closed 2 years ago

lorddaren commented 2 years ago

Since we missed the last release for the new websockets version (which pushed the next release until February). Is it possible to publish the websockets version to HACS so that we can have a larger beta adoption to test things out? I would like to see how things are operating so I can begin working on adding in additional devices (locks, and sensors) which may also need a larger discussion.

Thanks again for providing the time and energy to the library, I know more than anyone else that it can be really tough to keep up.

mellis commented 2 years ago

Is it ready at all? Seems to still be in PR https://github.com/home-assistant/core/pull/60465

Looks to have been idle for a while, I assume they have been busy.

lawtancool commented 2 years ago

Hi everyone! Thanks for your continued interest in this project!

I have been testing the code in https://github.com/home-assistant/core/pull/60465 for a week now, but there's still one big thing that needs to be fixed:

Does anyone have an idea as to how we can get Home Assistant to update our token every 24h (like on a schedule/before a certain expiry date)?

lawtancool commented 2 years ago

Hi @mellis @Xorso,

Please try adding this repo https://github.com/lawtancool/hass-control4 to your HACS as a custom repository.

See https://hacs.xyz/docs/faq/custom_repositories for instructions on how to do that.

I have added code to automatically update the director token before it expires, please test and let me know if you can still turn on/off lights 24h after restarting Home Assistant.

lorddaren commented 2 years ago

@lawtancool Thank you! I thought I had that worked that out on a websocket disconnect to retrieve the director token. I will definitely get this installed and start testing. I would love to see it be a part of the core. Thanks again for the time and effort.

mellis commented 2 years ago

I installed HACS and the integration from the repository. Now all of the devices from the Control4 integration have the status "The device is disabled by Config entry.". Am I missing some necessary yaml configuration?

edit: never mind, I realized I could just go into the edit section for the device in the UI and re-enable them πŸ€¦β€β™‚οΈ. I'll let you know if I have any auth issues in the next day or so.

lawtancool commented 2 years ago

@Xorso @mellis Could you both update the integration through HACS? I just pushed a fix for the token refresh, as it wasn't properly implemented earlier.

mellis commented 2 years ago

@lawtancool downloaded the update πŸ‘. Should I disable the option to poll devices now as well?

3023E72B-E2F4-41C6-BC9F-0362526F4431

lawtancool commented 2 years ago

@lawtancool downloaded the update πŸ‘. Should I disable the option to poll devices now as well?

@mellis There's no need to change that setting - I honestly don't even know what that would do, since we don't use polling at all anymore. πŸ˜…

lorddaren commented 2 years ago

Just updated. Yeah polling will need to be stripped out (unless we want to use it as a fallback at some point). I am hoping this is going to make it easier to get other entities in places as well (real time sensor data, motion detection, and maybe even some energy usage from the newer switches)

Xesyliad commented 2 years ago

Should this method also expose non-light relays that are part of the EA3, for example garage door switch, and reed switches?

lorddaren commented 2 years ago

@Xesyliad I hope to be able to work on this now that we have it running out of HACS. It should allow for better testing and additional entity types.

@lawtancool I have been running past 24 hours and things are running smooth. I need to kick up my logging into debug but I feel like the tokens are refreshing. Are you still seeing issues?

mellis commented 2 years ago

I also haven’t seen any token issues here.

lawtancool commented 2 years ago

After a few more days of continuous testing, I have discovered that Home Assistant stops receiving WebSockets updates after around 48 hours since the last restart. This is because, while we are refreshing the tokens every 24h, we aren't restarting the WebSocket connection to use the new tokens, and eventually the Control4 Director sends a BadToken error to us over WebSocket.

I'll have to find some time to figure out how to restart the WebSocket connection when the tokens are refreshed. It might not be easy/elegant, since the current code design would require the callbacks for each entity to be re-registered, essentially forcing a full re-setup of the Home Assistant integration and entities every 24h.

lawtancool commented 2 years ago

@mellis @Xorso I've updated the HACS integration to fix the Websockets token refresh, please update and let me know if Home Assistant continues to receive state updates without logging errors after 24-48hours.

mellis commented 2 years ago

@lawtancool i updated yesterday, will let you know if I notice anything.

lorddaren commented 2 years ago

So far things have been running smooth. I am past the 48 hour mark. Are you guys seeing anything?

mellis commented 2 years ago

Things are all fine here, I also don't see any errors related to the c4 integration in the log.

Xesyliad commented 2 years ago

Not experiencing any issues so far.

lawtancool commented 2 years ago

Hi everyone!

I've updated the HACS integration again. Please update and let me know how it goes!

It will take a while for the Home Assistant maintainers to merge my code into the core, but I think the HACS integration is pretty much feature complete now.

Changes:

Xesyliad commented 2 years ago

Does this mean that development may soon begin on adding features, for example relay support?

lorddaren commented 2 years ago

@lawtancool Thanks so much for all the work! Maybe we should chat in another thread to see what integration to tackle next?

lawtancool commented 2 years ago

@Xorso Yes, let's create another issue to discuss further integration work with different devices. This issue will be left open to discuss the Websockets HACS component.

@Xesyliad pyControl4 already has support for relays, but there's no Home Assistant code for it.

The problem with relay support is that my Control4 system doesn't have any relays in it, making it impossible for me to test a relay integration. If you/someone else has a relay and is willing to develop and test the integration, they can always open a PR with the Home Assistant core directly. I would be glad to review such a PR, but I wouldn't be able to verify the actual functionality.