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 = ( export const localizeDeviceAutomationAction = (
hass: HomeAssistant, hass: HomeAssistant,
action: DeviceAction action: DeviceAction
) => { ): string => {
const state = action.entity_id ? hass.states[action.entity_id] : undefined; const state = action.entity_id ? hass.states[action.entity_id] : undefined;
return ( return (
hass.localize( hass.localize(
@ -107,17 +107,19 @@ export const localizeDeviceAutomationAction = (
"entity_name", "entity_name",
state ? computeStateName(state) : action.entity_id || "<unknown>", state ? computeStateName(state) : action.entity_id || "<unknown>",
"subtype", "subtype",
hass.localize( action.subtype
`component.${action.domain}.device_automation.action_subtype.${action.subtype}` ? hass.localize(
) || action.subtype `component.${action.domain}.device_automation.action_subtype.${action.subtype}`
) || `"${action.subtype}" ${action.type}` ) || action.subtype
: ""
) || (action.subtype ? `"${action.subtype}" ${action.type}` : action.type!)
); );
}; };
export const localizeDeviceAutomationCondition = ( export const localizeDeviceAutomationCondition = (
hass: HomeAssistant, hass: HomeAssistant,
condition: DeviceCondition condition: DeviceCondition
) => { ): string => {
const state = condition.entity_id const state = condition.entity_id
? hass.states[condition.entity_id] ? hass.states[condition.entity_id]
: undefined; : undefined;
@ -127,17 +129,22 @@ export const localizeDeviceAutomationCondition = (
"entity_name", "entity_name",
state ? computeStateName(state) : condition.entity_id || "<unknown>", state ? computeStateName(state) : condition.entity_id || "<unknown>",
"subtype", "subtype",
hass.localize( condition.subtype
`component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}` ? hass.localize(
) || condition.subtype `component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}`
) || `"${condition.subtype}" ${condition.type}` ) || condition.subtype
: ""
) ||
(condition.subtype
? `"${condition.subtype}" ${condition.type}`
: condition.type!)
); );
}; };
export const localizeDeviceAutomationTrigger = ( export const localizeDeviceAutomationTrigger = (
hass: HomeAssistant, hass: HomeAssistant,
trigger: DeviceTrigger trigger: DeviceTrigger
) => { ): string => {
const state = trigger.entity_id ? hass.states[trigger.entity_id] : undefined; const state = trigger.entity_id ? hass.states[trigger.entity_id] : undefined;
return ( return (
hass.localize( hass.localize(
@ -145,9 +152,12 @@ export const localizeDeviceAutomationTrigger = (
"entity_name", "entity_name",
state ? computeStateName(state) : trigger.entity_id || "<unknown>", state ? computeStateName(state) : trigger.entity_id || "<unknown>",
"subtype", "subtype",
hass.localize( trigger.subtype
`component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}` ? hass.localize(
) || trigger.subtype `component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}`
) || `"${trigger.subtype}" ${trigger.type}` ) || 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 { HomeAssistant } from "../../../../types";
import "./ha-automation-action-row"; import "./ha-automation-action-row";
import { HaDeviceAction } from "./types/ha-automation-action-device_id";
@customElement("ha-automation-action") @customElement("ha-automation-action")
export default class HaAutomationAction extends LitElement { export default class HaAutomationAction extends LitElement {
@property() public hass!: HomeAssistant; @property() public hass!: HomeAssistant;
@ -46,7 +48,7 @@ export default class HaAutomationAction extends LitElement {
private _addAction() { private _addAction() {
const actions = this.actions.concat({ const actions = this.actions.concat({
service: "", ...HaDeviceAction.defaultConfig,
}); });
fireEvent(this, "value-changed", { value: actions }); fireEvent(this, "value-changed", { value: actions });

View File

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

View File

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

View File

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

View File

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