Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions src/data/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export interface NavigateActionConfig {
navigation_path: string;
}

export interface UrlActionConfig {
action: "url";
url_path: string;
}

export interface MoreInfoActionConfig {
action: "more-info";
}
Expand All @@ -57,6 +62,7 @@ export type ActionConfig =
| ToggleActionConfig
| CallServiceActionConfig
| NavigateActionConfig
| UrlActionConfig
| MoreInfoActionConfig
| NoActionConfig;

Expand Down
7 changes: 7 additions & 0 deletions src/panels/lovelace/common/compute-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ function computeActionTooltip(
config.navigation_path
)}`;
break;
case "url":
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.url",
"url_path",
config.url_path
)}`;
break;
case "toggle":
tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.toggle",
Expand Down
5 changes: 5 additions & 0 deletions src/panels/lovelace/common/handle-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export const handleClick = (
navigate(node, actionConfig.navigation_path);
}
break;
case "url":
if (actionConfig.url_path) {
window.open(actionConfig.url_path);
}
break;
case "toggle":
if (config.entity) {
toggleEntity(hass, config.entity!);
Expand Down
21 changes: 17 additions & 4 deletions src/panels/lovelace/components/hui-action-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ActionConfig,
NavigateActionConfig,
CallServiceActionConfig,
UrlActionConfig,
} from "../../../data/lovelace";

declare global {
Expand Down Expand Up @@ -51,6 +52,11 @@ export class HuiActionEditor extends LitElement {
return config.navigation_path || "";
}

get _url_path(): string {
const config = this.config! as UrlActionConfig;
return config.url_path || "";
}

get _service(): string {
const config = this.config! as CallServiceActionConfig;
return config.service || "";
Expand Down Expand Up @@ -87,6 +93,16 @@ export class HuiActionEditor extends LitElement {
></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"
? html`
<ha-service-picker
Expand All @@ -106,10 +122,7 @@ export class HuiActionEditor extends LitElement {
return;
}
const target = ev.target! as EditorTarget;
if (
this.config &&
this.config[this[`${target.configValue}`]] === target.value
) {
if (this[`_${target.configValue}`] === target.value) {
return;
}
if (target.configValue === "action") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ export class HuiEntityButtonCardEditor extends LitElement
return html``;
}

const actions = ["more-info", "toggle", "navigate", "call-service", "none"];
const actions = [
"more-info",
"toggle",
"navigate",
"url",
"call-service",
"none",
];

return html`
${configElementStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class HuiPictureCardEditor extends LitElement
return html``;
}

const actions = ["navigate", "call-service", "none"];
const actions = ["navigate", "url", "call-service", "none"];

return html`
${configElementStyle}
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface CardPickTarget extends EventTarget {
export const actionConfigStruct = struct({
action: "string",
navigation_path: "string?",
url_path: "string?",
service: "string?",
service_data: "object?",
});
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@
"hold": "Hold:",
"tap": "Tap:",
"navigate_to": "Navigate to {location}",
"url": "Open window to {url_path}",
"toggle": "Toggle {name}",
"call_service": "Call service {name}",
"more_info": "Show more-info: {name}"
Expand Down