Add low battery alerts using a websocket connection #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds low-battery notifications to Controller Tools.
This is done via a new websocket API. The frontend will create a permanent ws connection to the backend when decky initializes the plugin. But if it gets disconnected, it will reconnect after 10 secs. When the client opens the ws connection, the backend will start a background thread that checks every 60s the status of controllers and then fires an alert if we have yet to send one in the last 60m. That background thread is killed if the ws connection is closed.
I've additionally added a new settings section in the UI to disable notifications, this is primarily to silence alerts if there is a bug. Settings are powered by the new
SettingsServicethat uses a JSON file as its backing store. We store it in /home/deck/homebrew/settings/controller-tools.json if running on the deck, or /tmp/controller-tools.json for local dev.Finally, I added a feature to inject a fake controller for testing while running in debug mode. You need to create a JSON equivalent of the
Controllerstruct in /tmp/fake_controller.json (use camelCase for field names), and the api::controllers() will pick it up and inject it into the response Vec. I used this to verify alerts by adding a controller with low battery and in the discharging state.closes #10