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

Multi-action grid widget implementation #4783

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mrdanielps
Copy link

@mrdanielps mrdanielps commented Nov 3, 2024

Summary

Adds a new widget that allows the user to configure multiple actions in a grid. It's somewhat based on the existing ButtonWidget.

The widget is responsive, adjusting the number of columns based on size, and becomes scrollable when it doesn't fit all the actions.

Fixes #1193, #4549

Screenshots

Dynamic colors - light
Screenshot_20241102_185606

Dynamic colors - dark
Screenshot_20241102_185620

API <31
Screenshot_20241102_185635

Configuration and resizing

Screen_recording_20241102_185549.mp4

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#1132

Any other notes

I've limited the scope of this PR for easier review, hence the draft status, but I will update it based on feedback.
The main features I think are necessary before merging are auto-completion for icons and action data, feedback when the button is pressed, and maybe entity states.

Additionally, the existing button widget could be updated to reflect the UI changes and share some of their code. However, I didn't want to change too much considering a proposal exists to refactor this code (#4640).

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mrdanielps

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@bgoncal
Copy link
Member

bgoncal commented Nov 4, 2024

Looking great! Will the state of each item reflect in realtime? for example if the light is ON

@mrdanielps
Copy link
Author

Looking great! Will the state of each item reflect in realtime? for example if the light is ON

Not yet. As mentioned in the additional notes, I limited the scope of this PR for the initial review, just to get some feedback. Although looking at the entity widget implementation, I see it should be pretty straightforward to add, so I'll look into as soon as I can.

@bgoncal
Copy link
Member

bgoncal commented Nov 5, 2024

How often can a widget update in Android? In iOS the minimum auto-refresh is 15 minutes (besides other techniques like updating through push notification trigger)

@mrdanielps
Copy link
Author

It's actually quite similar on Android. The fastest auto-refresh is 30 minutes, but AFAIK anything that wakes up the app can manually trigger an update, like broadcasts or push notifications. Widget interactions can also update it, so pressing the button will allow for the state to be updated immediately.

@dshokouhi
Copy link
Member

The template widget updates instantly for me, there is no delay there. Our Template widget and entity state widget use a websocket subscription to update instantly.

@bgoncal
Copy link
Member

bgoncal commented Nov 5, 2024

@dshokouhi so you keep a websocket connection all the time for the widget? 🪫😭
(We do that in iOS for local push too hahaha)

@dshokouhi
Copy link
Member

so you keep a websocket connection all the time for the widget? 🪫😭

For widgets only when the screen turns on, then we stop the connection when the screen turns off. Its our best effort to keep them as up to as possible while not draining too much battery

(We do that in iOS for local push too hahaha)

yup same for local push we never stop the connection and also send a ping to the server every 30 seconds to ensure its active and current.

@mrdanielps
Copy link
Author

Looking great! Will the state of each item reflect in realtime? for example if the light is ON

Done!

Screen_recording_20241111_005218.webm

@@ -58,6 +58,7 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.media)
api(libs.core.remoteviews)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be included in the common module? I dont seem to see it used in any common module files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's only actually needed in :app and :automotive. I've now moved the declaration to each module.

@dshokouhi
Copy link
Member

Gave this PR a quick test run. I think you have captured the obvious missing features like auto complete, ideally the behavior for each action should mimic the existing button widget with how fields are populated. I think that will match general user expectation. For example that widget handles when a custom integration provides incomplete action data and also when a user provides invalid action data. Looking forward to seeing this PR progress!

@mrdanielps
Copy link
Author

ideally the behavior for each action should mimic the existing button widget with how fields are populated. I think that will match general user expectation. For example that widget handles when a custom integration provides incomplete action data and also when a user provides invalid action data.

I see, I was thinking of implementing it like the entity widget, which only takes an ID, but I'll certainly take that into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grid-based multi-action scene control widget.
3 participants