Skip to content

Commit 28a89ff

Browse files
authored
Add custom element decorators instead of customElements.define (#28235)
* Add custom element decorators instead of customElements.define * Ignore * prettier
1 parent 81b5dde commit 28a89ff

32 files changed

+65
-94
lines changed

src/components/chart/state-history-chart-line.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PropertyValues } from "lit";
22
import { html, LitElement } from "lit";
3-
import { property, state } from "lit/decorators";
3+
import { customElement, property, state } from "lit/decorators";
44
import type { VisualMapComponentOption } from "echarts/components";
55
import type { LineSeriesOption } from "echarts/charts";
66
import type { YAXisOption } from "echarts/types/dist/shared";
@@ -27,6 +27,7 @@ const safeParseFloat = (value) => {
2727
return isFinite(parsed) ? parsed : null;
2828
};
2929

30+
@customElement("state-history-chart-line")
3031
export class StateHistoryChartLine extends LitElement {
3132
@property({ attribute: false }) public hass!: HomeAssistant;
3233

@@ -795,7 +796,6 @@ export class StateHistoryChartLine extends LitElement {
795796
return Math.abs(value) < 1 ? value : roundingFn(value);
796797
}
797798
}
798-
customElements.define("state-history-chart-line", StateHistoryChartLine);
799799

800800
declare global {
801801
interface HTMLElementTagNameMap {

src/components/entity/state-badge.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mdiAlert } from "@mdi/js";
22
import type { HassEntity } from "home-assistant-js-websocket";
33
import type { CSSResultGroup, PropertyValues } from "lit";
44
import { LitElement, css, html, nothing } from "lit";
5-
import { property, state } from "lit/decorators";
5+
import { customElement, property, state } from "lit/decorators";
66
import { ifDefined } from "lit/directives/if-defined";
77
import { styleMap } from "lit/directives/style-map";
88
import { computeDomain } from "../../common/entity/compute_domain";
@@ -17,6 +17,7 @@ import { CLIMATE_HVAC_ACTION_TO_MODE } from "../../data/climate";
1717
import type { HomeAssistant } from "../../types";
1818
import "../ha-state-icon";
1919

20+
@customElement("state-badge")
2021
export class StateBadge extends LitElement {
2122
public hass?: HomeAssistant;
2223

@@ -265,5 +266,3 @@ declare global {
265266
"state-badge": StateBadge;
266267
}
267268
}
268-
269-
customElements.define("state-badge", StateBadge);

src/components/map/ha-entity-marker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { LitElement, html, css } from "lit";
2-
import { property } from "lit/decorators";
2+
import { customElement, property } from "lit/decorators";
33
import { styleMap } from "lit/directives/style-map";
44
import type { HomeAssistant } from "../../types";
55
import { fireEvent } from "../../common/dom/fire_event";
66
import "../ha-state-icon";
77

8+
@customElement("ha-entity-marker")
89
class HaEntityMarker extends LitElement {
910
@property({ attribute: false }) public hass!: HomeAssistant;
1011

@@ -89,8 +90,6 @@ class HaEntityMarker extends LitElement {
8990
`;
9091
}
9192

92-
customElements.define("ha-entity-marker", HaEntityMarker);
93-
9493
declare global {
9594
interface HTMLElementTagNameMap {
9695
"ha-entity-marker": HaEntityMarker;

src/dialogs/more-info/controls/more-info-camera.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css, html, LitElement, nothing } from "lit";
2-
import { property, state } from "lit/decorators";
2+
import { customElement, property, state } from "lit/decorators";
33
import { slugify } from "../../../common/string/slugify";
44
import "../../../components/buttons/ha-progress-button";
55
import "../../../components/ha-camera-stream";
@@ -9,6 +9,7 @@ import type { HomeAssistant } from "../../../types";
99
import { fileDownload } from "../../../util/file_download";
1010
import { showToast } from "../../../util/toast";
1111

12+
@customElement("more-info-camera")
1213
class MoreInfoCamera extends LitElement {
1314
@property({ attribute: false }) public hass!: HomeAssistant;
1415

@@ -112,8 +113,6 @@ class MoreInfoCamera extends LitElement {
112113
`;
113114
}
114115

115-
customElements.define("more-info-camera", MoreInfoCamera);
116-
117116
declare global {
118117
interface HTMLElementTagNameMap {
119118
"more-info-camera": MoreInfoCamera;

src/dialogs/more-info/controls/more-info-climate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@mdi/js";
88
import type { CSSResultGroup, PropertyValues } from "lit";
99
import { LitElement, css, html, nothing } from "lit";
10-
import { property, state } from "lit/decorators";
10+
import { customElement, property, state } from "lit/decorators";
1111
import { stopPropagation } from "../../../common/dom/stop_propagation";
1212
import { supportsFeature } from "../../../common/entity/supports-feature";
1313
import "../../../components/ha-attribute-icon";
@@ -32,6 +32,7 @@ import { moreInfoControlStyle } from "../components/more-info-control-style";
3232

3333
type MainControl = "temperature" | "humidity";
3434

35+
@customElement("more-info-climate")
3536
class MoreInfoClimate extends LitElement {
3637
@property({ attribute: false }) public hass!: HomeAssistant;
3738

@@ -567,8 +568,6 @@ class MoreInfoClimate extends LitElement {
567568
}
568569
}
569570

570-
customElements.define("more-info-climate", MoreInfoClimate);
571-
572571
declare global {
573572
interface HTMLElementTagNameMap {
574573
"more-info-climate": MoreInfoClimate;

src/dialogs/more-info/controls/more-info-group.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { HassEntity } from "home-assistant-js-websocket";
22
import type { CSSResultGroup, PropertyValues } from "lit";
33
import { LitElement, css, html, nothing } from "lit";
4-
import { property, state } from "lit/decorators";
4+
import { customElement, property, state } from "lit/decorators";
55
import { dynamicElement } from "../../../common/dom/dynamic-element-directive";
66
import type { GroupEntity } from "../../../data/group";
77
import { computeGroupDomain } from "../../../data/group";
@@ -13,6 +13,7 @@ import {
1313
importMoreInfoControl,
1414
} from "../state_more_info_control";
1515

16+
@customElement("more-info-group")
1617
class MoreInfoGroup extends LitElement {
1718
@property({ attribute: false }) public hass!: HomeAssistant;
1819

@@ -106,8 +107,6 @@ class MoreInfoGroup extends LitElement {
106107
}
107108
}
108109

109-
customElements.define("more-info-group", MoreInfoGroup);
110-
111110
declare global {
112111
interface HTMLElementTagNameMap {
113112
"more-info-group": MoreInfoGroup;

src/dialogs/more-info/controls/more-info-humidifier.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mdiPower, mdiTuneVariant } from "@mdi/js";
22
import type { CSSResultGroup, PropertyValues } from "lit";
33
import { LitElement, css, html, nothing } from "lit";
4-
import { property, state } from "lit/decorators";
4+
import { customElement, property, state } from "lit/decorators";
55
import { stopPropagation } from "../../../common/dom/stop_propagation";
66
import { supportsFeature } from "../../../common/entity/supports-feature";
77
import "../../../components/ha-control-select-menu";
@@ -15,6 +15,7 @@ import type { HomeAssistant } from "../../../types";
1515
import "../components/ha-more-info-control-select-container";
1616
import { moreInfoControlStyle } from "../components/more-info-control-style";
1717

18+
@customElement("more-info-humidifier")
1819
class MoreInfoHumidifier extends LitElement {
1920
@property({ attribute: false }) public hass!: HomeAssistant;
2021

@@ -249,8 +250,6 @@ class MoreInfoHumidifier extends LitElement {
249250
}
250251
}
251252

252-
customElements.define("more-info-humidifier", MoreInfoHumidifier);
253-
254253
declare global {
255254
interface HTMLElementTagNameMap {
256255
"more-info-humidifier": MoreInfoHumidifier;

src/layouts/ha-init-page.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { PropertyValues } from "lit";
22
import { css, html, LitElement } from "lit";
3-
import { property, state } from "lit/decorators";
3+
import { customElement, property, state } from "lit/decorators";
44
import "../components/ha-spinner";
55
import "../components/ha-button";
66

7+
@customElement("ha-init-page")
78
class HaInitPage extends LitElement {
89
@property({ type: Boolean }) public error = false;
910

@@ -120,8 +121,6 @@ class HaInitPage extends LitElement {
120121
`;
121122
}
122123

123-
customElements.define("ha-init-page", HaInitPage);
124-
125124
declare global {
126125
interface HTMLElementTagNameMap {
127126
"ha-init-page": HaInitPage;

src/managers/notification-manager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mdiClose } from "@mdi/js";
22
import { html, LitElement, nothing } from "lit";
3-
import { property, query, state } from "lit/decorators";
3+
import { customElement, property, query, state } from "lit/decorators";
44
import type { LocalizeKeys } from "../common/translations/localize";
55
import "../components/ha-button";
66
import "../components/ha-icon-button";
@@ -26,6 +26,7 @@ export interface ToastActionParams {
2626
| { translationKey: LocalizeKeys; args?: Record<string, string> };
2727
}
2828

29+
@customElement("notification-manager")
2930
class NotificationManager extends LitElement {
3031
@property({ attribute: false }) public hass!: HomeAssistant;
3132

@@ -115,8 +116,6 @@ class NotificationManager extends LitElement {
115116
}
116117
}
117118

118-
customElements.define("notification-manager", NotificationManager);
119-
120119
declare global {
121120
interface HTMLElementTagNameMap {
122121
"notification-manager": NotificationManager;

src/panels/calendar/dialog-calendar-event-detail.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TZDate } from "@date-fns/tz";
33
import { addDays, isSameDay } from "date-fns";
44
import type { CSSResultGroup } from "lit";
55
import { LitElement, css, html, nothing } from "lit";
6-
import { property, state } from "lit/decorators";
6+
import { customElement, property, state } from "lit/decorators";
77
import { formatDate } from "../../common/datetime/format_date";
88
import { formatDateTime } from "../../common/datetime/format_date_time";
99
import { formatTime } from "../../common/datetime/format_time";
@@ -26,6 +26,7 @@ import type { CalendarEventDetailDialogParams } from "./show-dialog-calendar-eve
2626
import { showCalendarEventEditDialog } from "./show-dialog-calendar-event-editor";
2727
import { resolveTimeZone } from "../../common/datetime/resolve-time-zone";
2828

29+
@customElement("dialog-calendar-event-detail")
2930
class DialogCalendarEventDetail extends LitElement {
3031
@property({ attribute: false }) public hass!: HomeAssistant;
3132

@@ -271,8 +272,3 @@ declare global {
271272
"dialog-calendar-event-detail": DialogCalendarEventDetail;
272273
}
273274
}
274-
275-
customElements.define(
276-
"dialog-calendar-event-detail",
277-
DialogCalendarEventDetail
278-
);

0 commit comments

Comments
 (0)