-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Automations & Scripts tables: show descriptions #28592
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
base: dev
Are you sure you want to change the base?
Automations & Scripts tables: show descriptions #28592
Conversation
|
I'll note that descriptions can be markdown, so rendering that inside of a plain text label might look pretty wrong without using a markdown renderer in some cases. |
|
Will think about it, thanks for the remark. |
| export const setEntityDescription = ( | ||
| hass: HomeAssistant, | ||
| entity_id: string, | ||
| descriptions: EntityDescription[], | ||
| getEntityConfigFunc: GetEntityConfigFunc | ||
| ) => { | ||
| getEntityConfigFunc(hass, entity_id).then((result) => { | ||
| let entry; | ||
| if (descriptions.length > 0) { | ||
| entry = descriptions.find((_entry) => _entry.entity_id === entity_id); | ||
| } | ||
| if (entry) { | ||
| entry.description = result.config.description ?? undefined; | ||
| } else { | ||
| descriptions.push({ | ||
| entity_id: entity_id, | ||
| description: result.config.description ?? undefined, | ||
| }); | ||
| } | ||
| }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extremely weird pattern. It should be an async function that returns data instead of modifying descriptions directly. The descriptions.push also won't trigger a render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to prepare a list of descriptions and then use it. I believed that acquiring a description takes some time - so wanted to get all descriptions right after a view is created - to have them ready by a moment of 1st render() call.
In reality, these descriptions are not ready yet by the 1st render() call - but they are ready by the 2nd call (do not recall exactly a difference between these two calls). So, I accepted the fact that anyway descriptions are acquired.
But I understand that I have not provided 100% guarantee that all descriptions will be ready by that 2nd render() call moment.
Also, these descriptions are acquired only once. To update them, you need to update a page (F5). Also, descriptions are updated for a NEW added entry (automation or script). Compare to memoize(): if anything is changed in states object or in registry, the memoized property is updated - and causes a new render() call. But descriptions are not a part of a states object or registry. So, I could not to monitor these descriptions asynchronously and then render() when needed. Finally, I decided that this is a rare case and it is not critical to track descriptions.
Sorry for probably being dumb, have a very little experience with async stuff in JS.
| this.automations.forEach((automation) => | ||
| setEntityDescription( | ||
| this.hass, | ||
| automation.entity_id, | ||
| this._fetchedDescriptions, | ||
| getAutomationStateConfig | ||
| ) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would fire a websocket request for each automation. Don't know if core supports it but we should batch this or just add the data in the original fetch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a list of possible requests somewhere?
| type GetEntityConfigFunc = ( | ||
| hass: HomeAssistant, | ||
| entity_id: string | ||
| ) => Promise<GetEntityConfigFuncResult | any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any shouldn't be needed here
|
@ildar170975 I get the idea, but a description most likely will be a long string or even markdown text, which is just not possible to display in a good way in a table. Tables are good at displaying small bits of data, for more I'd stay with showing it in the detailed view of an automation or anything other for that matter. This gets even more impossible to display on mobile. |
|
@marcinbauer85 Update: Desktop PC (1920x1200):
iPhone 15 (393x852) - descriptions are nicely displayed:
Some iPad (1024x768):
Next, an example with Markdown:
I agree that additional words like "Description" here are useless.
|





Breaking change
Proposed change
Initial discussion:
#28561 (comment)
Results:
Note that descriptions containing a markdown are "simplified" - the initial markdown like


is converted to
Tested with 100 automations stored in 10 yaml files, 100 scripts stored in 10 yaml files, seems to work rather fast.
WARNING: if a description is changed in a background (for example, if it was changed either in another browser tab or was edited in yaml file), this change will not be visible on a page until a re-render of the page.
This is my 1st experience with adding a new dependency into HA, so please tell me if I am wrong.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: