-
Notifications
You must be signed in to change notification settings - Fork 119
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isDefined } from '../../helpers'; | ||
import { EVariableType, TimeVariable } from '../../types'; | ||
|
||
export function timeVariable(...config: Partial<TimeVariable>[]) { | ||
//factory function to create TimeVariable from configuration | ||
|
||
const name = config.map(e => e.name).filter(isDefined); | ||
|
||
const variable: TimeVariable = { | ||
type: EVariableType.Time, | ||
name: name.length ? name.reduce((_acc, val) => val) : undefined, | ||
enable_seconds: config.some(e => e.enable_seconds), | ||
}; | ||
return variable; | ||
} | ||
|
||
export function timeVariableDisplay(value: any, _variable: TimeVariable): string { | ||
return String(value); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,12 @@ export class SchedulerEditorTime extends LitElement { | |
|
||
render() { | ||
if (!this.hass || !this.config || !this.entities || !this.actions) return html``; | ||
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))})`; | ||
} | ||
Comment on lines
+96
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
return html` | ||
<div class="content"> | ||
<div class="header"> | ||
|
@@ -102,7 +108,7 @@ export class SchedulerEditorTime extends LitElement { | |
${!this.timeslots | ||
? html` | ||
${this.getVariableEditor()} ${this.renderDays()} | ||
<div class="header">${this.hass.localize('ui.dialogs.helper_settings.input_datetime.time')}</div> | ||
<div class="header">${timePickerHeader}</div> | ||
<time-picker | ||
.hass=${this.hass} | ||
.value=${this.schedule.timeslots[0].start} | ||
|
@@ -150,6 +156,10 @@ export class SchedulerEditorTime extends LitElement { | |
`; | ||
} | ||
|
||
getEntityName(entity: EntityElement) { | ||
return entity.name || this.hass!.states[entity.id].attributes.friendly_name || computeEntity(entity.id); | ||
} | ||
|
||
renderSummary() { | ||
if (!this.entities || !this.actions) return html``; | ||
return html` | ||
|
@@ -159,11 +169,7 @@ export class SchedulerEditorTime extends LitElement { | |
entity => html` | ||
<div> | ||
<ha-icon icon="${PrettyPrintIcon(entity.icon)}"> </ha-icon> | ||
${capitalize( | ||
PrettyPrintName( | ||
entity.name || this.hass!.states[entity.id].attributes.friendly_name || computeEntity(entity.id) | ||
) | ||
)} | ||
${capitalize(PrettyPrintName(this.getEntityName(entity)))} | ||
</div> | ||
` | ||
)} | ||
|
@@ -395,11 +401,15 @@ export class SchedulerEditorTime extends LitElement { | |
return actions.map(action => { | ||
return Object.entries(this.actions!.find(e => compareActions(e, action, true))!.variables!).map( | ||
([field, variable]) => { | ||
let header: string = variable.name || PrettyPrintName(field); | ||
if (header.toLowerCase() === 'time') { | ||
const entity = this.entities?.[0]; | ||
if (entity) header += ` (${PrettyPrintName(this.getEntityName(entity))})`; | ||
} | ||
Comment on lines
+404
to
+408
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
return html` | ||
<div class="header"> | ||
${variable.name || PrettyPrintName(field)} | ||
</div> | ||
<div class="header">${header}</div> | ||
<scheduler-variable-picker | ||
.hass=${this.hass} | ||
.variable=${variable} | ||
.value=${action.service_data ? action.service_data[field] : null} | ||
@value-changed=${(ev: CustomEvent) => | ||
|
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 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.