Rename service button to action button (#21511)

This commit is contained in:
Bram Kragten 2024-07-31 16:19:32 +02:00 committed by GitHub
parent 3a83cb36a1
commit 574fc99889
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19 additions and 8 deletions

View File

@ -717,7 +717,7 @@ export class HaServiceControl extends LitElement {
}
const value = {
service: newService,
action: newService,
target,
};

View File

@ -18,5 +18,9 @@ const ALWAYS_LOADED_TYPES = new Set([
"state-label",
]);
export const createHuiElement = (config: LovelaceElementConfig) =>
createLovelaceElement("element", config, ALWAYS_LOADED_TYPES);
export const createHuiElement = (config: LovelaceElementConfig) => {
if (config.type === "action-button") {
config = { ...config, type: "service-button" };
}
return createLovelaceElement("element", config, ALWAYS_LOADED_TYPES);
};

View File

@ -1,7 +1,7 @@
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { any, assert, literal, object, optional, string } from "superstruct";
import { any, assert, enums, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
@ -12,7 +12,7 @@ import { ServiceButtonElementConfig } from "../../../elements/types";
import { LovelacePictureElementEditor } from "../../../types";
const serviceButtonElementConfigStruct = object({
type: literal("service-button"),
type: enums(["service-button", "action-button"]),
style: optional(any()),
title: optional(string()),
action: optional(string()),

View File

@ -31,7 +31,7 @@ const elementTypes: string[] = [
"state-badge",
"state-icon",
"state-label",
"service-button",
"action-button",
"icon",
"image",
"conditional",
@ -141,9 +141,13 @@ export class HuiPictureElementsCardRowEditor extends LitElement {
).entity ??
""
);
case "action-button":
case "service-button":
return (
element.title ?? (element as ServiceButtonElementConfig).service ?? ""
element.title ??
(element as ServiceButtonElementConfig).action ??
(element as ServiceButtonElementConfig).service ??
""
);
case "image":
return (

View File

@ -7,7 +7,9 @@ import { getPictureElementClass } from "../../create-element/create-picture-elem
@customElement("hui-picture-element-element-editor")
export class HuiPictureElementElementEditor extends HuiElementEditor<LovelaceElementConfig> {
protected get configElementType(): string | undefined {
return this.value?.type;
return this.value?.type === "action-button"
? "service-button"
: this.value?.type;
}
protected async getConfigElement(): Promise<

View File

@ -5997,6 +5997,7 @@
"state-icon": "State icon",
"state-label": "State label",
"service-button": "Perform action button",
"action-button": "Perform action button",
"icon": "Icon",
"image": "Image",
"conditional": "Conditional"