From 478ed0aed917e4fedca5948115c22e258645d451 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Sun, 4 Aug 2024 22:40:03 +0200 Subject: [PATCH] Replace call service by perform action (#1484) --- .hass_dev/views/chips-view.yaml | 10 +++---- .hass_dev/views/person-view.yaml | 30 +++++++++---------- docs/cards/chips.md | 30 +++++++++---------- hacs.json | 8 ++--- .../alarm-control-panel-card-editor.ts | 2 +- .../chips-card/chips/action-chip-editor.ts | 2 +- .../chips/alarm-control-panel-chip-editor.ts | 2 +- .../chips-card/chips/weather-chip-editor.ts | 2 +- src/cards/person-card/person-card-editor.ts | 2 +- src/cards/select-card/select-card-editor.ts | 2 +- src/cards/title-card/title-card-editor.ts | 2 +- src/cards/update-card/update-card-editor.ts | 2 +- src/ha/data/lovelace.ts | 8 +++-- .../lovelace/editor/structs/action-struct.ts | 9 ++++-- src/utils/base-element.ts | 15 +--------- 15 files changed, 60 insertions(+), 66 deletions(-) diff --git a/.hass_dev/views/chips-view.yaml b/.hass_dev/views/chips-view.yaml index 85f466d2e..89ad18a3d 100644 --- a/.hass_dev/views/chips-view.yaml +++ b/.hass_dev/views/chips-view.yaml @@ -124,9 +124,9 @@ cards: - type: action icon: mdi:bell tap_action: - action: call-service - service: notify.persistent_notification - service_data: + action: perform-action + perform_action: notify.persistent_notification + data: message: This is notification from mushroom dashboard - type: action icon: mdi:github @@ -158,8 +158,8 @@ cards: grey {% endif %} tap_action: - action: call-service - service: light.toggle + action: perform-action + peform_action: light.toggle target: entity_id: light.bed_light - type: template diff --git a/.hass_dev/views/person-view.yaml b/.hass_dev/views/person-view.yaml index 36a8bfd34..08fa043db 100644 --- a/.hass_dev/views/person-view.yaml +++ b/.hass_dev/views/person-view.yaml @@ -65,45 +65,45 @@ cards: name: Home icon: mdi:home tap_action: - action: call-service - service: device_tracker.see - service_data: + action: perform-action + perform_action: device_tracker.see + data: dev_id: demo_anne_therese location_name: home - type: button name: Not Home icon: mdi:home-export-outline tap_action: - action: call-service - service: device_tracker.see - service_data: + action: perform-action + perform_action: device_tracker.see + data: dev_id: demo_anne_therese location_name: not_home - type: button name: Unknown icon: mdi:help tap_action: - action: call-service - service: device_tracker.see - service_data: + action: perform-action + perform_action: device_tracker.see + data: dev_id: demo_anne_therese location_name: unknown - type: button name: Living Room icon: mdi:sofa tap_action: - action: call-service - service: device_tracker.see - service_data: + action: perform-action + perform_action: device_tracker.see + data: dev_id: demo_anne_therese location_name: Living Room - type: button name: Office icon: mdi:office-building tap_action: - action: call-service - service: device_tracker.see - service_data: + action: perform-action + perform_action: device_tracker.see + data: dev_id: demo_anne_therese gps: [52.37451608362128, 4.888106097860146] columns: 3 diff --git a/docs/cards/chips.md b/docs/cards/chips.md index a6b194e54..0eaae09fe 100644 --- a/docs/cards/chips.md +++ b/docs/cards/chips.md @@ -18,7 +18,7 @@ All the options are available in the lovelace editor but you can use `yaml` if y ![Chip action light](../images/chip-action-light.png) ![Chip action dark](../images/chip-action-dark.png) -An action chip allows you to perform a Home Assistant action (navigate, call-service, etc...). +An action chip allows you to perform a Home Assistant action (navigate, perform-action, etc...). ### Alarm control panel chip @@ -84,17 +84,17 @@ A weather chip allows you to display the weather. \* You can render weather svg icons using [weather state](https://developers.home-assistant.io/docs/core/entity/weather/#recommended-values-for-state-and-condition) as icon : -- weather-clear-night -- weather-cloudy -- weather-fog -- weather-lightning -- weather-lightning-rainy -- weather-partlycloudy -- weather-pouring -- weather-rainy -- weather-hail -- weather-snowy -- weather-snowy-rainy -- weather-sunny -- weather-windy -- weather-windy-variant +- weather-clear-night +- weather-cloudy +- weather-fog +- weather-lightning +- weather-lightning-rainy +- weather-partlycloudy +- weather-pouring +- weather-rainy +- weather-hail +- weather-snowy +- weather-snowy-rainy +- weather-sunny +- weather-windy +- weather-windy-variant diff --git a/hacs.json b/hacs.json index 1b6bca90b..77b4297e4 100644 --- a/hacs.json +++ b/hacs.json @@ -1,6 +1,6 @@ { - "name": "Mushroom", - "filename": "mushroom.js", - "homeassistant": "2024.7.0b0", - "render_readme": true + "name": "Mushroom", + "filename": "mushroom.js", + "homeassistant": "2024.8.0b0", + "render_readme": true } diff --git a/src/cards/alarm-control-panel-card/alarm-control-panel-card-editor.ts b/src/cards/alarm-control-panel-card/alarm-control-panel-card-editor.ts index 0ef5f0881..1f52cd594 100644 --- a/src/cards/alarm-control-panel-card/alarm-control-panel-card-editor.ts +++ b/src/cards/alarm-control-panel-card/alarm-control-panel-card-editor.ts @@ -24,7 +24,7 @@ const actions: UiAction[] = [ "more-info", "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/cards/chips-card/chips/action-chip-editor.ts b/src/cards/chips-card/chips/action-chip-editor.ts index 1634251db..7ba2a3d95 100644 --- a/src/cards/chips-card/chips/action-chip-editor.ts +++ b/src/cards/chips-card/chips/action-chip-editor.ts @@ -14,7 +14,7 @@ import { DEFAULT_ACTION_ICON } from "./action-chip"; const actions: UiAction[] = [ "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/cards/chips-card/chips/alarm-control-panel-chip-editor.ts b/src/cards/chips-card/chips/alarm-control-panel-chip-editor.ts index f3c155ee4..df5ee9fee 100644 --- a/src/cards/chips-card/chips/alarm-control-panel-chip-editor.ts +++ b/src/cards/chips-card/chips/alarm-control-panel-chip-editor.ts @@ -15,7 +15,7 @@ const actions: UiAction[] = [ "more-info", "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/cards/chips-card/chips/weather-chip-editor.ts b/src/cards/chips-card/chips/weather-chip-editor.ts index f8f1a7c67..4f8afe962 100644 --- a/src/cards/chips-card/chips/weather-chip-editor.ts +++ b/src/cards/chips-card/chips/weather-chip-editor.ts @@ -17,7 +17,7 @@ const actions: UiAction[] = [ "more-info", "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/cards/person-card/person-card-editor.ts b/src/cards/person-card/person-card-editor.ts index 2f4efa97c..6c9447d78 100644 --- a/src/cards/person-card/person-card-editor.ts +++ b/src/cards/person-card/person-card-editor.ts @@ -17,7 +17,7 @@ const actions: UiAction[] = [ "more-info", "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/cards/select-card/select-card-editor.ts b/src/cards/select-card/select-card-editor.ts index 3f2a7ee3b..51416fa24 100644 --- a/src/cards/select-card/select-card-editor.ts +++ b/src/cards/select-card/select-card-editor.ts @@ -17,7 +17,7 @@ const actions: UiAction[] = [ "more-info", "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/cards/title-card/title-card-editor.ts b/src/cards/title-card/title-card-editor.ts index 30329a337..357367e32 100644 --- a/src/cards/title-card/title-card-editor.ts +++ b/src/cards/title-card/title-card-editor.ts @@ -10,7 +10,7 @@ import { loadHaComponents } from "../../utils/loader"; import { TITLE_CARD_EDITOR_NAME } from "./const"; import { TitleCardConfig, titleCardConfigStruct } from "./title-card-config"; -const actions: UiAction[] = ["navigate", "url", "call-service", "none"]; +const actions: UiAction[] = ["navigate", "url", "perform-action", "none"]; const TITLE_LABELS = [ "title", "subtitle", diff --git a/src/cards/update-card/update-card-editor.ts b/src/cards/update-card/update-card-editor.ts index f1ddaf7ac..1abd8ec68 100644 --- a/src/cards/update-card/update-card-editor.ts +++ b/src/cards/update-card/update-card-editor.ts @@ -19,7 +19,7 @@ const actions: UiAction[] = [ "more-info", "navigate", "url", - "call-service", + "perform-action", "assist", "none", ]; diff --git a/src/ha/data/lovelace.ts b/src/ha/data/lovelace.ts index 1db60edff..cb77cf9ae 100644 --- a/src/ha/data/lovelace.ts +++ b/src/ha/data/lovelace.ts @@ -126,10 +126,12 @@ export interface ToggleActionConfig extends BaseActionConfig { } export interface CallServiceActionConfig extends BaseActionConfig { - action: "call-service"; - service: string; + action: "call-service" | "perform-action"; + /** @deprecated "service" is kept for backwards compatibility. Replaced by "perform_action". */ + service?: string; + perform_action: string; target?: HassServiceTarget; - // "service_data" is kept for backwards compatibility. Replaced by "data". + /** @deprecated "service_data" is kept for backwards compatibility. Replaced by "data". */ service_data?: Record; data?: Record; } diff --git a/src/ha/panels/lovelace/editor/structs/action-struct.ts b/src/ha/panels/lovelace/editor/structs/action-struct.ts index 512e45aa8..463f4fb97 100644 --- a/src/ha/panels/lovelace/editor/structs/action-struct.ts +++ b/src/ha/panels/lovelace/editor/structs/action-struct.ts @@ -31,8 +31,9 @@ const actionConfigStructUrl = object({ }); const actionConfigStructService = object({ - action: literal("call-service"), - service: string(), + action: enums(["call-service", "perform-action"]), + service: optional(string()), + perform_action: optional(string()), service_data: optional(object()), data: optional(object()), target: optional( @@ -67,6 +68,7 @@ export const actionConfigStructType = object({ "toggle", "more-info", "call-service", + "perform-action", "url", "navigate", "assist", @@ -80,6 +82,9 @@ export const actionConfigStruct = dynamic((value) => { case "call-service": { return actionConfigStructService; } + case "perform-action": { + return actionConfigStructService; + } case "fire-dom-event": { return actionConfigStructCustom; } diff --git a/src/utils/base-element.ts b/src/utils/base-element.ts index 139adc8d6..2b469a142 100644 --- a/src/utils/base-element.ts +++ b/src/utils/base-element.ts @@ -1,6 +1,6 @@ import { css, CSSResultGroup, LitElement, PropertyValues } from "lit"; import { property } from "lit/decorators.js"; -import { atLeastHaVersion, HomeAssistant } from "../ha"; +import { HomeAssistant } from "../ha"; import "../shared/badge-icon"; import "../shared/card"; import "../shared/shape-avatar"; @@ -18,13 +18,6 @@ export function computeDarkMode(hass?: HomeAssistant): boolean { export class MushroomBaseElement extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - protected firstUpdated(_changedProperties: PropertyValues): void { - this.toggleAttribute( - "pre-2024-8", - !atLeastHaVersion(this.hass.config.version, 2024, 8) - ); - } - protected updated(changedProps: PropertyValues): void { super.updated(changedProps); if (changedProps.has("hass") && this.hass) { @@ -50,12 +43,6 @@ export class MushroomBaseElement extends LitElement { ${themeColorCss} ${themeVariables} } - :host([pre-2024-8]) { - --spacing: var(--mush-spacing, 12px); - --control-height: var(--mush-control-height, 40px); - --control-spacing: var(--mush-spacing, 12px); - --icon-size: var(--mush-icon-size, 40px); - } `, ]; }