Use right naming convention for ui_action and ui_color selector (#16235)

This commit is contained in:
Paul Bottein 2023-04-19 12:13:19 +02:00 committed by GitHub
parent d8cb5a6a42
commit c470ced308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 19 deletions

View File

@ -6,7 +6,7 @@ import { HomeAssistant } from "../../types";
import "../../panels/lovelace/components/hui-action-editor"; import "../../panels/lovelace/components/hui-action-editor";
import { ActionConfig } from "../../data/lovelace"; import { ActionConfig } from "../../data/lovelace";
@customElement("ha-selector-ui-action") @customElement("ha-selector-ui_action")
export class HaSelectorUiAction extends LitElement { export class HaSelectorUiAction extends LitElement {
@property() public hass!: HomeAssistant; @property() public hass!: HomeAssistant;
@ -24,7 +24,7 @@ export class HaSelectorUiAction extends LitElement {
.label=${this.label} .label=${this.label}
.hass=${this.hass} .hass=${this.hass}
.config=${this.value} .config=${this.value}
.actions=${this.selector["ui-action"]?.actions} .actions=${this.selector.ui_action?.actions}
.tooltipText=${this.helper} .tooltipText=${this.helper}
@value-changed=${this._valueChanged} @value-changed=${this._valueChanged}
></hui-action-editor> ></hui-action-editor>

View File

@ -6,7 +6,7 @@ import { UiColorSelector } from "../../data/selector";
import "../../panels/lovelace/components/hui-color-picker"; import "../../panels/lovelace/components/hui-color-picker";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
@customElement("ha-selector-ui-color") @customElement("ha-selector-ui_color")
export class HaSelectorUiColor extends LitElement { export class HaSelectorUiColor extends LitElement {
@property() public hass!: HomeAssistant; @property() public hass!: HomeAssistant;

View File

@ -42,10 +42,12 @@ const LOAD_ELEMENTS = {
tts: () => import("./ha-selector-tts"), tts: () => import("./ha-selector-tts"),
location: () => import("./ha-selector-location"), location: () => import("./ha-selector-location"),
color_temp: () => import("./ha-selector-color-temp"), color_temp: () => import("./ha-selector-color-temp"),
"ui-action": () => import("./ha-selector-ui-action"), ui_action: () => import("./ha-selector-ui-action"),
"ui-color": () => import("./ha-selector-ui-color"), ui_color: () => import("./ha-selector-ui-color"),
}; };
const LEGACY_UI_SELECTORS = new Set(["ui-action", "ui-color"]);
@customElement("ha-selector") @customElement("ha-selector")
export class HaSelector extends LitElement { export class HaSelector extends LitElement {
@property() public hass!: HomeAssistant; @property() public hass!: HomeAssistant;
@ -75,7 +77,11 @@ export class HaSelector extends LitElement {
} }
private get _type() { private get _type() {
return Object.keys(this.selector)[0]; const type = Object.keys(this.selector)[0];
if (LEGACY_UI_SELECTORS.has(type)) {
return type.replace("-", "_");
}
return type;
} }
protected willUpdate(changedProps: PropertyValues) { protected willUpdate(changedProps: PropertyValues) {
@ -91,6 +97,10 @@ export class HaSelector extends LitElement {
if ("device" in selector) { if ("device" in selector) {
return handleLegacyDeviceSelector(selector); return handleLegacyDeviceSelector(selector);
} }
const type = Object.keys(this.selector)[0];
if (LEGACY_UI_SELECTORS.has(type)) {
return { [type.replace("-", "_")]: selector[type] };
}
return selector; return selector;
}); });

View File

@ -332,14 +332,14 @@ export interface TTSSelector {
} }
export interface UiActionSelector { export interface UiActionSelector {
"ui-action": { ui_action: {
actions?: UiAction[]; actions?: UiAction[];
} | null; } | null;
} }
export interface UiColorSelector { export interface UiColorSelector {
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
"ui-color": {} | null; ui_color: {} | null;
} }
export const filterSelectorDevices = ( export const filterSelectorDevices = (

View File

@ -65,11 +65,11 @@ const SCHEMA = [
}, },
{ {
name: "tap_action", name: "tap_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
{ {
name: "hold_action", name: "hold_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
] as const; ] as const;

View File

@ -48,11 +48,11 @@ const SCHEMA = [
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
{ {
name: "hold_action", name: "hold_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
{ {
name: "double_tap_action", name: "double_tap_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
] as const; ] as const;

View File

@ -61,11 +61,11 @@ const SCHEMA = [
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
{ {
name: "tap_action", name: "tap_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
{ {
name: "hold_action", name: "hold_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
] as const; ] as const;

View File

@ -51,11 +51,11 @@ const SCHEMA = [
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
{ {
name: "tap_action", name: "tap_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
{ {
name: "hold_action", name: "hold_action",
selector: { "ui-action": {} }, selector: { ui_action: {} },
}, },
] as const; ] as const;

View File

@ -87,7 +87,7 @@ export class HuiTileCardEditor
{ {
name: "color", name: "color",
selector: { selector: {
"ui-color": {}, ui_color: {},
}, },
}, },
{ {
@ -115,13 +115,13 @@ export class HuiTileCardEditor
{ {
name: "tap_action", name: "tap_action",
selector: { selector: {
"ui-action": {}, ui_action: {},
}, },
}, },
{ {
name: "icon_tap_action", name: "icon_tap_action",
selector: { selector: {
"ui-action": {}, ui_action: {},
}, },
}, },
] as const, ] as const,