Skip to content

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

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.

@vlaraort
Copy link

There is no progress in this? 🫠

It's a really interesting improvement

@dnestico
Copy link

Wish this could be merged....

@mrdanielps
Copy link
Author

Sorry for the long wait!
I'm currently working on an improved version written in Glance that builds on the great work by @TimoPtr with the new ToDo widget.

I hope to have it ready soon enough, but for those interested, here's a sneak peek.

glance-grid-widget.mp4

Adds a new widget that allows to configure multiple actions.

Fixes home-assistant#1193 home-assistant#4549
Comment on lines +2 to +17
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:minWidth="40dp"
android:minHeight="40dp"
android:targetCellWidth="4"
android:targetCellHeight="2"
android:updatePeriodMillis="86400000"
android:description="@string/widget_grid_desc"
android:previewImage="@drawable/widget_example_grid"
android:initialLayout="@layout/glance_default_loading_layout"
android:configure="io.homeassistant.companion.android.widgets.grid.config.GridWidgetConfigureActivity"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen"
android:widgetFeatures="reconfigurable"
tools:ignore="UnusedAttribute">
</appwidget-provider> No newline at end of file

Check failure

Code scanning / Android Lint

Unused resources Error

The resource R.xml.grid_widget_info appears to be unused
@vlaraort
Copy link

This is awesome! Also like the idea of the reload button to prevent excessive connections to check status. Can't wait!

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.

5 participants