Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add weekday to time contidion editor #6786

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
182fcec
add weekday to time contidion
Misiu Sep 4, 2020
faee2c3
Fix gauge editor (#6783)
bramkragten Sep 4, 2020
d1a9cb4
Add person badge (#6785)
bramkragten Sep 4, 2020
f7eb824
remove quote
Misiu Sep 4, 2020
a60d3ce
review fixes part1
Misiu Sep 4, 2020
93ed135
code readability
Misiu Sep 4, 2020
af0fe76
review fixes part2
Misiu Sep 4, 2020
9c4fdaa
Minor EN text improvements / fixes (#6788)
spacegaier Sep 4, 2020
f1bc311
review fixes part3
Misiu Sep 4, 2020
c1847b3
review fixes part4
Misiu Sep 4, 2020
793b9f2
Tweak card create dialog a bit (#6787)
bramkragten Sep 4, 2020
aa5e20d
Add basic nodes list & node metadata to OZW config panel (#6719)
cgarwood Sep 4, 2020
349a5f5
More Info History: Scrollbar Style (#6790)
zsarnett Sep 4, 2020
b065f00
Allow local storage decorator to register as property (#6776)
bramkragten Sep 4, 2020
e63a78b
Media Browser Panel (#6772)
zsarnett Sep 4, 2020
2adeb88
Bumped version to 20200904.0
bramkragten Sep 4, 2020
fcc22ba
Add node details shortcut to OZW device pages (#6791)
cgarwood Sep 4, 2020
d5794c3
[ci skip] Translation update
homeassistant Sep 5, 2020
879011c
Fix incorrect link to mode documentation in automation editor (#6793)
donkawechico Sep 5, 2020
8f8a2ce
Don't show source select dialog when media player Unavailable. (#6799)
pszafer Sep 5, 2020
3fd7899
Display services as services and not devices (#6798)
ludeeus Sep 6, 2020
d69333d
[ci skip] Translation update
homeassistant Sep 6, 2020
bd66bd6
Add color to hass-error-screen (#6803)
ludeeus Sep 6, 2020
76f59d9
Remove extra > from button (#6804)
ludeeus Sep 6, 2020
9aa8175
Update ha-logbook.ts
bramkragten Sep 6, 2020
509481e
Ignore more proxy disconnect codes (#6805)
ludeeus Sep 6, 2020
cfa0c45
Fix media browser panel title + selection header color (#6807)
spacegaier Sep 6, 2020
a37aad1
Minor typo fix (#6809)
SeanPM5 Sep 6, 2020
efe8eca
Media browser updates (#6801)
zsarnett Sep 6, 2020
c73330a
[ci skip] Translation update
homeassistant Sep 7, 2020
979b7ae
Add attention required for config flows in progress (#6808)
bramkragten Sep 7, 2020
d5bc498
Fix action handler bugs (#6811)
bramkragten Sep 7, 2020
bb24624
Use Sortable to move entities in entities editor (#6810)
zsarnett Sep 7, 2020
e5c386c
Fix white flash in dark mode (#6815)
bramkragten Sep 7, 2020
0c7c536
Fixes issues with channel toggle (#6812)
ludeeus Sep 7, 2020
80224e6
Fix onboarding styling (#6819)
bramkragten Sep 7, 2020
de7ffb1
Automation editor tweaks (#6713)
bramkragten Sep 7, 2020
5339fe6
Updates to correct zindexs on new dialogs (#6816)
zsarnett Sep 7, 2020
046f7b5
Handle media browser errors (#6813)
bramkragten Sep 7, 2020
f15fbe5
Bumped version to 20200907.0
bramkragten Sep 7, 2020
0889f42
[ci skip] Translation update
homeassistant Sep 8, 2020
30c47a6
fix more info content
zsarnett Sep 8, 2020
01a4d57
Merge pull request #6835 from home-assistant/fix-more-info
bramkragten Sep 8, 2020
8b1801f
Fix header on media browser in safari (#6838)
zsarnett Sep 8, 2020
d7448ec
Fix Calendar Card in Add Card dialog (#6833)
zsarnett Sep 8, 2020
327f6ba
simplify
Misiu Sep 8, 2020
9349f34
add weekday to time contidion
Misiu Sep 4, 2020
313a764
review fixes part1
Misiu Sep 4, 2020
dea7734
review fixes part2
Misiu Sep 4, 2020
b26062e
review fixes part3
Misiu Sep 4, 2020
77d2ec9
review fixes part4
Misiu Sep 4, 2020
112b72f
simplify
Misiu Sep 8, 2020
abdb4d9
rebase + comments
Misiu Sep 8, 2020
de5cab3
Merge branch 'weekday' of https://github.com/Misiu/frontend into weekday
Misiu Sep 8, 2020
48ec0b6
remove duplicate interface
Misiu Sep 8, 2020
3d4358c
Revert "remove duplicate interface"
Misiu Sep 8, 2020
72ca9c9
Revert "Merge branch 'weekday' of https://github.com/Misiu/frontend i…
Misiu Sep 8, 2020
6960c25
Revert "rebase + comments"
Misiu Sep 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface TimeCondition {
condition: "time";
after: string;
before: string;
weekday: string[];
}

export interface TemplateCondition {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
import "@polymer/paper-input/paper-input";
import { customElement, html, LitElement, property } from "lit-element";
import {
css,
CSSResult,
customElement,
html,
LitElement,
property,
} from "lit-element";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { computeRTLDirection } from "../../../../../common/util/compute_rtl";
import "../../../../../components/ha-formfield";
import { HaSwitch } from "../../../../../components/ha-switch";
import { TimeCondition } from "../../../../../data/automation";
import { HomeAssistant } from "../../../../../types";
import {
ConditionElement,
handleChangeEvent,
} from "../ha-automation-condition-row";

interface Weekday {
name: string;
order: number;
}

@customElement("ha-automation-condition-time")
export class HaTimeCondition extends LitElement implements ConditionElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property() public condition!: TimeCondition;
@property({ attribute: false }) public condition!: TimeCondition;

private _days: Weekday[] = [
{ name: "mon", order: 1 },
{ name: "tue", order: 2 },
{ name: "wed", order: 3 },
{ name: "thu", order: 4 },
{ name: "fri", order: 5 },
{ name: "sat", order: 6 },
{ name: "sun", order: 7 },
];

public static get defaultConfig() {
return {};
}

protected render() {
const { after, before } = this.condition;
const { after, before, weekday } = this.condition;
return html`
<paper-input
.label=${this.hass.localize(
Expand All @@ -36,10 +62,80 @@ export class HaTimeCondition extends LitElement implements ConditionElement {
.value=${before}
@value-changed=${this._valueChanged}
></paper-input>

${this._days.map(
(day) => html`
<ha-formfield
class="flex"
.label=${this.hass!.localize(
`ui.panel.config.automation.editor.conditions.type.time.weekdays.${day.name}`
)}
.dir=${computeRTLDirection(this.hass!)}
alignEnd
spaceBetween
>
<ha-switch
.day=${day.name}
.checked=${weekday ? weekday.includes(day.name) : false}
@change=${this._dayValueChanged}
>
</ha-switch>
</ha-formfield>
`
)}
`;
}

private _valueChanged(ev: CustomEvent): void {
handleChangeEvent(this, ev);
}

private _dayValueChanged(ev: CustomEvent): void {
ev.stopPropagation();

const day = (ev.currentTarget as any).day;
const checked = (ev.currentTarget as HaSwitch).checked;

let days = this.condition.weekday;
if (!days) {
days = [];
}

if (checked) {
days.push(day);
} else {
days = days.filter((d) => d !== day);
}

days.sort((a: string, b: string) => {
const first: number =
this._days.find((d) => d.name === b.toLowerCase())?.order ?? 1;
const second: number =
this._days.find((d) => d.name === a.toLowerCase())?.order ?? 2;
return second - first;
});

this.condition.weekday = days;

fireEvent(this, "value-changed", {
value: this.condition,
});
}

static get styles(): CSSResult[] {
return [
css`
.flex {
display: flex;
height: 40px;
}
`,
];
}
}

declare global {
interface HTMLElementTagNameMap {
"ha-automation-condition-time": HaTimeCondition;
}
}
12 changes: 11 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,17 @@
"time": {
"label": "[%key:ui::panel::config::automation::editor::triggers::type::time::label%]",
"after": "After",
"before": "Before"
"before": "Before",
"days": "Days",
"weekdays": {
"mon": "Monday",
"tue": "Tuesday",
"wed": "Wednesday",
"thu": "Thursday",
"fri": "Friday",
"sat": "Saturday",
"sun": "Sunday"
}
},
"zone": {
"label": "[%key:ui::panel::config::automation::editor::triggers::type::zone::label%]",
Expand Down