Change defaults of automations to device (#4843)

* Change defaults of automations to device

* Script too

* Update device_automation.ts

* Update device_automation.ts
This commit is contained in:
Bram Kragten 2020-02-13 05:43:44 +01:00 committed by GitHub
parent ec046bc925
commit f45785fafe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 26 deletions

View File

@ -99,7 +99,7 @@ export const deviceAutomationsEqual = (
export const localizeDeviceAutomationAction = (
hass: HomeAssistant,
action: DeviceAction
) => {
): string => {
const state = action.entity_id ? hass.states[action.entity_id] : undefined;
return (
hass.localize(
@ -107,17 +107,19 @@ export const localizeDeviceAutomationAction = (
"entity_name",
state ? computeStateName(state) : action.entity_id || "<unknown>",
"subtype",
hass.localize(
`component.${action.domain}.device_automation.action_subtype.${action.subtype}`
) || action.subtype
) || `"${action.subtype}" ${action.type}`
action.subtype
? hass.localize(
`component.${action.domain}.device_automation.action_subtype.${action.subtype}`
) || action.subtype
: ""
) || (action.subtype ? `"${action.subtype}" ${action.type}` : action.type!)
);
};
export const localizeDeviceAutomationCondition = (
hass: HomeAssistant,
condition: DeviceCondition
) => {
): string => {
const state = condition.entity_id
? hass.states[condition.entity_id]
: undefined;
@ -127,17 +129,22 @@ export const localizeDeviceAutomationCondition = (
"entity_name",
state ? computeStateName(state) : condition.entity_id || "<unknown>",
"subtype",
hass.localize(
`component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}`
) || condition.subtype
) || `"${condition.subtype}" ${condition.type}`
condition.subtype
? hass.localize(
`component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}`
) || condition.subtype
: ""
) ||
(condition.subtype
? `"${condition.subtype}" ${condition.type}`
: condition.type!)
);
};
export const localizeDeviceAutomationTrigger = (
hass: HomeAssistant,
trigger: DeviceTrigger
) => {
): string => {
const state = trigger.entity_id ? hass.states[trigger.entity_id] : undefined;
return (
hass.localize(
@ -145,9 +152,12 @@ export const localizeDeviceAutomationTrigger = (
"entity_name",
state ? computeStateName(state) : trigger.entity_id || "<unknown>",
"subtype",
hass.localize(
`component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}`
) || trigger.subtype
) || `"${trigger.subtype}" ${trigger.type}`
trigger.subtype
? hass.localize(
`component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}`
) || trigger.subtype
: ""
) ||
(trigger.subtype ? `"${trigger.subtype}" ${trigger.type}` : trigger.type!)
);
};

View File

@ -13,6 +13,8 @@ import { Action } from "../../../../data/script";
import { HomeAssistant } from "../../../../types";
import "./ha-automation-action-row";
import { HaDeviceAction } from "./types/ha-automation-action-device_id";
@customElement("ha-automation-action")
export default class HaAutomationAction extends LitElement {
@property() public hass!: HomeAssistant;
@ -46,7 +48,7 @@ export default class HaAutomationAction extends LitElement {
private _addAction() {
const actions = this.actions.concat({
service: "",
...HaDeviceAction.defaultConfig,
});
fireEvent(this, "value-changed", { value: actions });

View File

@ -9,7 +9,7 @@ import {
import "@material/mwc-button";
import "../../../../components/ha-card";
import { HaStateCondition } from "./types/ha-automation-condition-state";
import { HaDeviceCondition } from "./types/ha-automation-condition-device";
import { fireEvent } from "../../../../common/dom/fire_event";
import { HomeAssistant } from "../../../../types";
@ -48,8 +48,8 @@ export default class HaAutomationCondition extends LitElement {
private _addCondition() {
const conditions = this.conditions.concat({
condition: "state",
...HaStateCondition.defaultConfig,
condition: "device",
...HaDeviceCondition.defaultConfig,
});
fireEvent(this, "value-changed", { value: conditions });

View File

@ -36,6 +36,8 @@ import "./condition/ha-automation-condition";
import "./trigger/ha-automation-trigger";
import "../../../layouts/hass-tabs-subpage";
import { configSections } from "../ha-panel-config";
import { HaDeviceAction } from "./action/types/ha-automation-action-device_id";
import { HaDeviceTrigger } from "./trigger/types/ha-automation-trigger-device";
export class HaAutomationEditor extends LitElement {
@property() public hass!: HomeAssistant;
@ -75,7 +77,7 @@ export class HaAutomationEditor extends LitElement {
`
: ""}
<div
class="${classMap({
class="content ${classMap({
rtl: computeRTL(this.hass),
})}"
>
@ -273,9 +275,9 @@ export class HaAutomationEditor extends LitElement {
"ui.panel.config.automation.editor.default_name"
),
description: "",
trigger: [{ platform: "state" }],
trigger: [{ platform: "device", ...HaDeviceTrigger.defaultConfig }],
condition: [],
action: [{ service: "" }],
action: [{ ...HaDeviceAction.defaultConfig }],
...initData,
};
}

View File

@ -13,7 +13,7 @@ import { fireEvent } from "../../../../common/dom/fire_event";
import { HomeAssistant } from "../../../../types";
import "./ha-automation-trigger-row";
import { HaStateTrigger } from "./types/ha-automation-trigger-state";
import { HaDeviceTrigger } from "./types/ha-automation-trigger-device";
import { Trigger } from "../../../../data/automation";
@customElement("ha-automation-trigger")
@ -47,8 +47,8 @@ export default class HaAutomationTrigger extends LitElement {
private _addTrigger() {
const triggers = this.triggers.concat({
platform: "state",
...HaStateTrigger.defaultConfig,
platform: "device",
...HaDeviceTrigger.defaultConfig,
});
fireEvent(this, "value-changed", { value: triggers });

View File

@ -29,6 +29,7 @@ import { HomeAssistant, Route } from "../../../types";
import "../automation/action/ha-automation-action";
import { computeObjectId } from "../../../common/entity/compute_object_id";
import { configSections } from "../ha-panel-config";
import { HaDeviceAction } from "../automation/action/types/ha-automation-action-device_id";
export class HaScriptEditor extends LitElement {
@property() public hass!: HomeAssistant;
@ -193,7 +194,7 @@ export class HaScriptEditor extends LitElement {
this._dirty = initData ? true : false;
this._config = {
alias: this.hass.localize("ui.panel.config.script.editor.default_name"),
sequence: [{ service: "" }],
sequence: [{ ...HaDeviceAction.defaultConfig }],
...initData,
};
}