new action: url (#3773)

* new action: url

Takes a `url_path` option.
Closes https://github.com/home-assistant/ui-schema/issues/249
I'm experience the issue described here with my string values in the action-editor: https://github.com/home-assistant/home-assistant-polymer/issues/2645. Have not been able to track down where the issue is.

* Fix losing config on init

* fix action-editor
This commit is contained in:
Ian Richardson 2019-09-22 14:56:29 -05:00 committed by Bram Kragten
parent 9a92ed31f6
commit f871387fa6
8 changed files with 46 additions and 6 deletions

View File

@ -45,6 +45,11 @@ export interface NavigateActionConfig {
navigation_path: string; navigation_path: string;
} }
export interface UrlActionConfig {
action: "url";
url_path: string;
}
export interface MoreInfoActionConfig { export interface MoreInfoActionConfig {
action: "more-info"; action: "more-info";
} }
@ -57,6 +62,7 @@ export type ActionConfig =
| ToggleActionConfig | ToggleActionConfig
| CallServiceActionConfig | CallServiceActionConfig
| NavigateActionConfig | NavigateActionConfig
| UrlActionConfig
| MoreInfoActionConfig | MoreInfoActionConfig
| NoActionConfig; | NoActionConfig;

View File

@ -66,6 +66,13 @@ function computeActionTooltip(
config.navigation_path config.navigation_path
)}`; )}`;
break; break;
case "url":
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.url",
"url_path",
config.url_path
)}`;
break;
case "toggle": case "toggle":
tooltip += `${hass.localize( tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.toggle", "ui.panel.lovelace.cards.picture-elements.toggle",

View File

@ -43,6 +43,11 @@ export const handleClick = (
navigate(node, actionConfig.navigation_path); navigate(node, actionConfig.navigation_path);
} }
break; break;
case "url":
if (actionConfig.url_path) {
window.open(actionConfig.url_path);
}
break;
case "toggle": case "toggle":
if (config.entity) { if (config.entity) {
toggleEntity(hass, config.entity!); toggleEntity(hass, config.entity!);

View File

@ -19,6 +19,7 @@ import {
ActionConfig, ActionConfig,
NavigateActionConfig, NavigateActionConfig,
CallServiceActionConfig, CallServiceActionConfig,
UrlActionConfig,
} from "../../../data/lovelace"; } from "../../../data/lovelace";
declare global { declare global {
@ -51,6 +52,11 @@ export class HuiActionEditor extends LitElement {
return config.navigation_path || ""; return config.navigation_path || "";
} }
get _url_path(): string {
const config = this.config! as UrlActionConfig;
return config.url_path || "";
}
get _service(): string { get _service(): string {
const config = this.config! as CallServiceActionConfig; const config = this.config! as CallServiceActionConfig;
return config.service || ""; return config.service || "";
@ -87,6 +93,16 @@ export class HuiActionEditor extends LitElement {
></paper-input> ></paper-input>
` `
: ""} : ""}
${this._action === "url"
? html`
<paper-input
label="Url Path"
.value="${this._url_path}"
.configValue="${"url_path"}"
@value-changed="${this._valueChanged}"
></paper-input>
`
: ""}
${this.config && this.config.action === "call-service" ${this.config && this.config.action === "call-service"
? html` ? html`
<ha-service-picker <ha-service-picker
@ -106,10 +122,7 @@ export class HuiActionEditor extends LitElement {
return; return;
} }
const target = ev.target! as EditorTarget; const target = ev.target! as EditorTarget;
if ( if (this[`_${target.configValue}`] === target.value) {
this.config &&
this.config[this[`${target.configValue}`]] === target.value
) {
return; return;
} }
if (target.configValue === "action") { if (target.configValue === "action") {

View File

@ -92,7 +92,14 @@ export class HuiEntityButtonCardEditor extends LitElement
return html``; return html``;
} }
const actions = ["more-info", "toggle", "navigate", "call-service", "none"]; const actions = [
"more-info",
"toggle",
"navigate",
"url",
"call-service",
"none",
];
return html` return html`
${configElementStyle} ${configElementStyle}

View File

@ -58,7 +58,7 @@ export class HuiPictureCardEditor extends LitElement
return html``; return html``;
} }
const actions = ["navigate", "call-service", "none"]; const actions = ["navigate", "url", "call-service", "none"];
return html` return html`
${configElementStyle} ${configElementStyle}

View File

@ -52,6 +52,7 @@ export interface CardPickTarget extends EventTarget {
export const actionConfigStruct = struct({ export const actionConfigStruct = struct({
action: "string", action: "string",
navigation_path: "string?", navigation_path: "string?",
url_path: "string?",
service: "string?", service: "string?",
service_data: "object?", service_data: "object?",
}); });

View File

@ -1057,6 +1057,7 @@
"hold": "Hold:", "hold": "Hold:",
"tap": "Tap:", "tap": "Tap:",
"navigate_to": "Navigate to {location}", "navigate_to": "Navigate to {location}",
"url": "Open window to {url_path}",
"toggle": "Toggle {name}", "toggle": "Toggle {name}",
"call_service": "Call service {name}", "call_service": "Call service {name}",
"more_info": "Show more-info: {name}" "more_info": "Show more-info: {name}"