e.id).forEach((e,i)=>{this.updateActiveEntryAction(Va(e,t),i)}):this.entities.forEach((e,t)=>{this.updateActiveEntryAction(null,t)})}getVariableEditor(){if(null===this.activeEntry||!this.actions)return N``;const e=[];return this.schedule.timeslots[this.activeEntry].actions.forEach(t=>{t=Qe(t,"entity_id"),this.actions.find(e=>us(e,t,!0)&&Object.keys(e.variables||{}).length)&&(e.some(e=>st(e,t))||e.push(t))}),e.map(e=>Object.entries(this.actions.find(t=>us(t,e,!0)).variables).map(([t,i])=>N`
+
+ this.entities.forEach((i,s)=>{this.updateActiveEntryAction({service_data:{[t]:e.detail.value}},s)})}
+ >
+ ${this.hass.localize("ui.dialogs.helper_settings.input_select.no_options")}
+
+ `))}selectDays(e){const t=e.target.value;let i=this.schedule.weekdays;if(Object.values(Ue).includes(t))switch(t){case Ue.Daily:i=["daily"];break;case Ue.Workday:i=["workday"];break;case Ue.Weekend:i=["weekend"];break;case Ue.Custom:i=[]}else i=t;this.schedule=Object.assign(Object.assign({},this.schedule),{weekdays:i})}cancelClick(){const e=new CustomEvent("cancelClick");this.dispatchEvent(e)}saveClick(){const e=new CustomEvent("saveClick",{detail:this.schedule});this.dispatchEvent(e)}optionsClick(){const e=new CustomEvent("optionsClick",{detail:this.schedule});this.dispatchEvent(e)}editActionClick(){const e=new CustomEvent("editActionClick",{detail:this.schedule});this.dispatchEvent(e)}async deleteClick(e){const t=e.target;if(await new Promise(e=>{Me(t,"show-dialog",{dialogTag:"dialog-delete-confirm",dialogImport:()=>Promise.resolve().then((function(){return Ha})),dialogParams:{cancel:()=>{e(!1)},confirm:()=>{e(!0)}}})})){const e=new CustomEvent("deleteClick");this.dispatchEvent(e)}}};Fa.styles=r`
+ ${ts}
+ div.summary {
+ display: grid;
+ grid-template-columns: 1fr max-content 1fr;
+ grid-template-areas: 'entity arrow action';
+ grid-auto-flow: column;
+ grid-gap: 5px;
}
- function name(item) {
- var _a;
- return ((_a = item.name) === null || _a === void 0 ? void 0 : _a.trim()) || item.value || item.id || '';
- }
- function value(item, index) {
- return item.id || item.value || index;
- }
- let ButtonGroup = class ButtonGroup extends h$2 {
- constructor() {
- super(...arguments);
- this.items = [];
- this.value = null;
- }
- render() {
- if (!this.items.length) {
- return T `
-
-
-
- `;
- }
- return this.items.map((val, key) => this.renderButton(val, key));
- }
- renderButton(item, index) {
- const selection = Array.isArray(this.value) ? this.value : [this.value];
- const id = value(item, index);
- return T `
- this.selectItem(id)}
- >
- ${item.icon
- ? T `
-
- `
- : ''}
- ${PrettyPrintName(name(item))}
-
- `;
- }
- selectItem(val) {
- if (!Array.isArray(this.value)) {
- if (val == this.value) {
- if (this.optional)
- this.value = null;
- else
- return;
- }
- else
- this.value = val;
- }
- else if (!this.multiple) {
- this.value = this.value.includes(val) ? [] : Array(val);
- }
- else {
- let value = Array.isArray(this.value) ? [...this.value] : [];
- if (value.includes(val)) {
- if (this.min !== undefined && value.length <= this.min)
- return;
- value = value.filter(e => e != val);
- }
- else
- value.push(val);
- this.value = value;
- }
- const selection = Array.isArray(this.value)
- ? this.value.map(e => this.items.find((v, k) => value(v, k) == e))
- : this.value !== null
- ? this.items.find((v, k) => value(v, k) == this.value)
- : null;
- const myEvent = new CustomEvent('change', { detail: selection });
- this.dispatchEvent(myEvent);
- }
- };
- ButtonGroup.styles = commonStyle;
- __decorate([
- e$3({ type: Array })
- ], ButtonGroup.prototype, "items", void 0);
- __decorate([
- e$3()
- ], ButtonGroup.prototype, "value", void 0);
- __decorate([
- e$3({ type: Number })
- ], ButtonGroup.prototype, "min", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], ButtonGroup.prototype, "optional", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], ButtonGroup.prototype, "multiple", void 0);
- ButtonGroup = __decorate([
- n$4('button-group')
- ], ButtonGroup);
-
- let SchedulerEditorCard = class SchedulerEditorCard extends h$2 {
- constructor() {
- super(...arguments);
- this.selectedEntities = [];
- this.multipleEntity = false;
- this.scheduleEntities = [];
- this.timeSchemeSelected = false;
- }
- async firstUpdated() {
- this.scheduleEntities = (await fetchSchedules(this.hass)).map(e => e.entity_id);
- if (this.entities && this.entities.length) {
- const group = this.getGroups().find(group => group.entities.find(e => e == this.entities[0].id));
- if (!group)
- return;
- this.selectedGroup = group;
- this.selectedEntities = [...this.entities.map(e => e.id)];
- this.multipleEntity = this.selectedEntities.length > 1;
- }
- if (this.schedule) {
- if (this.schedule.timeslots.every(e => e.stop))
- this.timeSchemeSelected = true;
- else {
- const actions = unique(flatten(this.schedule.timeslots.map(e => e.actions)));
- const matchedActions = this.getActionsForEntity().filter(e => actions.some(a => compareActions(a, e, true)));
- if (matchedActions.length == 1)
- this.selectedAction = matchedActions[0];
- }
- }
- }
- getGroups() {
- if (!this.hass || !this.config)
- return [];
- const entities = computeEntities$1(this.hass, this.config).filter(e => g$1(e) !== 'switch' || !this.scheduleEntities.includes(e));
- const groups = entityGroups(entities, this.config, this.hass);
- groups.sort(sortAlphabetically);
- return groups;
- }
- getEntitiesForGroup() {
- if (!this.selectedGroup || !this.hass || !this.config)
- return [];
- const entities = this.selectedGroup.entities.map(e => parseEntity(e, this.hass, this.config));
- entities.sort(sortAlphabetically);
- return entities;
- }
- getActionsForEntity() {
- if (!this.hass || !this.config || !this.selectedEntities.length)
- return [];
- const actions = computeActions(this.selectedEntities, this.hass, this.config).map(e => Object.assign(e, { name: computeActionDisplay(e) }));
- actions.sort(sortAlphabetically);
- return actions;
- }
- render() {
- if (!this.hass || !this.config)
- return T ``;
- const groups = this.getGroups();
- if (groups.length == 1 && !isEqual(this.selectedGroup, groups[0]))
- this.selectGroup(groups[0]);
- const entities = this.getEntitiesForGroup();
- if (entities.length == 1 && this.selectedEntities[0] !== entities[0].id)
- this.selectEntity(entities[0].id);
- const actions = this.getActionsForEntity();
- return T `
-
-
-
-
- isEqual(e, this.selectedGroup))}
- @change=${(ev) => this.selectGroup(ev.detail)}
- >
- ${localize('ui.panel.entity_picker.no_groups_defined', getLocale(this.hass))}
-
-
-
- this.selectEntity(ev.target.value)}
- ?multiple=${this.multipleEntity}
- ?optional=${true}
- >
- ${!this.selectedGroup
- ? localize('ui.panel.entity_picker.no_group_selected', getLocale(this.hass))
- : localize('ui.panel.entity_picker.no_entities_for_group', getLocale(this.hass))}
-
-
-
- isEqual(e, this.selectedAction))}
- @change=${(ev) => this.selectAction(ev.detail)}
- >
- ${!this.selectedEntities.length
- ? localize('ui.panel.entity_picker.no_entity_selected', getLocale(this.hass))
- : localize('ui.panel.entity_picker.no_actions_for_entity', getLocale(this.hass))}
-
- ${this.makeSchemeButton(actions)}
-
-
- ${this.hass.localize('ui.common.next')}
-
-
- `;
- }
- makeSchemeButton(actionConfig) {
- if (!actionConfig.length || !this.hass)
- return T ``;
- return T `
-
-
- this.selectTimeScheme()}>
-
- ${localize('ui.panel.entity_picker.make_scheme', getLocale(this.hass))}
-
-
-
- `;
- }
- selectGroup(val) {
- this.selectedGroup = val;
- this.selectedEntities = [];
- this.selectedAction = undefined;
- }
- selectEntity(value) {
- this.selectedEntities = Array.isArray(value) ? value : [value];
- if (this.selectedAction) {
- const availableActions = this.getActionsForEntity();
- this.selectedAction = availableActions.find(e => compareActions(e, this.selectedAction));
- }
- else
- this.selectedAction = undefined;
- }
- selectAction(val) {
- this.selectedAction = val;
- this.timeSchemeSelected = false;
- }
- selectTimeScheme() {
- this.selectedAction = null;
- this.timeSchemeSelected = true;
- }
- cancelClick() {
- const myEvent = new CustomEvent('cancelClick');
- this.dispatchEvent(myEvent);
- }
- nextClick() {
- const myEvent = new CustomEvent('nextClick', {
- detail: {
- entities: this.selectedEntities,
- action: this.selectedAction,
- timeSchemeSelected: this.timeSchemeSelected,
- },
- });
- this.dispatchEvent(myEvent);
- }
- };
- SchedulerEditorCard.styles = commonStyle;
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "hass", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "config", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "selectedGroup", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "selectedEntities", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "selectedAction", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "entities", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "schedule", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "multipleEntity", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "scheduleEntities", void 0);
- __decorate([
- e$3()
- ], SchedulerEditorCard.prototype, "timeSchemeSelected", void 0);
- SchedulerEditorCard = __decorate([
- n$4('scheduler-editor-card')
- ], SchedulerEditorCard);
-
- let TimePicker = class TimePicker extends h$2 {
- constructor() {
- super(...arguments);
- this.stepSize = DefaultTimeStep;
- this.relativeMode = false;
- this.event = ETimeEvent.Sunrise;
- this.maxOffset = 2;
- }
- get time() {
- if (this._time >= 0)
- return this._time;
- return Math.abs(this._time);
- }
- set time(value) {
- const newTime = roundTime(value, this.stepSize, {
- wrapAround: !this.relativeMode,
- maxHours: this.relativeMode ? this.maxOffset : undefined,
- });
- const timeUpdated = newTime != this._time && isDefined(this._time);
- this._time = newTime;
- if (timeUpdated)
- this.updateValue();
- }
- firstUpdated() {
- const res = parseRelativeTime(this.value);
- if (!res)
- this.time = stringToTime(this.value, this.hass);
- else {
- this.relativeMode = true;
- this.event = res.event == ETimeEvent.Sunrise ? ETimeEvent.Sunrise : ETimeEvent.Sunset;
- this.time = res.sign == '+' ? stringToTime(res.offset, this.hass) : -stringToTime(res.offset, this.hass);
- }
- }
- updateValue() {
- if (this.relativeMode) {
- const sign = this._time >= 0 ? '+' : '-';
- const offset = timeToString(this.time);
- this.value = `${this.event}${sign}${offset}`;
- }
- else {
- this.value = timeToString(this.time);
- }
- const myEvent = new CustomEvent('change');
- this.dispatchEvent(myEvent);
- }
- render() {
- const timeString = this.relativeMode
- ? timeToString(this.time)
- : formatTime(stringToDate(timeToString(this.time)), getLocale(this.hass));
- const timeParts = timeString.split(/:|\ /);
- return T `
-
-
- (this.time = this._time + 3600)}>
-
-
-
-
${timeParts[0].padStart(2, '0')}
-
- (this.time = this._time - 3600)}>
-
-
-
-
:
-
- (this.time = this._time + this.stepSize * 60)}>
-
-
-
-
${timeParts[1]}
-
- (this.time = this._time - this.stepSize * 60)}>
-
-
-
- ${this.relativeMode
- ? T `
-
-
- ${this.getBeforeAfter()}
-
-
-
-
-
- `
- : timeParts.length > 2
- ? T `
-
-
- ${timeParts[2]}
-
-
- `
- : ''}
-
- ${this.getSunModeToggle()}
-
-
- `;
- }
- getSunModeToggle() {
- if (!this.hass)
- return T ``;
- if (!this.hass.states['sun.sun'])
- return T ``;
- return T `
-
-
-
- `;
- }
- getBeforeAfter() {
- if (!this.hass)
- return '';
- return this._time < 0
- ? this.hass.localize('ui.panel.config.automation.editor.conditions.type.sun.before').slice(0, -1)
- : this.hass.localize('ui.panel.config.automation.editor.conditions.type.sun.after').slice(0, -1);
- }
- toggleAmPm() {
- this.time = this._time + 12 * 3600;
- }
- toggleBeforeAfter() {
- this.time = -this._time;
- }
- toggleSunriseSunset() {
- this.event = this.event == ETimeEvent.Sunrise ? ETimeEvent.Sunset : ETimeEvent.Sunrise;
- }
- toggleMode() {
- if (!this.hass)
- return;
- this.relativeMode = !this.relativeMode;
- const sunEntity = this.hass.states['sun.sun'];
- const ts_sunrise = stringToTime(sunEntity.attributes.next_rising, this.hass);
- const ts_sunset = stringToTime(sunEntity.attributes.next_setting, this.hass);
- if (this.relativeMode) {
- this.event =
- Math.abs(this._time - ts_sunrise) < Math.abs(this._time - ts_sunset) ? ETimeEvent.Sunrise : ETimeEvent.Sunset;
- let offset = this.event == ETimeEvent.Sunrise ? this._time - ts_sunrise : this._time - ts_sunset;
- if (offset > 7200)
- offset = 7200;
- else if (offset < -7200)
- offset = -7200;
- this.time = offset;
- }
- else {
- this.time = this.event == ETimeEvent.Sunrise ? this._time + ts_sunrise : this._time + ts_sunset;
- }
- }
- };
- TimePicker.styles = i `
- div.time-picker {
- display: grid;
- grid-template-columns: min-content min-content min-content 1fr min-content;
- grid-template-rows: min-content min-content min-content;
- grid-template-areas:
- 'hours-up . minutes-up suffix options'
- 'hours separator minutes suffix options'
- 'hours-down . minutes-down suffix options';
- grid-gap: 10px 0px;
- align-items: center;
- }
-
- div.hours-up {
- grid-area: hours-up;
- }
- div.hours {
- grid-area: hours;
- }
- div.hours-down {
- grid-area: hours-down;
- }
- div.separator {
- grid-area: separator;
- }
- div.minutes-up {
- grid-area: minutes-up;
- }
- div.minutes {
- grid-area: minutes;
- }
- div.minutes-down {
- grid-area: minutes-down;
- }
- div.suffix {
- grid-area: suffix;
- flex-grow: 1;
- }
- div.options {
- grid-area: options;
- }
-
- div.hours-up,
- div.hours-down,
- div.minutes-up,
- div.minutes-down {
- --mdc-icon-size: 42px;
- }
-
- div.hours,
- div.minutes {
- font-size: 42px;
- text-align: center;
- }
-
- div.separator {
- font-size: 36px;
- }
-
- div.suffix mwc-button {
- --mdc-typography-button-font-size: 16px;
- --mdc-icon-size: 32px;
- }
-
- mwc-button.active {
- background: var(--primary-color);
- --mdc-theme-primary: var(--text-primary-color);
- border-radius: 4px;
- }
- `;
- __decorate([
- e$3()
- ], TimePicker.prototype, "hass", void 0);
- __decorate([
- e$3({ type: Number })
- ], TimePicker.prototype, "stepSize", void 0);
- __decorate([
- e$3()
- ], TimePicker.prototype, "relativeMode", void 0);
- __decorate([
- e$3()
- ], TimePicker.prototype, "event", void 0);
- __decorate([
- e$3()
- ], TimePicker.prototype, "_time", void 0);
- TimePicker = __decorate([
- n$4('time-picker')
- ], TimePicker);
-
- const relToAbsTime = (timeStr, hass, options = {}) => {
- const res = parseRelativeTime(timeStr);
- if (!res)
- return timeStr;
- const sunEntity = hass.states['sun.sun'];
- const ts_ref = res.event == 'sunrise'
- ? stringToTime(sunEntity.attributes.next_rising, hass)
- : stringToTime(sunEntity.attributes.next_setting, hass);
- let ts = res.sign == '+' ? ts_ref + stringToTime(res.offset, hass) : ts_ref - stringToTime(res.offset, hass);
- if (options.stepSize)
- ts = roundTime(ts, options.stepSize);
- return timeToString(ts);
- };
- const absToRelTime = (timeStr, event, hass, options = {}) => {
- const res = parseRelativeTime(timeStr);
- if (res)
- return timeStr;
- const ts = stringToTime(timeStr, hass);
- const sunEntity = hass.states['sun.sun'];
- const ts_sunrise = stringToTime(sunEntity.attributes.next_rising, hass);
- const ts_sunset = stringToTime(sunEntity.attributes.next_setting, hass);
- if (!event)
- event = Math.abs(ts - ts_sunrise) < Math.abs(ts - ts_sunset) ? ETimeEvent.Sunrise : ETimeEvent.Sunset;
- const ts_ref = event == ETimeEvent.Sunrise
- ? stringToTime(sunEntity.attributes.next_rising, hass)
- : stringToTime(sunEntity.attributes.next_setting, hass);
- let offset = ts - ts_ref;
- if (options.stepSize)
- offset = roundTime(offset, options.stepSize, { maxHours: 2 });
- return `${event}${offset > 0 ? '+' : '-'}${timeToString(Math.abs(offset))}`;
- };
-
- const SEC_PER_DAY = 86400;
- const SEC_PER_HOUR = 3600;
- let TimeslotEditor = class TimeslotEditor extends h$2 {
- constructor() {
- super(...arguments);
- this.slots = [];
- this.actions = [];
- this.stepSize = 10;
- this.isDragging = false;
- this.currentTime = 0;
- this.rangeMin = 0; //lower bound of zoomed timeframe
- this.rangeMax = SEC_PER_DAY; //upper bound of zoomed timeframe
- this.activeSlot = null;
- this.activeMarker = null;
- this.previousSlot = null;
- this.timer = 0;
- this.timeout = 0;
- this.zoomFactor = 1;
- }
- firstUpdated() {
- window.addEventListener('resize', () => {
- clearTimeout(this.timeout);
- this.timeout = window.setTimeout(() => {
- this.requestUpdate();
- }, 50);
- });
- }
- render() {
- if (!this.hass)
- return T ``;
- const fullWidth = parseFloat(getComputedStyle(this).getPropertyValue('width'));
- const width = (SEC_PER_DAY / (this.rangeMax - this.rangeMin)) * fullWidth;
- const left = (-this.rangeMin / (this.rangeMax - this.rangeMin)) * fullWidth;
- return T `
-
-
- ${this.renderSlots()}
-
-
-
-
- ${this.renderTimes()}
-
-
- = 24}
- >
-
- ${this.hass.localize('ui.dialogs.helper_settings.input_select.add')}
-
-
-
- ${this.hass.localize('ui.common.delete')}
-
- `;
- }
- renderSlots() {
- const fullWidth = parseFloat(getComputedStyle(this).getPropertyValue('width'));
- const width = (SEC_PER_DAY / (this.rangeMax - this.rangeMin)) * fullWidth;
- const left = (-this.rangeMin / (this.rangeMax - this.rangeMin)) * fullWidth;
- let start = left;
- return this.slots.map((e, i) => {
- const w = ((stringToTime(e.stop, this.hass) || SEC_PER_DAY) -
- stringToTime(e.start, this.hass)) /
- SEC_PER_DAY;
- const actionText = this.computeActionDisplay(e) || '';
- const textWidth = (actionText || '').length * 5 + 10;
- const leftMargin = start < 0 && start + w * width > 0 ? -start + 5 : 15;
- const rightMargin = start + w * width > fullWidth && start < fullWidth
- ? w * width - (fullWidth - start) + 5
- : 15;
- const availableWidth = w * width - leftMargin - rightMargin;
- start += w * width;
- return T `
-
- ${i > 0 && (this.activeSlot === i || this.activeSlot === i - 1)
- ? T `
-
- `
- : ''}
- ${i > 0 ? this.renderTooltip(i) : ''}
-
-
- ${actionText &&
- (availableWidth > textWidth / 3 || availableWidth > 50) &&
- availableWidth > 30
- ? actionText
- : ''}
-
-
- `;
- });
- }
- renderTooltip(i) {
- const res = parseRelativeTime(this.slots[i].start);
- return T `
-
- `;
- }
- renderTimes() {
- this._updateTooltips();
- const fullWidth = parseFloat(getComputedStyle(this).getPropertyValue('width'));
- const allowedStepSizes = [1, 2, 3, 4, 6, 8, 12];
- const segmentWidth = formatAmPm(getLocale(this.hass)) ? 55 : 40;
- let stepSize = Math.ceil(24 / (fullWidth / segmentWidth));
- while (!allowedStepSizes.includes(stepSize))
- stepSize++;
- const nums = [
- 0,
- ...Array.from(Array(24 / stepSize - 1).keys()).map(e => (e + 1) * stepSize),
- 24,
- ];
- return nums.map(e => {
- const isSpacer = e == 0 || e == 24;
- const w = isSpacer ? (stepSize / 48) * 100 : (stepSize / 24) * 100;
- return T `
-
- ${!isSpacer
- ? formatTime(stringToDate(timeToString(e * SEC_PER_HOUR)), getLocale(this.hass))
- : ''}
-
- `;
- });
- }
- computeActionDisplay(entry) {
- if (!this.hass)
- return;
- if (!entry.actions)
- return '';
- return unique(entry.actions.map(action => {
- const actionConfig = this.actions.find(e => compareActions(e, action, true));
- if (!actionConfig)
- return '???';
- if (actionConfig.variables &&
- Object.keys(actionConfig.variables).some(field => action.service_data && field in action.service_data)) {
- return Object.entries(actionConfig.variables)
- .filter(([field]) => action.service_data && field in action.service_data)
- .map(([field, variable]) => {
- const value = action.service_data[field];
- if (variable.type == EVariableType.Level) {
- variable = variable;
- return levelVariableDisplay(Number(value), variable);
- }
- else if (variable.type == EVariableType.List) {
- variable = variable;
- const listItem = variable.options.find(e => e.value == value);
- return PrettyPrintName(listItem && listItem.name ? listItem.name : String(value));
- }
- else
- return '';
- })
- .join(', ');
- }
- return PrettyPrintName(actionConfig.name ||
- localize(`services.${action.service}`, getLocale(this.hass)) ||
- action.service);
- })).join(', ');
- }
- _handleTouchStart(ev) {
- const fullWidth = parseFloat(getComputedStyle(this).getPropertyValue('width'));
- const width = (SEC_PER_DAY / (this.rangeMax - this.rangeMin)) * fullWidth;
- const left = (-this.rangeMin / (this.rangeMax - this.rangeMin)) * fullWidth;
- const Toffset = (-left / width) * SEC_PER_DAY;
- const marker = ev.target;
- let el = marker;
- while (!el.classList.contains('slot'))
- el = el.parentElement;
- const rightSlot = el;
- const leftSlot = rightSlot.previousElementSibling;
- const i = Number(leftSlot.getAttribute('slot'));
- const Tmin = i > 0 ? stringToTime(this.slots[i].start, this.hass) + 60 * this.stepSize : 0;
- const Tmax = i < this.slots.length - 2
- ? (stringToTime(this.slots[i + 1].stop, this.hass) || SEC_PER_DAY) -
- 60 * this.stepSize
- : SEC_PER_DAY;
- this.isDragging = true;
- const trackElement = rightSlot.parentElement
- .parentElement;
- const trackCoords = trackElement.getBoundingClientRect();
- let mouseMoveHandler = (ev) => {
- let startDragX;
- if (typeof TouchEvent !== 'undefined') {
- if (ev instanceof TouchEvent)
- startDragX = ev.changedTouches[0].pageX;
- else
- startDragX = ev.pageX;
- }
- else
- startDragX = ev.pageX;
- let x = startDragX - trackCoords.left;
- if (x > fullWidth - 10)
- x = fullWidth - 10;
- if (x < 10)
- x = 10;
- let time = Math.round((x / width) * SEC_PER_DAY + Toffset);
- if (time < Tmin)
- time = Tmin;
- if (time > Tmax)
- time = Tmax;
- this.currentTime = time;
- const relTime = parseRelativeTime(this.slots[i].stop);
- let timeString;
- if (relTime)
- timeString = absToRelTime(timeToString(time), relTime.event, this.hass, {
- stepSize: this.stepSize,
- });
- else {
- time =
- Math.round(time) >= SEC_PER_DAY ? SEC_PER_DAY : roundTime(time, this.stepSize);
- timeString = timeToString(time);
- }
- if (timeString == this.slots[i].stop)
- return;
- this.slots = Object.assign(this.slots, {
- [i]: Object.assign(Object.assign({}, this.slots[i]), { stop: timeString }),
- [i + 1]: Object.assign(Object.assign({}, this.slots[i + 1]), { start: timeString }),
- });
- this.requestUpdate();
- };
- const mouseUpHandler = () => {
- window.removeEventListener('mousemove', mouseMoveHandler);
- window.removeEventListener('touchmove', mouseMoveHandler);
- window.removeEventListener('mouseup', mouseUpHandler);
- window.removeEventListener('touchend', mouseUpHandler);
- mouseMoveHandler = () => {
- /**/
- };
- setTimeout(() => {
- this.isDragging = false;
- }, 100);
- marker.blur();
- const myEvent = new CustomEvent('update', { detail: { entries: this.slots } });
- this.dispatchEvent(myEvent);
- };
- window.addEventListener('mouseup', mouseUpHandler);
- window.addEventListener('touchend', mouseUpHandler);
- window.addEventListener('blur', mouseUpHandler);
- window.addEventListener('mousemove', mouseMoveHandler);
- window.addEventListener('touchmove', mouseMoveHandler);
- }
- _selectSlot(ev) {
- if (this.isDragging)
- return;
- let el = ev.target;
- if (el.tagName.toLowerCase() == 'span')
- el = el.parentElement;
- if (el.classList.contains('handle'))
- el = el.parentElement;
- const slot = Number(el.getAttribute('slot'));
- if (this.activeSlot == slot && this.activeMarker === null) {
- this.activeSlot = null;
- //this.rangeMin = 0;
- //this.rangeMax = SEC_PER_DAY;
- this.previousSlot = null;
- }
- else {
- this.previousSlot = this.activeSlot;
- this.activeSlot = slot;
- //this._calculateZoom();
- }
- this.activeMarker = null;
- this._updateZoom();
- const myEvent = new CustomEvent('update', { detail: { entry: this.activeSlot } });
- this.dispatchEvent(myEvent);
- }
- _calculateZoom() {
- const slot = Number(this.activeSlot);
- let min = stringToTime(this.slots[slot].start, this.hass);
- let max = stringToTime(this.slots[slot].stop, this.hass) || SEC_PER_DAY;
- const fullWidth = parseFloat(getComputedStyle(this).getPropertyValue('width'));
- min -= (max - min) / 3;
- max += (max - min) / 3;
- if (((max - min) / SEC_PER_DAY) * fullWidth >= 100) {
- min = 0;
- max = SEC_PER_DAY;
- }
- else {
- if (min < 0)
- max -= min;
- if (max > SEC_PER_DAY)
- min -= max - SEC_PER_DAY;
- }
- this.rangeMin = min > 0 ? min : 0;
- this.rangeMax = max < SEC_PER_DAY ? max : SEC_PER_DAY;
- clearInterval(this.timer);
- clearTimeout(this.timeout);
- this.timer = window.setInterval(() => {
- this._updateTooltips();
- }, 50);
- this.timeout = window.setTimeout(() => {
- clearInterval(this.timer);
- this._updateTooltips();
- }, 230);
- }
- _addSlot() {
- if (this.activeSlot === null)
- return;
- const activeSlot = this.slots[this.activeSlot];
- const startTime = stringToTime(activeSlot.start, this.hass);
- let endTime = stringToTime(activeSlot.stop, this.hass);
- if (endTime < startTime)
- endTime += SEC_PER_DAY;
- const newStop = roundTime(startTime + (endTime - startTime) / 2, this.stepSize);
- this.slots = [
- ...this.slots.slice(0, this.activeSlot),
- Object.assign(Object.assign({}, this.slots[this.activeSlot]), { stop: timeToString(newStop) }),
- Object.assign(Object.assign({}, this.slots[this.activeSlot]), { start: timeToString(newStop), stop: timeToString(endTime), actions: [] }),
- ...this.slots.slice(this.activeSlot + 1),
- ];
- this._updateZoom();
- const myEvent = new CustomEvent('update', { detail: { entries: this.slots } });
- this.dispatchEvent(myEvent);
- }
- _removeSlot() {
- if (this.activeSlot === null)
- return;
- const cutIndex = this.activeSlot == this.slots.length - 1 ? this.activeSlot - 1 : this.activeSlot;
- this.slots = [
- ...this.slots.slice(0, cutIndex),
- Object.assign(Object.assign({}, this.slots[cutIndex + 1]), { start: this.slots[cutIndex].start, stop: this.slots[cutIndex + 1].stop }),
- ...this.slots.slice(cutIndex + 2),
- ];
- if (this.activeSlot == this.slots.length)
- this.activeSlot--;
- this._updateZoom();
- const myEvent = new CustomEvent('update', { detail: { entries: this.slots } });
- this.dispatchEvent(myEvent);
- }
- _updateTooltips() {
- var _a;
- const fullWidth = parseFloat(getComputedStyle(this).getPropertyValue('width'));
- const tooltips = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.tooltip');
- const getBounds = (el) => {
- const width = el.offsetWidth;
- const left = el.parentElement.offsetLeft + el.offsetLeft - 15;
- if (el.parentElement.classList.contains('left'))
- return [left + width / 2, left + (3 * width) / 2];
- else if (el.parentElement.classList.contains('right'))
- return [left - width / 2, left + width / 2];
- return [left, left + width];
- };
- tooltips === null || tooltips === void 0 ? void 0 : tooltips.forEach((tooltip, i) => {
- const container = tooltip.parentElement;
- const visible = container.classList.contains('visible');
- const slot = Number(container.parentElement.getAttribute('slot'));
- if (slot != this.activeSlot && slot - 1 != this.activeSlot) {
- if (visible)
- container.classList.remove('visible');
- }
- else {
- const left = tooltip.parentElement.offsetLeft;
- if (left < 0 || left > fullWidth + 15) {
- if (visible)
- container.classList.remove('visible');
- }
- else {
- if (!visible)
- container.classList.add('visible');
- const width = container.offsetWidth;
- const isCenter = container.classList.contains('center');
- let marginLeft = getBounds(tooltip)[0], marginRight = fullWidth - getBounds(tooltip)[1];
- if (i > 0 && slot - 1 == this.activeSlot)
- marginLeft -= getBounds(tooltips[i - 1])[1];
- else if (i + 1 < tooltips.length && slot == this.activeSlot) {
- const w = getBounds(tooltips[i + 1])[0];
- marginRight -= w < 0 ? 0 : fullWidth - w;
- }
- //console.log(`tooltip ${i} marginLeft ${marginLeft} marginRight ${marginRight}`);
- if (marginLeft < marginRight) {
- if (marginLeft < 0) {
- if (isCenter && marginRight > width / 2) {
- container.classList.add('right');
- container.classList.remove('center');
- container.classList.remove('left');
- }
- }
- else {
- container.classList.add('center');
- container.classList.remove('right');
- container.classList.remove('left');
- }
- }
- else {
- if (marginRight < 0) {
- if (isCenter && marginLeft > width / 2) {
- container.classList.add('left');
- container.classList.remove('center');
- container.classList.remove('right');
- }
- }
- else {
- container.classList.add('center');
- container.classList.remove('left');
- container.classList.remove('right');
- }
- }
- }
- }
- });
- }
- _updateZoom() {
- // let center = SEC_PER_DAY / 2;
- // if (this.activeSlot !== null) {
- // const activeSlot = this.slots[this.activeSlot];
- // let min = stringToTime(activeSlot.start, this.hass!);
- // let max = stringToTime(activeSlot.stop!, this.hass!) || SEC_PER_DAY;
- // center = Math.round((max + min) / 2);
- // }
- // let timeSpan = SEC_PER_DAY;
- // if (this.zoomFactor == 2) timeSpan = SEC_PER_DAY / 2;
- // else if (this.zoomFactor == 3) timeSpan = SEC_PER_DAY / 4;
- // else if (this.zoomFactor == 4) timeSpan = SEC_PER_DAY / 8;
- // let min = center - Math.round(timeSpan / 2);
- // let max = center + Math.round(timeSpan / 2);
- // if (min < 0) {
- // max += -min;
- // min = 0;
- // if (max > SEC_PER_DAY) max = SEC_PER_DAY;
- // } else if (max > SEC_PER_DAY) {
- // min -= max - SEC_PER_DAY;
- // max = SEC_PER_DAY;
- // if (min < 0) min = 0;
- // }
- // this.rangeMin = min;
- // this.rangeMax = max;
- clearInterval(this.timer);
- clearTimeout(this.timeout);
- this.timer = window.setInterval(() => {
- this._updateTooltips();
- }, 50);
- this.timeout = window.setTimeout(() => {
- clearInterval(this.timer);
- this._updateTooltips();
- }, 230);
- }
- // private _zoomIn() {
- // this.zoomFactor++;
- // this._updateZoom();
- // }
- // private _zoomOut() {
- // this.zoomFactor--;
- // this._updateZoom();
- // }
- _selectMarker(ev, enable = true) {
- ev.stopImmediatePropagation();
- let el = ev.target;
- while (!el.classList.contains('slot'))
- el = el.parentElement;
- const slot = Number(el.getAttribute('slot'));
- if (enable && this.activeMarker === slot)
- this.activeMarker = null;
- else
- this.activeMarker = enable ? slot : null;
- const myEvent = new CustomEvent('update', {
- detail: { entry: this.activeSlot, marker: this.activeMarker },
- });
- this.dispatchEvent(myEvent);
- this._updateTooltips();
- }
- static get styles() {
- return i `
- :host {
- display: block;
- max-width: 100%;
- overflow: hidden;
- }
- div.outer {
- width: 100%;
- overflow-x: hidden;
- overflow-y: hidden;
- border-radius: 5px;
- }
- div.wrapper,
- div.time-wrapper {
- white-space: nowrap;
- transition: width 0.2s cubic-bezier(0.17, 0.67, 0.83, 0.67),
- margin 0.2s cubic-bezier(0.17, 0.67, 0.83, 0.67);
- }
- .slot {
- float: left;
- background: rgba(var(--rgb-primary-color), 0.7);
- height: 60px;
- cursor: pointer;
- box-sizing: border-box;
- transition: background 0.1s cubic-bezier(0.17, 0.67, 0.83, 0.67);
- }
- .wrapper.selectable .slot:hover {
- background: rgba(var(--rgb-primary-color), 0.85);
- }
- .slot:not(:first-child) {
- border-left: 1px solid var(--card-background-color);
- }
- .slot:not(:last-child) {
- border-right: 1px solid var(--card-background-color);
- }
- .slot.active {
- background: rgba(var(--rgb-accent-color), 0.7);
- }
- .slot.noborder {
- border: none;
- }
- .wrapper.selectable .slot.active:hover {
- background: rgba(var(--rgb-accent-color), 0.85);
- }
- div.time-wrapper div {
- float: left;
- display: flex;
- position: relative;
- height: 25px;
- line-height: 25px;
- font-size: 12px;
- text-align: center;
- align-content: center;
- align-items: center;
- justify-content: center;
- }
- div.time-wrapper div.time:before {
- content: ' ';
- background: var(--disabled-text-color);
- position: absolute;
- left: 0px;
- top: 0px;
- width: 1px;
- height: 5px;
- margin-left: 50%;
- margin-top: 0px;
- }
- .slot span {
- font-size: 14px;
- color: var(--text-primary-color);
- height: 100%;
- display: flex;
- align-content: center;
- align-items: center;
- justify-content: center;
- transition: margin 0.2s cubic-bezier(0.17, 0.67, 0.83, 0.67);
- word-break: break-all;
- white-space: normal;
- overflow: hidden;
- line-height: 1em;
- }
- div.handle {
- display: flex;
- height: 100%;
- width: 36px;
- margin-left: -19px;
- margin-bottom: -60px;
- align-content: center;
- align-items: center;
- justify-content: center;
- }
- div.button-holder {
- background: var(--card-background-color);
- border-radius: 50%;
- width: 24px;
- height: 24px;
- display: flex;
- visibility: hidden;
- animation: 0.2s fadeIn;
- animation-fill-mode: forwards;
- }
- ha-icon-button {
- --mdc-icon-button-size: 36px;
- margin-top: -6px;
- margin-left: -6px;
- }
- @keyframes fadeIn {
- 99% {
- visibility: hidden;
- }
- 100% {
- visibility: visible;
- }
- }
- div.tooltip-container {
- position: absolute;
- margin-top: -28px;
- margin-left: -40px;
- width: 80px;
- height: 26px;
- display: flex;
- text-align: center;
- display: none;
- }
- div.tooltip-container.visible {
- display: block;
- }
- div.tooltip-container.left {
- margin-left: -80px;
- text-align: right;
- }
- div.tooltip-container.right {
- margin-left: 0px;
- text-align: left;
- }
- div.tooltip {
- display: inline-flex;
- margin: 0px auto;
- border-radius: 5px;
- color: var(--text-primary-color);
- font-size: 1em;
- padding: 0px 5px;
- text-align: center;
- line-height: 26px;
- z-index: 1;
- transition: all 0.1s ease-in;
- transform-origin: center bottom;
- --tooltip-color: var(--primary-color);
- background: var(--tooltip-color);
- }
- div.tooltip.active {
- --tooltip-color: rgba(var(--rgb-accent-color), 0.7);
- }
- div.tooltip-container.left div.tooltip {
- transform-origin: right bottom;
- }
- div.tooltip-container.right div.tooltip {
- transform-origin: left bottom;
- }
- div.tooltip-container.center div.tooltip:before {
- content: ' ';
- width: 0px;
- height: 0px;
- border-left: 6px solid transparent;
- border-right: 6px solid transparent;
- border-top: 10px solid var(--tooltip-color);
- position: absolute;
- margin-top: 25px;
- margin-left: calc(50% - 6px);
- top: 0px;
- left: 0px;
- }
- div.tooltip-container.left div.tooltip:before {
- content: ' ';
- border-top: 10px solid transparent;
- border-bottom: 10px solid transparent;
- border-right: 8px solid var(--tooltip-color);
- opacity: 1;
- position: absolute;
- margin-top: 15px;
- margin-left: calc(100% - 8px);
- left: 0px;
- top: 0px;
- width: 0px;
- height: 0px;
- }
- div.tooltip-container.right div.tooltip:before {
- content: ' ';
- border-top: 10px solid transparent;
- border-bottom: 10px solid transparent;
- border-left: 8px solid var(--tooltip-color);
- opacity: 1;
- position: absolute;
- margin-top: 15px;
- margin-left: 0px;
- left: 0px;
- top: 0px;
- width: 0px;
- height: 0px;
- }
- div.tooltip ha-icon {
- --mdc-icon-size: 20px;
- }
- mwc-button ha-icon {
- margin-right: 11px;
- }
- `;
- }
- };
- __decorate([
- e$3()
- ], TimeslotEditor.prototype, "hass", void 0);
- __decorate([
- e$3({ type: Array })
- ], TimeslotEditor.prototype, "slots", void 0);
- __decorate([
- e$3({ type: Array })
- ], TimeslotEditor.prototype, "actions", void 0);
- __decorate([
- e$3({ type: Number })
- ], TimeslotEditor.prototype, "stepSize", void 0);
- __decorate([
- e$3()
- ], TimeslotEditor.prototype, "rangeMin", void 0);
- __decorate([
- e$3()
- ], TimeslotEditor.prototype, "rangeMax", void 0);
- __decorate([
- e$3()
- ], TimeslotEditor.prototype, "activeSlot", void 0);
- __decorate([
- e$3()
- ], TimeslotEditor.prototype, "activeMarker", void 0);
- __decorate([
- e$4({ passive: true })
- ], TimeslotEditor.prototype, "_handleTouchStart", null);
- TimeslotEditor = __decorate([
- n$4('timeslot-editor')
- ], TimeslotEditor);
-
- const loadHaForm = async () => {
- if (customElements.get("ha-checkbox") && customElements.get("ha-slider")) return;
- await customElements.whenDefined("partial-panel-resolver");
- const ppr = document.createElement('partial-panel-resolver');
- ppr.hass = {
- panels: [{
- url_path: "tmp",
- component_name: "config"
- }]
- };
-
- ppr._updateRoutes();
-
- await ppr.routerOptions.routes.tmp.load();
- await customElements.whenDefined("ha-panel-config");
- const cpr = document.createElement("ha-panel-config");
- await cpr.routerOptions.routes.automation.load();
- };
-
- let VariableSlider = class VariableSlider extends h$2 {
- constructor() {
- super(...arguments);
- this.min = 0;
- this.max = 255;
- this.step = 1;
- this.scaleFactor = 1;
- this.unit = '';
- this.optional = false;
- this.disabled = false;
- this._displayedValue = 0;
- }
- //raw value
- set value(value) {
- value = isNaN(value) ? this.min : this._roundedValue(value / this.scaleFactor);
- this._displayedValue = value;
- }
- firstUpdated() {
- (async () => await loadHaForm())();
- if (this.disabled && !this.optional) {
- this.disabled = false;
- this.requestUpdate();
- }
- }
- render() {
- return T `
-
-
- ${this.getCheckbox()}
-
-
- ${this.getSlider()}
-
-
- ${this._displayedValue}${this.unit}
-
-
- `;
- }
- getSlider() {
- if (!this.disabled) {
- return T `
-
- `;
- }
- else {
- return T `
-
- `;
- }
- }
- getCheckbox() {
- if (!this.optional)
- return T ``;
- return T `
-
- `;
- }
- toggleChecked(e) {
- const checked = e.target.checked;
- this.disabled = !checked;
- const value = this.disabled ? null : this._scaledValue(this._displayedValue);
- A$1(this, 'value-changed', { value: value });
- }
- _updateValue(e) {
- let value = Number(e.target.value);
- this._displayedValue = value;
- value = this._scaledValue(this._displayedValue);
- A$1(this, 'value-changed', { value: value });
- }
- _roundedValue(value) {
- value = Math.round(value / this.step) * this.step;
- value = parseFloat(value.toPrecision(12));
- if (value > this.max)
- value = this.max;
- else if (value < this.min)
- value = this.min;
- return value;
- }
- _scaledValue(value) {
- value = this._roundedValue(value);
- value = value * this.scaleFactor;
- value = parseFloat(value.toFixed(2));
- return value;
- }
- };
- VariableSlider.styles = i `
- ${commonStyle} :host {
- width: 100%;
- }
- ha-slider {
- width: 100%;
- --paper-slider-pin-start-color: var(--primary-color);
- }
- `;
- __decorate([
- e$3({ type: Number })
- ], VariableSlider.prototype, "min", void 0);
- __decorate([
- e$3({ type: Number })
- ], VariableSlider.prototype, "max", void 0);
- __decorate([
- e$3({ type: Number })
- ], VariableSlider.prototype, "step", void 0);
- __decorate([
- e$3({ type: Number })
- ], VariableSlider.prototype, "value", null);
- __decorate([
- e$3({ type: Number })
- ], VariableSlider.prototype, "scaleFactor", void 0);
- __decorate([
- e$3({ type: String })
- ], VariableSlider.prototype, "unit", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], VariableSlider.prototype, "optional", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], VariableSlider.prototype, "disabled", void 0);
- __decorate([
- e$3({ type: Number })
- ], VariableSlider.prototype, "_displayedValue", void 0);
- VariableSlider = __decorate([
- n$4('variable-slider')
- ], VariableSlider);
-
- let SchedulerVariablePicker = class SchedulerVariablePicker extends h$2 {
- firstUpdated() {
- var _a;
- if ((this.value === null || this.value === undefined) &&
- ((_a = this.variable) === null || _a === void 0 ? void 0 : _a.type) == EVariableType.Level &&
- !this.variable.optional)
- this.levelVariableUpdated(this.variable.min);
- }
- render() {
- if (!this.variable)
- return T ``;
- else if (this.variable.type == EVariableType.Level)
- return this.renderLevelVariable();
- else if (this.variable.type == EVariableType.List)
- return this.renderListVariable();
- else if (this.variable.type == EVariableType.Text)
- return this.renderTextVariable();
- else
- return T ``;
- }
- levelVariableUpdated(ev) {
- const value = typeof ev == 'number' ? ev : Number(ev.detail.value);
- this.value = value;
- A$1(this, 'value-changed', { value: value });
- }
- renderLevelVariable() {
- const variable = this.variable;
- const value = Number(this.value);
- return T `
-
-
- `;
- }
- listVariableUpdated(ev) {
- const value = typeof ev == 'string' ? ev : String(ev.target.value);
- this.value = value;
- A$1(this, 'value-changed', { value: value });
- }
- renderListVariable() {
- const variable = this.variable;
- const options = variable.options;
- const value = String(this.value) || null;
- if (options.length == 1 && value != options[0].value)
- this.listVariableUpdated(options[0].value);
- return T `
-
- `;
- }
- renderTextVariable() {
- const variable = this.variable;
- const value = this.value;
- return T `
-
-
- `;
- }
- };
- __decorate([
- e$3()
- ], SchedulerVariablePicker.prototype, "variable", void 0);
- __decorate([
- e$3()
- ], SchedulerVariablePicker.prototype, "value", void 0);
- SchedulerVariablePicker = __decorate([
- n$4('scheduler-variable-picker')
- ], SchedulerVariablePicker);
-
- let DialogDeleteConfirm = class DialogDeleteConfirm extends h$2 {
- async showDialog(params) {
- this._params = params;
- await this.updateComplete;
- }
- async closeDialog() {
- if (this._params)
- this._params.cancel();
- this._params = undefined;
- }
- render() {
- if (!this._params)
- return T ``;
- return T `
-
-
-
-
-
- ${this.hass.localize('ui.dialogs.more_info_control.restored.confirm_remove_title')}
-
-
-
-
- ${this.hass.localize('ui.dialogs.more_info_control.restored.confirm_remove_text')}
-
-
-
- ${this.hass.localize('ui.dialogs.generic.cancel')}
-
-
- ${this.hass.localize('ui.dialogs.generic.ok')}
-
-
- `;
- }
- confirmClick() {
- this._params.confirm();
- }
- cancelClick() {
- this._params.cancel();
- }
- static get styles() {
- return i `
- div.wrapper {
- color: var(--primary-text-color);
- }
- `;
- }
- };
- __decorate([
- e$3({ attribute: false })
- ], DialogDeleteConfirm.prototype, "hass", void 0);
- __decorate([
- r$3()
- ], DialogDeleteConfirm.prototype, "_params", void 0);
- DialogDeleteConfirm = __decorate([
- n$4('dialog-delete-confirm')
- ], DialogDeleteConfirm);
-
- var dialogDeleteConfirm = /*#__PURE__*/Object.freeze({
- __proto__: null,
- get DialogDeleteConfirm () { return DialogDeleteConfirm; }
- });
-
- function startOfWeek(locale) {
- const parts = locale.match(/^([a-z]{2,3})(?:-([a-z]{3})(?=$|-))?(?:-([a-z]{4})(?=$|-))?(?:-([a-z]{2}|\d{3})(?=$|-))?/i);
- const language = parts[1];
- const region = parts[4];
- const regionSat = 'AEAFBHDJDZEGIQIRJOKWLYOMQASDSY'.match(/../g);
- const regionSun = 'AGARASAUBDBRBSBTBWBZCACNCODMDOETGTGUHKHNIDILINJMJPKEKHKRLAMHMMMOMTMXMZNINPPAPEPHPKPRPTPYSASGSVTHTTTWUMUSVEVIWSYEZAZW'.match(/../g);
- const languageSat = ['ar', 'arq', 'arz', 'fa'];
- const languageSun = 'amasbndzengnguhehiidjajvkmknkolomhmlmrmtmyneomorpapssdsmsnsutatethtnurzhzu'.match(/../g);
- if (region)
- return regionSun.includes(region) ? 'sun' : regionSat.includes(region) ? 'sat' : 'mon';
- else
- return languageSun.includes(language) ? 'sun' : languageSat.includes(language) ? 'sat' : 'mon';
+ div.summary-entity {
+ grid-area: entity;
}
-
- const assignAction = (entity_id, action) => {
- let output = {
- entity_id: entity_id,
- service: action.service,
- service_data: Object.assign({}, action.service_data),
- };
- Object.entries(action.variables || {}).forEach(([key, config]) => {
- const serviceArgs = Object.keys(output.service_data || {});
- if (serviceArgs.includes(key))
- return;
- if (config.type == EVariableType.Level) {
- config = config;
- output = Object.assign(Object.assign({}, output), { service_data: config.optional
- ? omit(output.service_data || {}, key)
- : Object.assign(Object.assign({}, output.service_data), { [key]: parseFloat((config.min * config.scale_factor).toPrecision(12)) || 0 }) });
- }
- else if (config.type == EVariableType.List) {
- config = config;
- output = Object.assign(Object.assign({}, output), { service_data: Object.assign(Object.assign({}, output.service_data), { [key]: config.options.length ? config.options[0].value : undefined }) });
- }
- else if (config.type == EVariableType.Text) {
- config = config;
- output = Object.assign(Object.assign({}, output), { service_data: Object.assign(Object.assign({}, output.service_data), { [key]: '' }) });
- }
- });
- return output;
- };
-
- let SchedulerTimepickerCard = class SchedulerTimepickerCard extends h$2 {
- constructor() {
- super(...arguments);
- this.activeEntry = null;
- this.activeMarker = null;
- this.timeslots = false;
- this.editItem = false;
- }
- firstUpdated() {
- if (!this.actions || !this.hass)
- return;
- if (!this.timeslots)
- this.activeEntry = 0;
- const actions = this.actions.map(e => {
- const action = Object.assign(Object.assign({}, e), { service_data: omit(e.service_data || {}, ...Object.keys(e.variables || {})) });
- return Object.assign(e, {
- name: computeActionDisplay(action),
- });
- });
- actions.sort(sortAlphabetically);
- this.actions = actions;
- }
- render() {
- if (!this.hass || !this.config || !this.entities || !this.actions)
- return T ``;
- return T `
-
-
-
-
- ${this.renderSummary()}
- ${!this.timeslots
- ? T `
- ${this.getVariableEditor()} ${this.renderDays()}
-
- this.updateActiveEntry({ start: ev.target.value })}
- >
-
- `
- : T `
- ${this.renderDays()}
-
-
-
-
-
- ${this.renderMarkerOptions()} ${this.renderActions()} ${this.getVariableEditor()}
- `}
-
-
- e.actions.length).length}
- >
- ${this.hass.localize('ui.common.save')}
-
- ${this.editItem
- ? T `
- ${this.hass.localize('ui.common.delete')}
- `
- : ''}
- ${this.hass.localize('ui.dialogs.helper_settings.input_select.options')}
-
-
- `;
- }
- renderSummary() {
- if (!this.entities || !this.actions)
- return T ``;
- return T `
-
-
- ${this.entities.map(entity => T `
-
-
- ${capitalize(PrettyPrintName(entity.name || this.hass.states[entity.id].attributes.friendly_name || b$1(entity.id)))}
-
- `)}
-
-
-
-
-
- ${this.timeslots
- ? T `
-
-
- ${capitalize(localize('ui.panel.entity_picker.make_scheme', getLocale(this.hass)))}
-
- `
- : T `
-
-
- ${capitalize(this.actions[0].name || b$1(this.actions[0].service))}
-
- `}
-
-
- `;
- }
- renderDays() {
- if (!this.hass)
- return T ``;
- let weekdays = Array.from(Array(7).keys());
- const firstWeekday = startOfWeek(this.hass.language);
- const shiftCount = weekdays.length - weekdayArray.findIndex(e => e.substr(0, 3) == firstWeekday);
- weekdays = [...weekdays.slice(-shiftCount), ...weekdays.slice(0, -shiftCount)];
- const DayOptions = weekdays.map(e => Object({ value: weekdayArray[e].substr(0, 3), name: formatWeekday(e, getLocale(this.hass), true) }));
- const DayTypeOptions = [
- { value: EDayType.Daily, name: localize('ui.components.date.day_types_short.daily', getLocale(this.hass)) },
- { value: EDayType.Workday, name: localize('ui.components.date.day_types_short.workdays', getLocale(this.hass)) },
- { value: EDayType.Weekend, name: localize('ui.components.date.day_types_short.weekend', getLocale(this.hass)) },
- {
- value: EDayType.Custom,
- name: this.hass.localize('ui.panel.config.automation.editor.actions.type.choose.label'),
- },
- ];
- return T `
-
-
-
- ${weekdayType(this.schedule.weekdays) == EDayType.Custom
- ? T `
-
-
-
-
- `
- : ''}
- `;
- }
- renderActions() {
- var _a;
- if (!this.hass || this.activeMarker !== null)
- return;
- const selectedAction = this.activeEntry !== null && this.schedule.timeslots[this.activeEntry].actions.length
- ? this.schedule.timeslots[this.activeEntry].actions[0]
- : null;
- return T `
-
- compareActions(e, selectedAction, true)) : null}
- optional="true"
- @change=${this.selectAction}
- >
- ${localize('ui.panel.time_picker.no_timeslot_selected', getLocale(this.hass))}
-
- `;
- }
- renderMarkerOptions() {
- if (!this.hass || !this.config || this.activeMarker === null)
- return;
- const value = this.schedule.timeslots[this.activeMarker].start;
- const res = parseRelativeTime(value);
- const deltaSunrise = stringToTime(value, this.hass) - stringToTime('sunrise+00:00', this.hass), deltaSunset = stringToTime(value, this.hass) - stringToTime('sunset+00:00', this.hass);
- const markerOptions = [
- {
- value: 'time',
- name: this.hass.localize('ui.panel.config.automation.editor.triggers.type.time.at'),
- icon: 'hass:clock-outline',
- },
- {
- value: ETimeEvent.Sunrise,
- name: this.hass.localize('ui.panel.config.automation.editor.conditions.type.sun.sunrise'),
- icon: 'hass:weather-sunny',
- disabled: Math.abs(deltaSunrise) > 7200,
- },
- {
- value: ETimeEvent.Sunset,
- name: this.hass.localize('ui.panel.config.automation.editor.conditions.type.sun.sunset'),
- icon: 'hass:weather-night',
- disabled: Math.abs(deltaSunset) > 7200,
- },
- ];
- return T `
-
-
-
- `;
- }
- updateMarkerSetting(ev) {
- const value = ev.target.value;
- const ts = this.schedule.timeslots[this.activeMarker].start;
- const res = value == 'time'
- ? relToAbsTime(ts, this.hass, { stepSize: this.config.time_step })
- : absToRelTime(ts, value, this.hass, { stepSize: this.config.time_step });
- let timeslots = [...this.schedule.timeslots];
- timeslots = Object.assign(timeslots, {
- [this.activeMarker - 1]: Object.assign(Object.assign({}, this.schedule.timeslots[this.activeMarker - 1]), { stop: res }),
- [this.activeMarker]: Object.assign(Object.assign({}, this.schedule.timeslots[this.activeMarker]), { start: res }),
- });
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: [...timeslots] });
- }
- updateActiveEntry(data) {
- if (this.activeEntry === null)
- return;
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: Object.assign([...this.schedule.timeslots], {
- [this.activeEntry]: Object.assign(Object.assign({}, this.schedule.timeslots[this.activeEntry]), data),
- }) });
- }
- updateActiveEntryAction(data, num) {
- if (this.activeEntry === null)
- return;
- if (data && 'service' in data) {
- this.updateActiveEntry({
- actions: Object.assign([...this.schedule.timeslots[this.activeEntry].actions], {
- [num]: Object.assign(Object.assign({}, this.schedule.timeslots[this.activeEntry].actions[num]), data),
- }),
- });
- }
- else if (data) {
- //update service_data
- Object.entries(data).forEach(([key, val]) => {
- let actionConfig = [...this.schedule.timeslots[this.activeEntry].actions];
- let serviceData = typeof val == 'object' && key in this.schedule.timeslots[this.activeEntry].actions[num]
- ? Object.assign(Object.assign({}, actionConfig[num][key]), val) : val;
- const invalidParams = Object.keys(serviceData).filter(e => serviceData[e] === null);
- if (invalidParams.length)
- serviceData = omit(serviceData, ...invalidParams);
- actionConfig = Object.assign(actionConfig, {
- [num]: Object.assign(Object.assign({}, actionConfig[num]), { [key]: serviceData }),
- });
- this.updateActiveEntry({ actions: actionConfig });
- });
- }
- else {
- this.updateActiveEntry({
- actions: [...this.schedule.timeslots[this.activeEntry].actions].filter((_, i) => i != num),
- });
- }
- }
- handlePlannerUpdate(ev) {
- if (ev.detail.hasOwnProperty('entries')) {
- const entries = ev.detail.entries;
- if (entries.length < this.schedule.timeslots.length && this.activeEntry == this.schedule.timeslots.length - 1)
- this.activeEntry = this.schedule.timeslots.length - 2;
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: [...entries] });
- }
- else if (ev.detail.hasOwnProperty('entry')) {
- this.activeMarker = null;
- this.activeEntry = ev.detail.entry !== null ? Number(ev.detail.entry) : null;
- }
- if (ev.detail.hasOwnProperty('marker')) {
- this.activeEntry = null;
- this.activeMarker = ev.detail.marker !== null ? Number(ev.detail.marker) : null;
- }
- }
- selectAction(ev) {
- if (!this.actions || this.activeEntry === null)
- return;
- const action = ev.detail;
- if (action) {
- this.entities.map(e => e.id).forEach((entity_id, num) => {
- this.updateActiveEntryAction(assignAction(entity_id, action), num);
- });
- }
- else {
- this.entities.forEach((_, num) => {
- this.updateActiveEntryAction(null, num);
- });
- }
- }
- getVariableEditor() {
- if (this.activeEntry === null || !this.actions)
- return T ``;
- const actions = [];
- this.schedule.timeslots[this.activeEntry].actions.forEach(action => {
- action = omit(action, 'entity_id');
- if (!this.actions.find(e => compareActions(e, action, true) && Object.keys(e.variables || {}).length))
- return;
- if (!actions.some(e => isEqual(e, action)))
- actions.push(action);
- });
- return actions.map(action => {
- return Object.entries(this.actions.find(e => compareActions(e, action, true)).variables).map(([field, variable]) => {
- return T `
-
- this.entities.forEach((_, num) => {
- this.updateActiveEntryAction({
- service_data: { [field]: ev.detail.value },
- }, num);
- })}
- >
- ${this.hass.localize('ui.dialogs.helper_settings.input_select.no_options')}
-
- `;
- });
- });
- }
- selectDays(ev) {
- const value = ev.target.value;
- let weekdays = this.schedule.weekdays;
- if (Object.values(EDayType).includes(value)) {
- switch (value) {
- case EDayType.Daily:
- weekdays = ['daily'];
- break;
- case EDayType.Workday:
- weekdays = ['workday'];
- break;
- case EDayType.Weekend:
- weekdays = ['weekend'];
- break;
- case EDayType.Custom:
- weekdays = [];
- break;
- }
- }
- else {
- weekdays = value;
- }
- this.schedule = Object.assign(Object.assign({}, this.schedule), { weekdays: weekdays });
- }
- cancelClick() {
- const myEvent = new CustomEvent('cancelClick');
- this.dispatchEvent(myEvent);
- }
- saveClick() {
- const myEvent = new CustomEvent('saveClick', { detail: this.schedule });
- this.dispatchEvent(myEvent);
- }
- optionsClick() {
- const myEvent = new CustomEvent('optionsClick', { detail: this.schedule });
- this.dispatchEvent(myEvent);
- }
- editActionClick() {
- const myEvent = new CustomEvent('editActionClick', { detail: this.schedule });
- this.dispatchEvent(myEvent);
- }
- async deleteClick(ev) {
- const element = ev.target;
- const result = await new Promise(resolve => {
- A$1(element, 'show-dialog', {
- dialogTag: 'dialog-delete-confirm',
- dialogImport: () => Promise.resolve().then(function () { return dialogDeleteConfirm; }),
- dialogParams: {
- cancel: () => {
- resolve(false);
- },
- confirm: () => {
- resolve(true);
- },
- },
- });
- });
- if (result) {
- const myEvent = new CustomEvent('deleteClick');
- this.dispatchEvent(myEvent);
- }
- }
- };
- SchedulerTimepickerCard.styles = i `
- ${commonStyle}
- div.summary {
- display: grid;
- grid-template-columns: 1fr max-content 1fr;
- grid-template-areas: 'entity arrow action';
- grid-auto-flow: column;
- grid-gap: 5px;
- }
-
- div.summary-entity {
- grid-area: entity;
- }
- div.summary-action {
- grid-area: action;
- }
- div.summary-arrow {
- grid-area: arrow;
- color: var(--secondary-text-color);
- display: flex;
- justify-content: center;
- align-items: center;
- }
- div.summary-entity,
- div.summary-action {
- color: var(--dark-primary-color);
- padding: 5px;
- font-size: 14px;
- font-weight: 500;
- --mdc-icon-size: 20px;
- position: relative;
- display: flex;
- flex-direction: column;
- cursor: pointer;
- background: rgba(var(--rgb-primary-color), 0.15);
- border-radius: 4px;
- align-items: center;
- }
- div.summary-entity div,
- div.summary-action div {
- display: flex;
- flex-grow: 1;
- margin: 5px;
- width: 100%;
- align-items: center;
- }
- div.summary-entity ha-icon,
- div.summary-action ha-icon {
- display: flex;
- flex: 0 0 30px;
- }
- `;
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "hass", void 0);
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "config", void 0);
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "schedule", void 0);
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "actions", void 0);
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "entities", void 0);
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "activeEntry", void 0);
- __decorate([
- e$3()
- ], SchedulerTimepickerCard.prototype, "activeMarker", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], SchedulerTimepickerCard.prototype, "timeslots", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], SchedulerTimepickerCard.prototype, "editItem", void 0);
- SchedulerTimepickerCard = __decorate([
- n$4('scheduler-timepicker-card')
- ], SchedulerTimepickerCard);
-
- let SchedulerSelect = class SchedulerSelect extends h$2 {
- constructor() {
- super(...arguments);
- this.label = '';
- this.items = [];
- this.clearable = false;
- this.icons = false;
- this.disabled = false;
- this.allowCustomValue = false;
- this.invalid = false;
- this.rowRenderer = (root, _owner, entry) => {
- if (!root.firstElementChild && this.icons) {
- root.innerHTML = `
-
-
-
-
-
-
-
-
- `;
- root.querySelector('.name').textContent = entry.item.name;
- root.querySelector('[secondary]').textContent = entry.item.description || '';
- root.querySelector('ha-icon').icon = entry.item.icon;
- }
- else if (!root.firstElementChild) {
- root.innerHTML = `
-
-
-
- ${entry.item.name}
-
-
- `;
- }
- };
- }
- open() {
- this.updateComplete.then(() => {
- var _a, _b;
- (_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('vaadin-combo-box-light')) === null || _b === void 0 ? void 0 : _b.open();
- });
- }
- focus() {
- this.updateComplete.then(() => {
- var _a;
- ((_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('paper-input')).focus();
- });
- }
- shouldUpdate(changedProps) {
- if (changedProps.get('items')) {
- if (!isEqual(this.items, changedProps.get('items')))
- this.firstUpdated();
- else if (changedProps.size == 1)
- return false;
- }
- return true;
- }
- firstUpdated() {
- (async () => await loadHaForm())();
- this._comboBox.items = this.items;
- }
- render() {
- return T `
-
-
- ${isDefined(this._value) && this.items.find(e => e.value == this._value)
- ? T `
- ${this.icons
- ? T `
-
- `
- : ''}
- ${this.clearable
- ? T `
-
-
- `
- : ''}
- `
- : ''}
-
-
-
-
- `;
- }
- _clearValue(ev) {
- ev.stopPropagation();
- this._setValue('');
- }
- get _value() {
- return isDefined(this.value) ? this.value : '';
- }
- _openedChanged(ev) {
- this._opened = ev.detail.value;
- }
- _valueChanged(ev) {
- const newValue = ev.detail.value;
- if (newValue !== this._value) {
- this._setValue(newValue);
- }
- }
- _setValue(value) {
- this.value = value;
- setTimeout(() => {
- A$1(this, 'value-changed', { value });
- }, 0);
- }
- static get styles() {
- return i `
- :host {
- line-height: 1em;
- }
- paper-input > ha-icon-button {
- --mdc-icon-button-size: 24px;
- padding: 2px;
- color: var(--secondary-text-color);
- }
- [hidden] {
- display: none;
- }
- paper-input > ha-icon {
- display: flex;
- flex: 0 0 40px;
- color: var(--state-icon-color);
- width: 40px;
- height: 26px;
- align-items: center;
- }
- `;
- }
- };
- __decorate([
- e$3()
- ], SchedulerSelect.prototype, "label", void 0);
- __decorate([
- e$3()
- ], SchedulerSelect.prototype, "value", void 0);
- __decorate([
- e$3()
- ], SchedulerSelect.prototype, "items", void 0);
- __decorate([
- e$3()
- ], SchedulerSelect.prototype, "clearable", void 0);
- __decorate([
- e$3()
- ], SchedulerSelect.prototype, "icons", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], SchedulerSelect.prototype, "disabled", void 0);
- __decorate([
- r$3()
- ], SchedulerSelect.prototype, "_opened", void 0);
- __decorate([
- e$3({ attribute: 'allow-custom-value', type: Boolean })
- ], SchedulerSelect.prototype, "allowCustomValue", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], SchedulerSelect.prototype, "invalid", void 0);
- __decorate([
- o$5('vaadin-combo-box-light', true)
- ], SchedulerSelect.prototype, "_comboBox", void 0);
- SchedulerSelect = __decorate([
- n$4('scheduler-select')
- ], SchedulerSelect);
-
- let SchedulerSelector = class SchedulerSelector extends h$2 {
- constructor() {
- super(...arguments);
- this.items = [];
- this.value = [];
- this.label = '';
- this.invalid = false;
- }
- shouldUpdate(changedProps) {
- if (changedProps.get('items')) {
- if (!isEqual(this.items, changedProps.get('items')))
- this.firstUpdated();
- }
- return true;
- }
- firstUpdated() {
- //remove items from selection which are not in the list (anymore)
- if (this.value.some(e => !this.items.map(v => v.value).includes(e))) {
- this.value = this.value.filter(e => this.items.map(v => v.value).includes(e));
- A$1(this, 'value-changed', { value: this.value });
- }
- }
- render() {
- return T `
-
- ${this.value.length
- ? this.value
- .map(val => this.items.find(e => e.value == val))
- .filter(isDefined)
- .map(e => T `
-
-
- ${e.name}
-
- this._removeClick(e.value)}>
-
-
-
- `)
- : ''}
-
!this.value.includes(e.value))}
- label=${this.label}
- .icons=${false}
- .allowCustomValue=${true}
- @value-changed=${this._addClick}
- ?invalid=${this.invalid && this.value.length != this.items.length}
- >
-
-
- `;
- }
- _removeClick(value) {
- this.value = this.value.filter(e => e !== value);
- A$1(this, 'value-changed', { value: this.value });
- }
- _addClick(ev) {
- ev.stopPropagation();
- const target = ev.target;
- const value = target.value;
- if (!this.value.includes(value))
- this.value = [...this.value, value];
- target.value = '';
- A$1(this, 'value-changed', { value: [...this.value] });
- }
- static get styles() {
- return i `
- div.chip {
- height: 32px;
- border-radius: 16px;
- border: 2px solid rgba(var(--rgb-primary-color), 0.54);
- line-height: 1.25rem;
- font-size: 0.875rem;
- font-weight: 400;
- padding: 0px 12px;
- display: inline-flex;
- align-items: center;
- box-sizing: border-box;
- margin: 1px 0px;
- }
- .icon {
- vertical-align: middle;
- outline: none;
- display: flex;
- align-items: center;
- border-radius: 50%;
- padding: 6px;
- color: rgba(0, 0, 0, 0.54);
- background: rgb(168, 232, 251);
- --mdc-icon-size: 20px;
- margin-left: -14px !important;
- }
- .label {
- margin: 0px 4px;
- }
- .button {
- cursor: pointer;
- background: var(--secondary-text-color);
- border-radius: 50%;
- --mdc-icon-size: 14px;
- color: var(--card-background-color);
- width: 16px;
- height: 16px;
- padding: 1px;
- box-sizing: border-box;
- display: inline-flex;
- align-items: center;
- margin-right: -6px !important;
- }
- `;
- }
- };
- __decorate([
- e$3()
- ], SchedulerSelector.prototype, "items", void 0);
- __decorate([
- e$3({ type: Array })
- ], SchedulerSelector.prototype, "value", void 0);
- __decorate([
- e$3()
- ], SchedulerSelector.prototype, "label", void 0);
- __decorate([
- e$3({ type: Boolean })
- ], SchedulerSelector.prototype, "invalid", void 0);
- SchedulerSelector = __decorate([
- n$4('scheduler-selector')
- ], SchedulerSelector);
-
- const getMatchTypes = (hass, filter) => {
- let output = {};
- if (!(filter === null || filter === void 0 ? void 0 : filter.length) || filter.includes(EConditionMatchType.Above))
- output = Object.assign(Object.assign({}, output), { [EConditionMatchType.Above]: {
- value: EConditionMatchType.Above,
- name: hass.localize('ui.panel.config.automation.editor.triggers.type.numeric_state.above'),
- icon: 'hass:greater-than',
- } });
- if (!(filter === null || filter === void 0 ? void 0 : filter.length) || filter.includes(EConditionMatchType.Below))
- output = Object.assign(Object.assign({}, output), { [EConditionMatchType.Below]: {
- value: EConditionMatchType.Below,
- name: hass.localize('ui.panel.config.automation.editor.triggers.type.numeric_state.below'),
- icon: 'hass:less-than',
- } });
- if (!(filter === null || filter === void 0 ? void 0 : filter.length) || filter.includes(EConditionMatchType.Equal))
- output = Object.assign(Object.assign({}, output), { [EConditionMatchType.Equal]: {
- value: EConditionMatchType.Equal,
- name: localize('ui.panel.conditions.equal_to', getLocale(hass)),
- icon: 'hass:equal',
- } });
- if (!(filter === null || filter === void 0 ? void 0 : filter.length) || filter.includes(EConditionMatchType.Unequal))
- output = Object.assign(Object.assign({}, output), { [EConditionMatchType.Unequal]: {
- value: EConditionMatchType.Unequal,
- name: localize('ui.panel.conditions.unequal_to', getLocale(hass)),
- icon: 'hass:not-equal-variant',
- } });
- return output;
- };
- let SchedulerOptionsCard = class SchedulerOptionsCard extends h$2 {
- constructor() {
- super(...arguments);
- this.addCondition = false;
- this.tags = [];
- this.startDate = '';
- this.endDate = '';
- }
- async firstUpdated() {
- var _a, _b, _c;
- if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.tags) {
- (async () => await loadHaForm())();
- const tagEntries = await fetchTags(this.hass);
- const existingTags = tagEntries.map(e => e.name);
- const configTags = AsArray(this.config.tags);
- this.tags = [...existingTags, ...configTags.filter(e => !existingTags.includes(e) && e != 'none')];
- }
- (await window.loadCardHelpers()).importMoreInfoControl('input_datetime');
- this.startDate = ((_b = this.schedule) === null || _b === void 0 ? void 0 : _b.start_date) || formatDate(new Date(), getLocale(this.hass), true);
- this.endDate = ((_c = this.schedule) === null || _c === void 0 ? void 0 : _c.end_date) || formatDate(new Date(), getLocale(this.hass), true);
- }
- render() {
- var _a, _b;
- if (!this.hass || !this.config || !this.schedule)
- return T ``;
- let repeatTypes = [
- {
- name: this.hass.localize('ui.panel.config.automation.editor.actions.type.repeat.label'),
- value: ERepeatType.Repeat,
- icon: 'refresh',
- },
- {
- name: this.hass.localize('ui.dialogs.more_info_control.vacuum.stop'),
- value: ERepeatType.Pause,
- icon: 'stop',
- },
- {
- name: this.hass.localize('ui.common.delete'),
- value: ERepeatType.Single,
- icon: 'trash-can-outline',
- },
- ];
- if (isDefined(this.schedule.start_date)) {
- repeatTypes = repeatTypes.filter(e => e.value != ERepeatType.Repeat);
- }
- return T `
-
-
-
- ${!this.addCondition
- ? T `
-
- ${this.renderConditions()}
-
-
-
-
-
- ${this.hass.localize('ui.dialogs.helper_settings.input_select.add')}
-
-
-
- ${this.schedule.timeslots[0].stop &&
- this.schedule.timeslots[0].conditions &&
- this.schedule.timeslots[0].conditions.length > 0
- ? T `
-
- this.shadowRoot.querySelector('#track_conditions').click()}
- >
- ${localize('ui.panel.conditions.track_conditions', getLocale(this.hass))}
-
- `
- : ''}
-
-
-
-
-
-
-
-
-
-
-
-
- ${PrettyPrintName(((_a = localize('ui.components.date.days_range', getLocale(this.hass))
- .split('{')
- .shift()) === null || _a === void 0 ? void 0 : _a.trim()) || '')}
-
-
-
-
-
-
-
- ${PrettyPrintName(((_b = localize('ui.components.date.days_range', getLocale(this.hass))
- .split('}')[1]
- .split('{')
- .shift()) === null || _b === void 0 ? void 0 : _b.trim()) || '')}
-
-
-
-
-
-
-
-
-
-
- ${this.config.tags
- ? T `
-
-
-
- `
- : ''}
-
-
-
-
- `
- : this.renderAddCondition()}
-
-
- ${!this.addCondition
- ? T `
- e.actions.length).length}
- >
- ${this.hass.localize('ui.common.save')}
-
- ${this.hass.localize('ui.common.back')}
- `
- : T `
- ${this.hass.localize('ui.common.save')}
- ${this.editItem !== undefined
- ? T `
- ${this.hass.localize('ui.common.delete')}
- `
- : ''}
- ${this.hass.localize('ui.common.cancel')}
- `}
-
-
- `;
- }
- renderAddCondition() {
- if (!this.addCondition || !this.hass || !this.config)
- return T ``;
- if (!this.selectedEntity) {
- const hassEntities = computeEntities$1(this.hass, this.config, { filterActions: false, filterStates: true });
- const groups = entityGroups(hassEntities, this.config, this.hass);
- groups.sort((a, b) => (a.name.trim().toLowerCase() < b.name.trim().toLowerCase() ? -1 : 1));
- let entities = [];
- if (this.selectedGroup) {
- entities = groups
- .find(e => isEqual(e, this.selectedGroup))
- .entities.map(e => parseEntity(e, this.hass, this.config));
- entities.sort((a, b) => (a.name.trim().toLowerCase() < b.name.trim().toLowerCase() ? -1 : 1));
- }
- return T `
-
-
- isEqual(e, this.selectedGroup))}
- @change=${this.selectGroup}
- >
- ${localize('ui.panel.entity_picker.no_groups_defined', getLocale(this.hass))}
-
-
-
- isEqual(e, this.selectedEntity))}
- @change=${this.selectEntity}
- >
- ${!this.selectedGroup
- ? localize('ui.panel.entity_picker.no_group_selected', getLocale(this.hass))
- : localize('ui.panel.entity_picker.no_entities_for_group', getLocale(this.hass))}
-
- `;
- }
- else {
- const entity = this.selectedEntity;
- const states = computeStates(entity.id, this.hass, this.config);
- let availableMatchTypes;
- if ((states === null || states === void 0 ? void 0 : states.type) == EVariableType.Level)
- availableMatchTypes = [EConditionMatchType.Above, EConditionMatchType.Below];
- else if ((states === null || states === void 0 ? void 0 : states.type) == EVariableType.List)
- availableMatchTypes = [EConditionMatchType.Equal, EConditionMatchType.Unequal];
- else {
- const currentState = entity.id in this.hass.states ? this.hass.states[entity.id].state : null;
- if (!currentState || ['unavailable', 'unknown'].includes(currentState))
- availableMatchTypes = [
- EConditionMatchType.Equal,
- EConditionMatchType.Unequal,
- EConditionMatchType.Above,
- EConditionMatchType.Below,
- ];
- else if (!isNaN(Number(currentState)))
- availableMatchTypes = [EConditionMatchType.Above, EConditionMatchType.Below];
- else
- availableMatchTypes = [EConditionMatchType.Equal, EConditionMatchType.Unequal];
- }
- const matchTypes = getMatchTypes(this.hass, availableMatchTypes);
- return T `
-
-
-
-
- ${PrettyPrintName(entity.name)}
-
- {
- this.selectedEntity = undefined;
- }}
- >
-
-
-
-
- (this.conditionMatchType = ev.target.value)}
- >
-
-
-
- (this.conditionValue = ev.detail.value)}
- >
-
- `;
- }
- }
- selectGroup(ev) {
- this.selectedGroup = ev.detail;
- this.selectedEntity = undefined;
- }
- selectEntity(ev) {
- this.selectedEntity = ev.detail;
- this.conditionMatchType = undefined;
- this.conditionValue = undefined;
- }
- renderConditions() {
- if (!this.hass || !this.schedule)
- return T ``;
- const conditions = this.schedule.timeslots[0].conditions || [];
- if (!conditions.length)
- return T `
- ${localize('ui.panel.conditions.no_conditions_defined', getLocale(this.hass))}
- `;
- return conditions.map((item, num) => {
- const entity = parseEntity(item.entity_id, this.hass, this.config);
- const states = computeStates(item.entity_id, this.hass, this.config);
- return T `
-
-
-
- ${PrettyPrintName(entity.name)} ${getMatchTypes(this.hass)[item.match_type].name.toLowerCase()}
- ${states
- ? states.type == EVariableType.List
- ? listVariableDisplay(item.value, states)
- : states.type == EVariableType.Level
- ? levelVariableDisplay(item.value, states)
- : ''
- : ''}
-
- {
- this.editConditionClick(num);
- }}
- >
-
-
- `;
- });
- }
- addConditionClick() {
- this.addCondition = true;
- this.selectedEntity = undefined;
- this.selectedGroup = undefined;
- }
- confirmConditionClick() {
- var _a;
- if (!this.selectedEntity ||
- !this.config ||
- !this.hass ||
- !this.schedule ||
- !this.conditionMatchType ||
- !isDefined(this.conditionValue))
- return;
- const condition = {
- entity_id: this.selectedEntity.id,
- match_type: this.conditionMatchType,
- value: this.conditionValue,
- attribute: 'state',
- };
- const conditions = ((_a = this.schedule.timeslots[0].conditions) === null || _a === void 0 ? void 0 : _a.length) ? [...this.schedule.timeslots[0].conditions] : [];
- const type = this.schedule.timeslots[0].condition_type
- ? this.schedule.timeslots[0].condition_type
- : EConditionType.Any;
- if (this.editItem === undefined)
- conditions.push(condition);
- else
- conditions.splice(this.editItem, 1, condition);
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: this.schedule.timeslots.map(e => Object.assign(e, {
- conditions: conditions,
- condition_type: type,
- })) });
- this.addCondition = false;
- this.editItem = undefined;
- }
- cancelConditionClick() {
- this.addCondition = false;
- this.editItem = undefined;
- }
- editConditionClick(index) {
- if (!this.schedule || !this.schedule.timeslots[0].conditions || !this.hass || !this.config)
- return;
- const item = this.schedule.timeslots[0].conditions[index];
- if (!item)
- return;
- this.editItem = index;
- const hassEntities = computeEntities$1(this.hass, this.config, { filterActions: false, filterStates: true });
- const groups = entityGroups(hassEntities, this.config, this.hass);
- this.selectedGroup = groups.find(e => e.entities.includes(item.entity_id));
- this.selectedEntity = parseEntity(item.entity_id, this.hass, this.config);
- this.conditionMatchType = item.match_type;
- this.conditionValue = item.value;
- this.addCondition = true;
- }
- deleteConditionClick() {
- var _a;
- if (!this.config || !this.hass || !this.schedule || this.editItem === undefined)
- return;
- const conditions = ((_a = this.schedule.timeslots[0].conditions) === null || _a === void 0 ? void 0 : _a.length) ? [...this.schedule.timeslots[0].conditions] : [];
- conditions.splice(this.editItem, 1);
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: this.schedule.timeslots.map(e => Object.assign(e, {
- conditions: conditions,
- })) });
- this.addCondition = false;
- this.editItem = undefined;
- }
- conditionTypeSwitchClick(e) {
- if (!this.schedule)
- return;
- const checked = e.target.checked;
- const type = checked ? EConditionType.All : EConditionType.Any;
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: this.schedule.timeslots.map(e => Object.assign(e, {
- condition_type: type,
- })) });
- }
- trackConditionsClick(e) {
- if (!this.schedule)
- return;
- const checked = e.target.checked;
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: this.schedule.timeslots.map(e => Object(Object.assign(Object.assign({}, e), { track_conditions: checked }))) });
- }
- _setStartDate(ev) {
- const value = String(ev.detail.value);
- if (!value)
- return;
- const startDate = stringToDate(value);
- const endDate = stringToDate(this.endDate);
- if (startDate > endDate) {
- this.schedule = Object.assign(Object.assign({}, this.schedule), { end_date: value });
- this.endDate = value;
- }
- this.schedule = Object.assign(Object.assign({}, this.schedule), { start_date: value });
- this.startDate = value;
- }
- _setEndDate(ev) {
- const value = String(ev.detail.value);
- if (!value)
- return;
- const startDate = stringToDate(this.startDate);
- const endDate = stringToDate(value);
- if (startDate > endDate) {
- this.schedule = Object.assign(Object.assign({}, this.schedule), { start_date: value });
- this.startDate = value;
- }
- this.schedule = Object.assign(Object.assign({}, this.schedule), { end_date: value });
- this.endDate = value;
- }
- toggleEnableDateRange(ev) {
- const checked = ev.target.checked;
- const datePickers = this.shadowRoot.querySelectorAll('ha-date-input');
- this.schedule = Object.assign(Object.assign({}, this.schedule), { start_date: checked ? this.startDate : undefined, end_date: checked ? this.endDate : undefined, repeat_type: checked
- ? this.schedule.repeat_type == ERepeatType.Repeat
- ? ERepeatType.Pause
- : this.schedule.repeat_type
- : this.schedule.repeat_type == ERepeatType.Pause
- ? ERepeatType.Repeat
- : this.schedule.repeat_type });
- }
- updateName(e) {
- const value = e.target.value;
- this.schedule = Object.assign(Object.assign({}, this.schedule), { name: value });
- }
- updateRepeatType(e) {
- const value = e.target.value;
- this.schedule = Object.assign(Object.assign({}, this.schedule), { repeat_type: value });
- }
- getTagOptions() {
- var _a;
- let output = [...this.tags];
- if ((_a = this.schedule) === null || _a === void 0 ? void 0 : _a.tags.length)
- output = [...output, ...this.schedule.tags.filter(e => !output.includes(e))];
- output.sort(sortAlphabetically);
- return output.map(e => Object({ name: e, value: e }));
- }
- updateTags(ev) {
- let value = ev.target.value;
- value = value.map(e => e.trim());
- value = value.filter(e => e != 'none');
- value.sort(sortAlphabetically);
- this.schedule = Object.assign(Object.assign({}, this.schedule), { tags: value });
- }
- cancelClick() {
- if (this.addCondition) {
- this.addCondition = !this.addCondition;
- }
- else {
- const myEvent = new CustomEvent('cancelClick');
- this.dispatchEvent(myEvent);
- }
- }
- saveClick() {
- const myEvent = new CustomEvent('saveClick', {
- detail: this.schedule,
- });
- this.dispatchEvent(myEvent);
- }
- backClick() {
- const myEvent = new CustomEvent('backClick', {
- detail: this.schedule,
- });
- this.dispatchEvent(myEvent);
- }
- };
- SchedulerOptionsCard.styles = i `
- ${commonStyle}
- div.summary {
- display: flex;
- flex-direction: row;
- align-items: center;
- padding: 4px 0px;
- background: rgba(var(--rgb-primary-color), 0.15);
- color: var(--dark-primary-color);
- border-radius: 8px;
- margin: 2px 0px;
- font-size: 14px;
- font-weight: 500;
- }
- div.summary ha-icon {
- flex: 0 0 48px;
- justify-content: center;
- display: flex;
- }
- div.summary span {
- flex: 1 0 60px;
- display: flex;
- }
- div.summary ha-icon-button {
- margin: -8px 0px;
- }
- div.date-range {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- }
- div.date-range div {
- display: flex;
- align-items: center;
- }
- div.date-range div span {
- display: inline-flex;
- padding: 0px 10px;
- }
- div.date-range div:first-child span {
- padding-left: 0px;
- }
- div.condition-options {
- display: flex;
- flex-direction: row;
- margin-top: 10px;
- }
- div.track-conditions {
- display: flex;
- flex-direction: row;
- text-align: right;
- align-items: center;
- max-width: 50%;
- }
- div.track-conditions span {
- text-align: left;
- }
- `;
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "hass", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "config", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "schedule", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "selectedGroup", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "selectedEntity", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "conditionMatchType", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "conditionValue", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "editItem", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "addCondition", void 0);
- __decorate([
- e$3()
- ], SchedulerOptionsCard.prototype, "tags", void 0);
- __decorate([
- r$3()
- ], SchedulerOptionsCard.prototype, "startDate", void 0);
- __decorate([
- r$3()
- ], SchedulerOptionsCard.prototype, "endDate", void 0);
- SchedulerOptionsCard = __decorate([
- n$4('scheduler-options-card')
- ], SchedulerOptionsCard);
-
- let SchedulerCardEditor = class SchedulerCardEditor extends h$2 {
- constructor() {
- super(...arguments);
- this.scheduleEntities = [];
- this._cardTab = false;
- this.selectedDomain = '';
- }
- setConfig(config) {
- this._config = config;
- }
- async firstUpdated() {
- await loadHaForm();
- this.scheduleEntities = (await fetchSchedules(this.hass)).map(e => e.entity_id);
- const tagOptions = (await fetchTags(this.hass)).map(e => e.name);
- tagOptions.sort(sortAlphabetically);
- this.tagOptions = tagOptions;
- }
- render() {
- if (!this.hass || !this._config) {
- return T ``;
- }
- return T `
-
-
-
-
-
-
- ${!this._cardTab
- ? T `
-
-
- ${localize('ui.panel.card_editor.fields.entities.description', getLocale(this.hass))}
-
- ${this.getDomainSwitches()}
- `
- : T `
-
-
this._setTitleFormatOption(ev.target.value)}
- >
-
- ${typeof this._config.title == 'string'
- ? T `
-
{
- this._updateConfig({ title: String(ev.target.value) });
- }}
- >
- `
- : ''}
-
-
-
- ${localize('ui.panel.card_editor.fields.discover_existing.description', getLocale(this.hass))}
-
-
{
- this._updateConfig({ discover_existing: ev.target.checked });
- }}
- >
-
-
-
-
- ${localize('ui.panel.card_editor.fields.time_step.description', getLocale(this.hass))}
-
-
{
- this._updateConfig({ time_step: Number(ev.detail.value) });
- }}
- >
-
-
-
-
- ${localize('ui.panel.card_editor.fields.sort_by.description', getLocale(this.hass))}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${localize('ui.panel.card_editor.fields.display_format_primary.description', getLocale(this.hass))}
-
-
-
-
-
-
-
-
-
-
-
- ${localize('ui.panel.card_editor.fields.display_format_secondary.description', getLocale(this.hass))}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${localize('ui.panel.card_editor.fields.show_header_toggle.description', getLocale(this.hass))}
-
-
{
- this._updateConfig({ show_header_toggle: ev.target.checked });
- }}
- >
-
-
- ${this.tagOptions !== undefined
- ? T `
-
-
- ${localize('ui.panel.card_editor.fields.tags.description', getLocale(this.hass))}
-
-
-
- `
- : ''}
- `}
-
- `;
- }
- _selectTab(ev) {
- this._cardTab = ev.detail.index === 1;
- }
- _updateConfig(changes) {
- if (!this._config)
- return;
- this._config = Object.assign(Object.assign({}, this._config), changes);
- A$1(this, 'config-changed', { config: this._config });
- }
- _setTitleFormatOption(option) {
- var _a;
- if (!this.hass)
- return;
- if (option == 'standard')
- this._updateConfig({ title: true });
- else if (option == 'hidden')
- this._updateConfig({ title: false });
- else
- this._updateConfig({
- title: typeof ((_a = this._config) === null || _a === void 0 ? void 0 : _a.title) === 'string'
- ? this._config.title
- : localize('ui.panel.common.title', getLocale(this.hass)),
- });
- }
- getTitleOption() {
- if (!this.hass || !this._config)
- return '';
- if (typeof this._config.title == 'string')
- return 'custom';
- return this._config.title ? 'standard' : 'hidden';
- }
- updateTags(ev) {
- if (!this._config || !this.hass)
- return;
- let value = ev.target.value;
- value = value.map(e => e.trim());
- value.sort(sortAlphabetically);
- this._updateConfig({ tags: value });
- }
- getTagOptions() {
- if (!this._config || !this.hass)
- return [];
- let options = this.tagOptions || [];
- if (this._config.tags) {
- const configTags = AsArray(this._config.tags);
- options = [...options, ...configTags.filter(e => !options.includes(e))];
- }
- return options.map(e => Object({ name: e, value: e }));
- }
- _setSortBy(ev) {
- var _a;
- const checked = ev.target.checked;
- const value = ev.target.value;
- let config = AsArray(((_a = this._config) === null || _a === void 0 ? void 0 : _a.sort_by) || DefaultCardConfig.sort_by);
- if (value != 'state' && checked)
- config = config.filter(e => e == 'state');
- if (!config.includes(value) && checked)
- config = [...config, value];
- if (config.includes(value) && !checked)
- config = config.filter(e => e != value);
- this._updateConfig({ sort_by: config });
- }
- _setDisplayOptionsPrimary(ev) {
- var _a;
- const value = ev.target.value;
- const displayOptions = Object.assign(Object.assign({}, (((_a = this._config) === null || _a === void 0 ? void 0 : _a.display_options) || DefaultCardConfig.display_options)), { primary_info: value });
- this._updateConfig({ display_options: displayOptions });
- }
- _setDisplayOptionsSecondary(ev) {
- var _a;
- const value = ev.target.value;
- const checked = ev.target.checked;
- let displayOptions = Object.assign({}, (((_a = this._config) === null || _a === void 0 ? void 0 : _a.display_options) || DefaultCardConfig.display_options));
- let secondaryInfo = AsArray(displayOptions.secondary_info || []);
- secondaryInfo = checked ? Array.from(new Set([...secondaryInfo, value])) : secondaryInfo.filter(e => e !== value);
- secondaryInfo.sort((a, b) => {
- const ranking = {
- 'relative-time': 1,
- time: secondaryInfo.includes('relative-time') ? 3 : 2,
- days: secondaryInfo.includes('relative-time') ? 2 : 3,
- 'additional-tasks': 4,
- };
- const rankA = Object.keys(ranking).includes(a) ? ranking[a] : 5;
- const rankB = Object.keys(ranking).includes(b) ? ranking[b] : 5;
- if (rankA > rankB)
- return 1;
- if (rankA < rankB)
- return -1;
- return 0;
- });
- displayOptions = Object.assign(Object.assign({}, displayOptions), { secondary_info: [...secondaryInfo] });
- this._updateConfig({ display_options: displayOptions });
- }
- getDomainSwitches() {
- if (!this._config || !this.hass)
- return;
- const entities = computeEntities$1(this.hass, Object.assign(Object.assign({}, DefaultCardConfig), { include: ['*'] }), { filterActions: true, filterStates: true })
- .filter(e => g$1(e) !== 'switch' || !this.scheduleEntities.includes(e))
- .map(e => parseEntity(e, this.hass, { include: ['*'] }))
- .filter(e => standardStates(e.id, this.hass) || computeActions(e.id, this.hass, DefaultCardConfig));
- const domainList = entities.map(e => g$1(e.id)).filter((v, k, arr) => arr.indexOf(v) === k);
- domainList.sort((a, b) => (a.trim().toLowerCase() < b.trim().toLowerCase() ? -1 : 1));
- return domainList.map(domain => {
- var _a;
- const count = entities.filter(e => g$1(e.id) == domain).length;
- const domainEntities = entities.filter(e => g$1(e.id) == domain);
- const includedCount = domainEntities.filter(e => entityFilter(e.id, this._config)).length;
- if (!count)
- return ``;
- return T `
- this.toggleShowDomain(domain)}>
-
-
-
- ${domain}
-
- ${localize('ui.panel.card_editor.fields.entities.included_number', getLocale(this.hass), ['{number}', '{total}'], [includedCount, count])}
-
-
-
ev.stopPropagation()}
- @change=${(ev) => this.toggleSelectEntity(domain, ev.target.checked)}
- ?checked=${entityFilter(domain, this._config)}
- ?disabled=${entityFilter(domain, { groups: (_a = this._config) === null || _a === void 0 ? void 0 : _a.groups })}
- >
-
-
- ${this.selectedDomain == domain
- ? T `
-
- ${domainEntities.map(entity => {
- var _a, _b;
- return T `
- this.toggleSelectEntity(entity.id)}>
-
-
- ${entity.name}
-
- ${entity.id}
-
-
-
-
- `;
- })}
-
- `
- : ''}
- `;
- });
- }
- toggleShowDomain(domain) {
- if (!this._config || !this.hass)
- return;
- if (this.selectedDomain != domain) {
- this.selectedDomain = domain;
- }
- else {
- this.selectedDomain = '';
- }
- }
- toggleSelectEntity(entity_id, newValue) {
- if (!this._config || !this.hass)
- return;
- const isIncluded = entityFilter(entity_id, this._config);
- if (newValue === undefined)
- newValue = !isIncluded;
- const entityDomain = g$1(entity_id);
- let include = [...(this._config.include || [])];
- let exclude = [...(this._config.exclude || [])];
- if (!isIncluded && newValue) {
- if (exclude.includes(entity_id))
- exclude = exclude.filter(e => e != entity_id);
- if (!include.includes(entity_id))
- include = [...include, entity_id];
- }
- else if (isIncluded && !newValue) {
- if ((entityDomain && include.includes(entityDomain)) ||
- entityFilter(entity_id, { customize: this._config.customize }) ||
- (entityDomain && entityFilter(entityDomain, { customize: this._config.customize })))
- exclude = [...exclude, entity_id];
- if (include.includes(entity_id))
- include = include.filter(e => e != entity_id);
- }
- else
- return;
- include.sort(sortAlphabetically);
- exclude.sort(sortAlphabetically);
- this._updateConfig({ include: include, exclude: exclude });
- }
- static get styles() {
- return i `
- ${commonStyle}
- div.row {
- display: flex;
- align-items: center;
- flex-direction: row;
- cursor: pointer;
- margin: 10px 0px;
- }
- div.divider {
- height: 1px;
- background: var(--divider-color);
- }
- .info {
- margin-left: 16px;
- flex: 1 0 60px;
- }
- .info,
- .info > * {
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .secondary {
- display: block;
- color: var(--secondary-text-color);
- }
- div.row ha-icon {
- padding: 8px;
- color: var(--paper-item-icon-color);
- }
- div.row state-badge {
- flex: 0 0 40px;
- }
- div.row ha-switch {
- padding: 13px 5px;
- }
- `;
- }
- };
- __decorate([
- e$3()
- ], SchedulerCardEditor.prototype, "hass", void 0);
- __decorate([
- e$3()
- ], SchedulerCardEditor.prototype, "_config", void 0);
- __decorate([
- e$3()
- ], SchedulerCardEditor.prototype, "scheduleEntities", void 0);
- __decorate([
- e$3()
- ], SchedulerCardEditor.prototype, "tagOptions", void 0);
- __decorate([
- r$3()
- ], SchedulerCardEditor.prototype, "_cardTab", void 0);
- __decorate([
- e$3()
- ], SchedulerCardEditor.prototype, "selectedDomain", void 0);
- SchedulerCardEditor = __decorate([
- n$4('scheduler-card-editor')
- ], SchedulerCardEditor);
-
- let DialogError = class DialogError extends h$2 {
- async showDialog(params) {
- this._params = params;
- await this.updateComplete;
- }
- async closeDialog() {
- this._params = undefined;
- }
- render() {
- if (!this._params)
- return T ``;
- return T `
-
-
-
-
-
- ${this.hass.localize('state_badge.default.error')}
-
-
-
-
- ${this._params.error || ''}
-
-
-
- ${this.hass.localize('ui.dialogs.generic.ok')}
-
-
- `;
- }
- static get styles() {
- return i `
- div.wrapper {
- color: var(--primary-text-color);
- }
- `;
- }
- };
- __decorate([
- e$3({ attribute: false })
- ], DialogError.prototype, "hass", void 0);
- __decorate([
- r$3()
- ], DialogError.prototype, "_params", void 0);
- DialogError = __decorate([
- n$4('dialog-error')
- ], DialogError);
-
- var dialogError = /*#__PURE__*/Object.freeze({
- __proto__: null,
- get DialogError () { return DialogError; }
- });
-
- let DialogDeleteDefective = class DialogDeleteDefective extends h$2 {
- async showDialog(params) {
- this._params = params;
- await this.updateComplete;
- }
- async closeDialog() {
- if (this._params)
- this._params.cancel();
- this._params = undefined;
- }
- render() {
- if (!this._params)
- return T ``;
- return T `
-
-
-
-
-
- Defective entity
-
-
-
-
- This schedule is defective and cannot be edited with the card. Consider to delete the item and recreate it. If
- the problem persists, please report the issue on GitHub.
-
-
-
- ${this.hass.localize('ui.dialogs.generic.cancel')}
-
-
- ${this.hass.localize('ui.common.delete')}
-
-
- `;
- }
- confirmClick() {
- this._params.confirm();
- }
- cancelClick() {
- this._params.cancel();
- }
- static get styles() {
- return i `
- div.wrapper {
- color: var(--primary-text-color);
- }
- `;
- }
- };
- __decorate([
- e$3({ attribute: false })
- ], DialogDeleteDefective.prototype, "hass", void 0);
- __decorate([
- r$3()
- ], DialogDeleteDefective.prototype, "_params", void 0);
- DialogDeleteDefective = __decorate([
- n$4('dialog-delete-defective')
- ], DialogDeleteDefective);
-
- var dialogDeleteDefective = /*#__PURE__*/Object.freeze({
- __proto__: null,
- get DialogDeleteDefective () { return DialogDeleteDefective; }
- });
-
- const migrateActionConfig = (config, entities, actions, hass) => {
- if (!config)
- return null;
- const action = importAction(config, hass);
- let match = actions.find(e => compareActions(e, action, true));
- if (!match)
- return null;
- let output = entities.map(e => assignAction(e, match));
- output = Object.keys(match.variables || {})
- .filter(k => Object.keys(config.service_data || {}).includes(k))
- .reduce((output, variable) => {
- if (!output)
- return output;
- switch (match.variables[variable].type) {
- case EVariableType.Level:
- //keep the selected level variable while maintaining min/max/step size/scale factor
- const levelVariable = match.variables[variable];
- let val = Number(config.service_data[variable]);
- val = val / levelVariable.scale_factor;
- val = Math.round(val / levelVariable.step) * levelVariable.step;
- val = parseFloat(val.toPrecision(12));
- if (val > levelVariable.max)
- val = levelVariable.max;
- else if (val < levelVariable.min)
- val = levelVariable.min;
- val = val * levelVariable.scale_factor;
- val = parseFloat(val.toFixed(2));
- return output.map(e => Object.assign(e, { service_data: Object.assign(Object.assign({}, e.service_data), { [variable]: val }) }));
- case EVariableType.List:
- const listVariable = match.variables[variable];
- if (listVariable.options.some(e => e.value == config.service_data[variable]))
- //keep the selected list variable if it is in common
- return output.map(e => Object.assign(e, { service_data: Object.assign(Object.assign({}, e.service_data), { [variable]: config.service_data[variable] }) }));
- else
- return null;
- case EVariableType.Text:
- //keep the selected text variable
- return output.map(e => Object.assign(e, { service_data: Object.assign(Object.assign({}, e.service_data), { [variable]: config.service_data[variable] }) }));
- default:
- return output;
- }
- }, output);
- return output;
- };
-
- window.customCards = window.customCards || [];
- window.customCards.push({
- type: 'scheduler-card',
- name: 'Scheduler Card',
- description: 'Card to manage schedule entities made with scheduler-component.',
- });
- console.info(`%c SCHEDULER-CARD \n%c Version: ${CARD_VERSION.padEnd(7, ' ')}`, 'color: orange; font-weight: bold; background: black', 'color: white; font-weight: bold; background: dimgray');
- exports.SchedulerCard = class SchedulerCard extends h$2 {
- constructor() {
- super(...arguments);
- this._view = EViews.Overview;
- this.actions = [];
- this.translationsLoaded = false;
- this.editItem = null;
- }
- static getConfigElement() {
- return document.createElement('scheduler-card-editor');
- }
- set hass(hass) {
- this._hass = hass;
- }
- firstUpdated() {
- const hass = this._hass;
- if (hass.localize('ui.panel.config.automation.editor.actions.name'))
- this.translationsLoaded = true;
- else {
- const el = document.querySelector('home-assistant');
- el._loadFragmentTranslations(hass.language, 'config').then(() => {
- this._hass.localize;
- });
- }
- }
- shouldUpdate(changedProps) {
- const oldHass = changedProps.get('_hass');
- if (oldHass && changedProps.size == 1) {
- if (!oldHass.localize('ui.panel.config.automation.editor.actions.name')) {
- this.translationsLoaded = true;
- return true;
- }
- else if (this._view == EViews.Overview)
- return true;
- return false;
- }
- return true;
- }
- setConfig(userConfig) {
- ValidateConfig(userConfig);
- const config = Object.assign(Object.assign({}, DefaultCardConfig), userConfig);
- this._config = config;
- }
- getCardSize() {
- return 9;
- }
- render() {
- if (!this._hass || !this._config || !this.translationsLoaded)
- return T ``;
- if (this._view == EViews.Overview) {
- return T `
-
-
- `;
- }
- else if (this._view == EViews.NewSchedule) {
- return T `
-
-
- `;
- }
- else if (this._view == EViews.TimePicker || this._view == EViews.TimeScheme) {
- return T `
-
-
- `;
- }
- else if (this._view == EViews.Options) {
- return T `
-
-
- `;
- }
- else
- return T ``; //shouldnt happen!
- }
- _addItemClick() {
- this._view = EViews.NewSchedule;
- this.editItem = null;
- this.entities = [];
- this.actions = [];
- this.schedule = undefined;
- }
- _cancelEditClick() {
- this._view = EViews.Overview;
- this.editItem = null;
- }
- _confirmItemClick(ev) {
- if (!this._hass || !this._config)
- return;
- const entities = ev.detail.entities;
- this.entities = entities.map(e => parseEntity(e, this._hass, this._config));
- const timeSchemeSelected = Boolean(ev.detail.timeSchemeSelected);
- const action = ev.detail.action;
- const oldSchedule = this.schedule;
- const defaultTags = AsArray(this._config.tags).length == 1 ? AsArray(this._config.tags).slice(0, 1) : [];
- if (!timeSchemeSelected) {
- this.actions = [action];
- const defaultTimeslot = {
- start: '12:00:00',
- actions: entities.map(e => assignAction(e, this.actions[0])),
- };
- this.schedule = oldSchedule
- ? Object.assign(Object.assign({}, oldSchedule), { timeslots: oldSchedule.timeslots.length == 1 && !oldSchedule.timeslots[0].stop
- ? [
- Object.assign(Object.assign({}, oldSchedule.timeslots[0]), { actions: migrateActionConfig(oldSchedule.timeslots[0].actions[0], entities, this.actions, this._hass) ||
- defaultTimeslot.actions }),
- ]
- : [defaultTimeslot] }) : {
- weekdays: ['daily'],
- timeslots: [defaultTimeslot],
- repeat_type: ERepeatType.Repeat,
- tags: defaultTags,
- };
- this._view = EViews.TimePicker;
- }
- else {
- this.actions = computeActions(entities, this._hass, this._config);
- const defaultTimeslots = [
- {
- start: '00:00:00',
- stop: '08:00:00',
- actions: [],
- },
- {
- start: '08:00:00',
- stop: '16:00:00',
- actions: [],
- },
- {
- start: '16:00:00',
- stop: '00:00:00',
- actions: [],
- },
- ];
- if (oldSchedule) {
- //migrate existing schedule
- const actions = oldSchedule.timeslots
- .map(e => e.actions[0])
- .map(v => migrateActionConfig(v, entities, this.actions, this._hass));
- this.schedule = Object.assign(Object.assign({}, oldSchedule), { timeslots: oldSchedule.timeslots.length > 1 && oldSchedule.timeslots.every(e => e.stop)
- ? oldSchedule.timeslots.map((slot, i) => Object.assign(slot, { actions: actions[i] || [] }))
- : defaultTimeslots });
- }
- else {
- this.schedule = {
- weekdays: ['daily'],
- timeslots: defaultTimeslots,
- repeat_type: ERepeatType.Repeat,
- tags: defaultTags,
- };
- }
- this._view = EViews.TimeScheme;
- }
- }
- _editActionClick(ev) {
- this.schedule = ev.detail;
- this._view = EViews.NewSchedule;
- }
- async _saveItemClick(ev) {
- if (!this._hass)
- return;
- let schedule = ev.detail;
- schedule = Object.assign(Object.assign({}, schedule), { timeslots: schedule.timeslots
- .map(slot => {
- var _a;
- if (!slot.actions || !slot.actions.length)
- return null;
- if (slot.actions.some(e => !e.entity_id || g$1(e.entity_id || '') == 'notify')) {
- slot = Object.assign(Object.assign({}, slot), { actions: slot.actions.map(action => !action.entity_id || g$1(action.entity_id || '') == 'notify'
- ? omit(action, 'entity_id')
- : action) });
- }
- if (!slot.stop)
- slot = omit(slot, 'stop');
- if (!((_a = slot.conditions) === null || _a === void 0 ? void 0 : _a.length))
- slot = omit(slot, 'conditions', 'condition_type');
- return slot;
- })
- .filter(isDefined) });
- if (this.editItem) {
- const oldSchedule = await fetchScheduleItem(this._hass, this.editItem);
- if (isEqual(omit(schedule, 'timeslots'), omit(pick(oldSchedule, Object.keys(schedule)), 'timeslots')) &&
- schedule.timeslots.length == oldSchedule.timeslots.length &&
- schedule.timeslots.every((slot, i) => isEqual(slot, oldSchedule.timeslots[i]))) {
- // don't save if there are no changes
- this.editItem = null;
- this._view = EViews.Overview;
- }
- else {
- if (!oldSchedule.enabled)
- this._hass.callService('switch', 'turn_on', { entity_id: oldSchedule.entity_id });
- if (IsDefaultName(schedule.name))
- schedule = Object.assign(Object.assign({}, schedule), { name: '' });
- editSchedule(this._hass, Object.assign(Object.assign({}, schedule), { schedule_id: this.editItem }))
- .catch(e => handleError(e, this))
- .then(() => {
- this.editItem = null;
- this._view = EViews.Overview;
- });
- }
- }
- else {
- saveSchedule(this._hass, schedule)
- .catch(e => handleError(e, this))
- .then(() => {
- this._view = EViews.Overview;
- });
- }
- }
- _deleteItemClick() {
- if (!this.editItem || !this._hass)
- return;
- const entity_id = this.editItem;
- deleteSchedule(this._hass, entity_id)
- .catch(e => handleError(e, this))
- .then(() => {
- this.editItem = null;
- this._view = EViews.Overview;
- });
- }
- async _editItemClick(ev) {
- if (!this._hass || !this._config)
- return;
- const data = await fetchScheduleItem(this._hass, ev.detail);
- if (!data)
- return;
- const entities = unique(flatten(data.timeslots.map(e => e.actions.map(e => e.entity_id || e.service))));
- this.entities = entities.map(e => parseEntity(e, this._hass, this._config));
- let actions = computeActions(entities, this._hass, this._config);
- const usedActions = unique(flatten(data.timeslots.map(e => e.actions)));
- let extraActions = usedActions.filter(e => !actions.some(a => compareActions(a, e, true)));
- if (extraActions.length) {
- //actions that are not in the card
- unique(extraActions).forEach(e => actions.push(importAction(e, this._hass)));
- }
- this.actions = actions;
- this.schedule = {
- weekdays: data.weekdays,
- timeslots: data.timeslots,
- repeat_type: data.repeat_type,
- name: data.name,
- tags: data.tags || [],
- start_date: data.start_date,
- end_date: data.end_date,
- };
- this.editItem = data.schedule_id;
- if (!this.entities.length || !this.schedule.timeslots.length) {
- const result = await new Promise(resolve => {
- A$1(this, 'show-dialog', {
- dialogTag: 'dialog-delete-defective',
- dialogImport: () => Promise.resolve().then(function () { return dialogDeleteDefective; }),
- dialogParams: {
- cancel: () => {
- resolve(false);
- },
- confirm: () => {
- resolve(true);
- },
- },
- });
- });
- if (result)
- this._deleteItemClick();
- else
- this._cancelEditClick();
- return;
- }
- if (this.schedule.timeslots.every(e => e.stop)) {
- this.schedule = Object.assign(Object.assign({}, this.schedule), { timeslots: calculateTimeline(this.schedule.timeslots, this._hass) });
- if (!this.actions.length)
- handleError({ error: '', body: { message: `Could not compute actions for the schedule #${ev.detail}.` } }, this);
- else
- this._view = EViews.TimeScheme;
- }
- else {
- this.actions = this.actions
- .filter(e => usedActions.find(a => compareActions(e, a, true)))
- .reduce((_acc, e) => [e], []);
- if (!this.actions.length)
- handleError({ error: '', body: { message: `Could not compute actions for schedule #${ev.detail}.` } }, this);
- else
- this._view = EViews.TimePicker;
- }
- }
- _gotoOptionsClick(ev) {
- this.schedule = ev.detail;
- this._view = EViews.Options;
- }
- _optionsBackClick(ev) {
- this.schedule = ev.detail;
- if (this.schedule.timeslots.every(e => e.stop))
- this._view = EViews.TimeScheme;
- else
- this._view = EViews.TimePicker;
- }
- };
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "_config", void 0);
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "_hass", void 0);
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "_view", void 0);
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "entities", void 0);
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "actions", void 0);
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "schedule", void 0);
- __decorate([
- e$3()
- ], exports.SchedulerCard.prototype, "translationsLoaded", void 0);
- exports.SchedulerCard = __decorate([
- n$4('scheduler-card')
- ], exports.SchedulerCard);
-
- return exports;
-
-}({}));
+ div.summary-action {
+ grid-area: action;
+ }
+ div.summary-arrow {
+ grid-area: arrow;
+ color: var(--secondary-text-color);
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+ div.summary-entity,
+ div.summary-action {
+ color: var(--dark-primary-color);
+ padding: 5px;
+ font-size: 14px;
+ font-weight: 500;
+ --mdc-icon-size: 20px;
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ cursor: pointer;
+ background: rgba(var(--rgb-primary-color), 0.15);
+ border-radius: 4px;
+ align-items: center;
+ }
+ div.summary-entity div,
+ div.summary-action div {
+ display: flex;
+ flex-grow: 1;
+ margin: 5px;
+ width: 100%;
+ align-items: center;
+ }
+ div.summary-entity ha-icon,
+ div.summary-action ha-icon {
+ display: flex;
+ flex: 0 0 30px;
+ }
+ `,t([ae()],Fa.prototype,"hass",void 0),t([ae()],Fa.prototype,"config",void 0),t([ae()],Fa.prototype,"schedule",void 0),t([ae()],Fa.prototype,"actions",void 0),t([ae()],Fa.prototype,"entities",void 0),t([ae()],Fa.prototype,"activeEntry",void 0),t([ae()],Fa.prototype,"activeMarker",void 0),t([ae({type:Boolean})],Fa.prototype,"timeslots",void 0),t([ae({type:Boolean})],Fa.prototype,"editItem",void 0),Fa=t([ie("scheduler-timepicker-card")],Fa);let Ba=class extends ee{constructor(){super(...arguments),this.label="",this.items=[],this.clearable=!1,this.icons=!1,this.disabled=!1,this.allowCustomValue=!1,this.invalid=!1}open(){this.updateComplete.then(()=>{var e,t;null===(t=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("vaadin-combo-box-light"))||void 0===t||t.open()})}focus(){this.updateComplete.then(()=>{var e,t,i;null===(i=null===(t=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("vaadin-combo-box-light"))||void 0===t?void 0:t.inputElement)||void 0===i||i.focus()})}shouldUpdate(e){if(e.get("items"))if(st(this.items,e.get("items"))){if(1==e.size)return!1}else this.firstUpdated();return!0}firstUpdated(){(async()=>{await Pa()})(),this._comboBox.items=this.items}render(){return N`
+
+
+ ${it(this._value)&&this.items.find(e=>e.value==this._value)?N`
+ ${this.icons?N`
+
+ `:""}
+ ${this.clearable?N`
+
+
+ `:""}
+ `:""}
+
+
+
+ `}rowRenderer(e,t,i){e.firstElementChild||(e.innerHTML='\n \n \n \n '),e.querySelector(".name").textContent=i.item.name}_clearValue(e){e.stopPropagation(),this._setValue("")}get _value(){return it(this.value)?this.value:""}_toggleOpen(e){var t,i,s,a,o,n;this.items.length?this._opened?(null===(s=null===(i=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("vaadin-combo-box-light"))||void 0===i?void 0:i.inputElement)||void 0===s||s.blur(),e.stopPropagation()):null===(n=null===(o=null===(a=this.shadowRoot)||void 0===a?void 0:a.querySelector("vaadin-combo-box-light"))||void 0===o?void 0:o.inputElement)||void 0===n||n.focus():e.stopPropagation()}_openedChanged(e){this._opened=e.detail.value}_valueChanged(e){const t=e.detail.value;t!==this._value&&this._setValue(t)}_setValue(e){this.value=e,setTimeout(()=>{Me(this,"value-changed",{value:e})},0)}static get styles(){return r`
+ :host {
+ display: block;
+ width: 100%;
+ }
+ vaadin-combo-box-light {
+ position: relative;
+ }
+ ha-textfield {
+ width: 100%;
+ }
+ ha-textfield > ha-icon-button {
+ --mdc-icon-button-size: 24px;
+ padding: 2px;
+ color: var(--secondary-text-color);
+ }
+ ha-svg-icon {
+ color: var(--input-dropdown-icon-color);
+ position: absolute;
+ cursor: pointer;
+ }
+ ha-svg-icon.disabled {
+ cursor: default;
+ color: var(--disabled-text-color);
+ }
+ .toggle-button {
+ right: 12px;
+ top: -10px;
+ }
+ :host([opened]) .toggle-button {
+ color: var(--primary-color);
+ }
+ `}};t([ae()],Ba.prototype,"label",void 0),t([ae()],Ba.prototype,"value",void 0),t([ae()],Ba.prototype,"items",void 0),t([ae()],Ba.prototype,"clearable",void 0),t([ae()],Ba.prototype,"icons",void 0),t([ae({type:Boolean})],Ba.prototype,"disabled",void 0),t([oe()],Ba.prototype,"_opened",void 0),t([ae({attribute:"allow-custom-value",type:Boolean})],Ba.prototype,"allowCustomValue",void 0),t([ae({type:Boolean})],Ba.prototype,"invalid",void 0),t([function(e,t){return ne({descriptor:i=>{const s={get(){var t,i;return null!==(i=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(e))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(t){const t="symbol"==typeof i?Symbol():"__"+i;s.get=function(){var i,s;return void 0===this[t]&&(this[t]=null!==(s=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(e))&&void 0!==s?s:null),this[t]}}return s}})}("vaadin-combo-box-light",!0)],Ba.prototype,"_comboBox",void 0),Ba=t([ie("scheduler-select")],Ba);let Ya=class extends ee{constructor(){super(...arguments),this.items=[],this.value=[],this.label="",this.invalid=!1}shouldUpdate(e){return e.get("items")&&(st(this.items,e.get("items"))||this.firstUpdated()),!0}firstUpdated(){this.value.some(e=>!this.items.map(e=>e.value).includes(e))&&(this.value=this.value.filter(e=>this.items.map(e=>e.value).includes(e)),Me(this,"value-changed",{value:this.value}))}render(){return N`
+
+ ${this.value.length?this.value.map(e=>this.items.find(t=>t.value==e)).filter(it).map(e=>N`
+
+
+ ${e.name}
+
+ this._removeClick(e.value)}>
+
+
+
+ `):""}
+
+
+ !this.value.includes(e.value))}
+ label=${this.label}
+ .icons=${!1}
+ .allowCustomValue=${!0}
+ @value-changed=${this._addClick}
+ ?invalid=${this.invalid&&this.value.length!=this.items.length}
+ >
+
+ `}_removeClick(e){this.value=this.value.filter(t=>t!==e),Me(this,"value-changed",{value:this.value})}_addClick(e){e.stopPropagation();const t=e.target,i=t.value;this.value.includes(i)||(this.value=[...this.value,i]),t.value="",Me(this,"value-changed",{value:[...this.value]})}static get styles(){return r`
+ div.chip-set {
+ margin: 0px -4px;
+ }
+ div.chip {
+ height: 32px;
+ border-radius: 16px;
+ border: 2px solid rgba(var(--rgb-primary-color), 0.54);
+ line-height: 1.25rem;
+ font-size: 0.875rem;
+ font-weight: 400;
+ padding: 0px 12px;
+ display: inline-flex;
+ align-items: center;
+ box-sizing: border-box;
+ margin: 4px;
+ }
+ .icon {
+ vertical-align: middle;
+ outline: none;
+ display: flex;
+ align-items: center;
+ border-radius: 50%;
+ padding: 6px;
+ color: rgba(0, 0, 0, 0.54);
+ background: rgb(168, 232, 251);
+ --mdc-icon-size: 20px;
+ margin-left: -14px !important;
+ }
+ .label {
+ margin: 0px 4px;
+ }
+ .button {
+ cursor: pointer;
+ background: var(--secondary-text-color);
+ border-radius: 50%;
+ --mdc-icon-size: 14px;
+ color: var(--card-background-color);
+ width: 16px;
+ height: 16px;
+ padding: 1px;
+ box-sizing: border-box;
+ display: inline-flex;
+ align-items: center;
+ margin-right: -6px !important;
+ }
+ `}};t([ae()],Ya.prototype,"items",void 0),t([ae({type:Array})],Ya.prototype,"value",void 0),t([ae()],Ya.prototype,"label",void 0),t([ae({type:Boolean})],Ya.prototype,"invalid",void 0),Ya=t([ie("scheduler-selector")],Ya);const Wa=(e,t)=>{let i={};return(null==t?void 0:t.length)&&!t.includes(Pe.Above)||(i=Object.assign(Object.assign({},i),{[Pe.Above]:{value:Pe.Above,name:e.localize("ui.panel.config.automation.editor.triggers.type.numeric_state.above"),icon:"hass:greater-than"}})),(null==t?void 0:t.length)&&!t.includes(Pe.Below)||(i=Object.assign(Object.assign({},i),{[Pe.Below]:{value:Pe.Below,name:e.localize("ui.panel.config.automation.editor.triggers.type.numeric_state.below"),icon:"hass:less-than"}})),(null==t?void 0:t.length)&&!t.includes(Pe.Equal)||(i=Object.assign(Object.assign({},i),{[Pe.Equal]:{value:Pe.Equal,name:es("ui.panel.conditions.equal_to",ct(e)),icon:"hass:equal"}})),(null==t?void 0:t.length)&&!t.includes(Pe.Unequal)||(i=Object.assign(Object.assign({},i),{[Pe.Unequal]:{value:Pe.Unequal,name:es("ui.panel.conditions.unequal_to",ct(e)),icon:"hass:not-equal-variant"}})),i};let Ga=class extends ee{constructor(){super(...arguments),this.addCondition=!1,this.tags=[],this.startDate="",this.endDate=""}async firstUpdated(){var e,t,i;if(null===(e=this.config)||void 0===e?void 0:e.tags){(async()=>{await Pa()})();const e=(await os(this.hass)).map(e=>e.name),t=dt(this.config.tags);this.tags=[...e,...t.filter(t=>!e.includes(t)&&"none"!=t)]}(await window.loadCardHelpers()).importMoreInfoControl("input_datetime"),this.startDate=(null===(t=this.schedule)||void 0===t?void 0:t.start_date)||la(new Date,ct(this.hass),!0),this.endDate=(null===(i=this.schedule)||void 0===i?void 0:i.end_date)||la(new Date,ct(this.hass),!0)}render(){var e,t;if(!this.hass||!this.config||!this.schedule)return N``;let i=[{name:this.hass.localize("ui.panel.config.automation.editor.actions.type.repeat.label"),value:Le.Repeat,icon:"refresh"},{name:this.hass.localize("ui.dialogs.more_info_control.vacuum.stop"),value:Le.Pause,icon:"stop"},{name:this.hass.localize("ui.common.delete"),value:Le.Single,icon:"trash-can-outline"}];return it(this.schedule.start_date)&&(i=i.filter(e=>e.value!=Le.Repeat)),N`
+
+
+
+ ${this.addCondition?this.renderAddCondition():N`
+
+ ${this.renderConditions()}
+
+
+
+
+
+ ${this.hass.localize("ui.dialogs.helper_settings.input_select.add")}
+
+
+
+ ${this.schedule.timeslots[0].stop&&this.schedule.timeslots[0].conditions&&this.schedule.timeslots[0].conditions.length>0?N`
+
+ this.shadowRoot.querySelector("#track_conditions").click()}
+ >
+ ${es("ui.panel.conditions.track_conditions",ct(this.hass))}
+
+ `:""}
+
+
+
+
+
+
+
+
+
+
+
+
+ ${nt((null===(e=es("ui.components.date.days_range",ct(this.hass)).split("{").shift())||void 0===e?void 0:e.trim())||"")}
+
+
+
+
+
+
+
+ ${nt((null===(t=es("ui.components.date.days_range",ct(this.hass)).split("}")[1].split("{").shift())||void 0===t?void 0:t.trim())||"")}
+
+
+
+
+
+
+
+
+
+
+ ${this.config.tags?N`
+
+
+
+ `:""}
+
+
+
+
+ `}
+
+
+ ${this.addCondition?N`
+ ${this.hass.localize("ui.common.save")}
+ ${void 0!==this.editItem?N`
+ ${this.hass.localize("ui.common.delete")}
+ `:""}
+ ${this.hass.localize("ui.common.cancel")}
+ `:N`
+ e.actions.length).length}
+ >
+ ${this.hass.localize("ui.common.save")}
+
+ ${this.hass.localize("ui.common.back")}
+ `}
+
+
+ `}renderAddCondition(){if(!this.addCondition||!this.hass||!this.config)return N``;if(this.selectedEntity){const e=this.selectedEntity,t=Ca(e.id,this.hass,this.config);let i;if((null==t?void 0:t.type)==Ie.Level)i=[Pe.Above,Pe.Below];else if((null==t?void 0:t.type)==Ie.List)i=[Pe.Equal,Pe.Unequal];else{const t=e.id in this.hass.states?this.hass.states[e.id].state:null;i=!t||["unavailable","unknown"].includes(t)?[Pe.Equal,Pe.Unequal,Pe.Above,Pe.Below]:isNaN(Number(t))?[Pe.Equal,Pe.Unequal]:[Pe.Above,Pe.Below]}const s=Wa(this.hass,i);return N`
+
+
+
+
+ ${nt(e.name)}
+
+ {this.selectedEntity=void 0}}
+ >
+
+
+
+
+ this.conditionMatchType=e.target.value}
+ >
+
+
+
+ this.conditionValue=e.detail.value}
+ >
+
+ `}{const e=wa(Aa(this.hass,this.config,{filterActions:!1,filterStates:!0}),this.config,this.hass);e.sort((e,t)=>e.name.trim().toLowerCase()st(e,this.selectedGroup)).entities.map(e=>Gs(e,this.hass,this.config)),t.sort((e,t)=>e.name.trim().toLowerCase()