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

Add the time domain (time entities) to the list of standard configuration actions #808

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pdcastro
Copy link
Contributor

@pdcastro pdcastro commented Mar 25, 2024

This PR addresses issue #807. Please check that issue’s description for background information (use cases, justification).

Screenshots of what this PR achieves

Scheduler Card Configuration — Included Entities
Before this PR, time entities were not listed — there wasn’t a ‘time’ row in the screenshot below. After this PR, the ‘time’ row is listed, allowing time entities to be selected.
Scheduler Card Configuration - Entities - Time

New Schedule - Entity Editor - Time Entity
New Schedule - Entity Editor

New Schedule - Time Editor - Time Entity - Set Value
New Schedule - Time Editor

New Schedule - Time Editor - Time Entity - Make Scheme
New Schedule - Time Editor - Scheme

Scheduler Card - Configured Entities - Time Entity
Scheduler Card - Configured Entities

Comment on lines +96 to +101
let timePickerHeader = '';
if (!this.timeslots) {
timePickerHeader = this.hass.localize('ui.dialogs.helper_settings.input_datetime.time');
if (this.entities?.[0].id.startsWith('time'))
timePickerHeader += ` (${localize('ui.panel.common.title', getLocale(this.hass))})`;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This timePickerHeader logic changes the section title from "TIME" to "TIME (SCHEDULER)" to help disambiguate between the two time sections — see red arrows in the screenshots below. This only applies when the selected entity is a time entity. If the user selected a different entity, say switch, the section title remains as before, i.e. simply "TIME".

Without the timePickerHeader logic:
New Schedule - Time Editor - ambiguous highlight

With the timePickerHeader logic:
New Schedule - Time Editor - highlight

Comment on lines +404 to +408
let header: string = variable.name || PrettyPrintName(field);
if (header.toLowerCase() === 'time') {
const entity = this.entities?.[0];
if (entity) header += ` (${PrettyPrintName(this.getEntityName(entity))})`;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This header logic changes the section title from "TIME" to "TIME (<entity name>)" to help disambiguate between the two time sections — see red arrows in the screenshots below. This only applies when the selected entity is a time entity. If the user selected a different entity, say switch, the section title remains as before (not including the entity name).

Without the header logic:
New Schedule - Time Editor - ambiguous highlight

With the header logic:
New Schedule - Time Editor - highlight

Comment on lines +99 to +107
return html`
<ha-time-input
.enableSecond=${variable.enable_seconds}
.value=${value}
.locale=${this.hass.locale}
@value-changed=${this.listVariableUpdated}
></ha-time-input>
<div class="key">${variable.enable_seconds ? 'Hours:Minutes:Seconds' : 'Hours:Minutes'}</div>
`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The choice of the <ha-time-input> component can be argued. My reasoning for not using the <time-picker> component (which is used to set / edit the scheduler time) was simply to visually differentiate between the two time sections (see other comments). Users would be used to the <time-picker> component for setting the scheduler time and they would also be used to the <ha-time-input> component for editing HA time entities.

@pdcastro pdcastro mentioned this pull request Mar 26, 2024
@nielsfaber
Copy link
Owner

I'm impressed with your efforts, the PR looks pretty good to me.
Sadly, the fact that you had to touch 20+ files to implement this feature only emphasises that the code is in need of optimisation.
As said, I am currently working on a rewrite of the code.
For this reason I think we have to park this PR for a while (I am not adding new features to the current code base anymore).
I am hopeful that it can be 'ported' to the new version without too much extra effort.
The new version should be 'feature-complete' within the next month, we can continue from there.
A general comment (for future contribution): I think it's helpful to open a feature request to discuss/align on a new feature before starting on the implementation. This reduces the risk of writing code that may not be adopted in the project.
My apologies for putting your contribution on hold.

@pdcastro
Copy link
Contributor Author

[…] For this reason I think we have to park this PR for a while […]

That’s all right. I take comfort in knowing that you seem happy to incorporate this feature in principle. I had originally planned to discuss it before any implementation, 😇 and I thought it should include “photoshopping” what the time editor screen might look like. But then I thought: “Why don’t just do a quick hack of the time editor screen on its own, just to load a <ha-time-input> component there?” “Would that even be possible?” “Do custom cards have the ability of instantiating just any HA frontend component?” ”How would I even go about hacking it?” I actually had so many questions as I had never worked on a frontend project before, and I was really curious. So I just started playing with the code a bit, not planning on any large implementation, but each small step led to more questions and further small steps to answer those questions... “Now I’ve come this far, might as well finish it!” I had no idea that the final solution would involve touching so many files, honestly I initially thought I’d have to change “just a few HTML templates” — because that’s what a custom card is, right? 😄 How hard could that possibly be? 😅

By the way, I now appreciate so much more the effort that you put in creating this custom card. There is so much logic in it that end users are just oblivious to. On behalf of clueless end users, thank you! 🙏

Meanwhile, I am already using this feature through my fork of your repo, so in any event I am already benefiting from it. 🙂

Copy link

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Apr 26, 2024
@pdcastro
Copy link
Contributor Author

Rebased on the main branch in order to remove the ‘stale’ label and to fix merge conflicts.

@github-actions github-actions bot removed the Stale label Apr 27, 2024
Copy link

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label May 27, 2024
@pdcastro
Copy link
Contributor Author

Bump

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

Successfully merging this pull request may close these issues.

None yet

2 participants