Skip to content

Commit

Permalink
Replace call service by perform action (#1484)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Aug 4, 2024
1 parent 6304553 commit 478ed0a
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 66 deletions.
10 changes: 5 additions & 5 deletions .hass_dev/views/chips-view.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions .hass_dev/views/person-view.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions docs/cards/chips.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const actions: UiAction[] = [
"more-info",
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
2 changes: 1 addition & 1 deletion src/cards/chips-card/chips/action-chip-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DEFAULT_ACTION_ICON } from "./action-chip";
const actions: UiAction[] = [
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const actions: UiAction[] = [
"more-info",
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
2 changes: 1 addition & 1 deletion src/cards/chips-card/chips/weather-chip-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const actions: UiAction[] = [
"more-info",
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
2 changes: 1 addition & 1 deletion src/cards/person-card/person-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const actions: UiAction[] = [
"more-info",
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
2 changes: 1 addition & 1 deletion src/cards/select-card/select-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const actions: UiAction[] = [
"more-info",
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
2 changes: 1 addition & 1 deletion src/cards/title-card/title-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/cards/update-card/update-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const actions: UiAction[] = [
"more-info",
"navigate",
"url",
"call-service",
"perform-action",
"assist",
"none",
];
Expand Down
8 changes: 5 additions & 3 deletions src/ha/data/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
data?: Record<string, unknown>;
}
Expand Down
9 changes: 7 additions & 2 deletions src/ha/panels/lovelace/editor/structs/action-struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -67,6 +68,7 @@ export const actionConfigStructType = object({
"toggle",
"more-info",
"call-service",
"perform-action",
"url",
"navigate",
"assist",
Expand All @@ -80,6 +82,9 @@ export const actionConfigStruct = dynamic<any>((value) => {
case "call-service": {
return actionConfigStructService;
}
case "perform-action": {
return actionConfigStructService;
}
case "fire-dom-event": {
return actionConfigStructCustom;
}
Expand Down
15 changes: 1 addition & 14 deletions src/utils/base-element.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) {
Expand All @@ -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);
}
`,
];
}
Expand Down

0 comments on commit 478ed0a

Please sign in to comment.