mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-04 08:29:52 +00:00
Compare commits
1 Commits
toolbar-to
...
revert-rev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74db7f5868 |
@@ -16,9 +16,9 @@ import {
|
||||
} from "../../../../src/common/auth/token_storage";
|
||||
import { atLeastVersion } from "../../../../src/common/config/version";
|
||||
import { toggleAttribute } from "../../../../src/common/dom/toggle_attribute";
|
||||
import "../../../../src/components/ha-button";
|
||||
import "../../../../src/components/ha-icon";
|
||||
import "../../../../src/components/ha-list";
|
||||
import "../../../../src/components/ha-button";
|
||||
import "../../../../src/components/ha-list-item";
|
||||
import "../../../../src/components/ha-svg-icon";
|
||||
import {
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
import { isStrategyDashboard } from "../../../../src/data/lovelace/config/types";
|
||||
import type { LovelaceViewConfig } from "../../../../src/data/lovelace/config/view";
|
||||
import "../../../../src/layouts/hass-loading-screen";
|
||||
import { generateDefaultViewConfig } from "../../../../src/panels/lovelace/common/generate-lovelace-config";
|
||||
import "./hc-layout";
|
||||
|
||||
@customElement("hc-cast")
|
||||
@@ -95,9 +96,7 @@ class HcCast extends LitElement {
|
||||
<ha-list @action=${this._handlePickView} activatable>
|
||||
${(
|
||||
this.lovelaceViews ?? [
|
||||
{
|
||||
title: "Home",
|
||||
},
|
||||
generateDefaultViewConfig({}, {}, {}, {}, () => ""),
|
||||
]
|
||||
).map(
|
||||
(view, idx) => html`
|
||||
|
||||
@@ -16,10 +16,14 @@ import memoizeOne from "memoize-one";
|
||||
import { computeCssColor } from "../../common/color/compute-color";
|
||||
import { hex2rgb } from "../../common/color/convert-color";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeDeviceNameDisplay } from "../../common/entity/compute_device_name";
|
||||
import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import { slugify } from "../../common/string/slugify";
|
||||
import {
|
||||
computeDeviceName,
|
||||
computeDeviceNameDisplay,
|
||||
} from "../../common/entity/compute_device_name";
|
||||
import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import { computeEntityName } from "../../common/entity/compute_entity_name";
|
||||
import { getEntityContext } from "../../common/entity/context/get_entity_context";
|
||||
import { getConfigEntry } from "../../data/config_entries";
|
||||
import { labelsContext } from "../../data/context";
|
||||
import { domainToName } from "../../data/integration";
|
||||
@@ -168,10 +172,23 @@ export class HaTargetPickerValueChip extends LitElement {
|
||||
if (type === "entity") {
|
||||
this._setDomainName(computeDomain(itemId));
|
||||
|
||||
const stateObj = this.hass.states[itemId];
|
||||
const stateObject = this.hass.states[itemId];
|
||||
const entityName = computeEntityName(
|
||||
stateObject,
|
||||
this.hass.entities,
|
||||
this.hass.devices
|
||||
);
|
||||
const { device } = getEntityContext(
|
||||
stateObject,
|
||||
this.hass.entities,
|
||||
this.hass.devices,
|
||||
this.hass.areas,
|
||||
this.hass.floors
|
||||
);
|
||||
const deviceName = device ? computeDeviceName(device) : undefined;
|
||||
return {
|
||||
name: computeStateName(stateObj) || itemId,
|
||||
stateObject: stateObj,
|
||||
name: entityName || deviceName || itemId,
|
||||
stateObject,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ export class HaDeviceEntitiesCard extends LitElement {
|
||||
addEntitiesToLovelaceView(
|
||||
this,
|
||||
this.hass,
|
||||
computeCards(this.hass, entities, {
|
||||
computeCards(this.hass.states, entities, {
|
||||
title: this.deviceName,
|
||||
}),
|
||||
computeSection(entities, {
|
||||
|
||||
@@ -5,7 +5,8 @@ import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDeviceNameDisplay } from "../../../../common/entity/compute_device_name";
|
||||
import "../../../../components/ha-alert";
|
||||
import "../../../../components/ha-area-picker";
|
||||
import "../../../../components/ha-dialog";
|
||||
import "../../../../components/ha-wa-dialog";
|
||||
import "../../../../components/ha-dialog-footer";
|
||||
import "../../../../components/ha-button";
|
||||
import "../../../../components/ha-labels-picker";
|
||||
import type { HaSwitch } from "../../../../components/ha-switch";
|
||||
@@ -19,6 +20,8 @@ import type { DeviceRegistryDetailDialogParams } from "./show-dialog-device-regi
|
||||
class DialogDeviceRegistryDetail extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _nameByUser!: string;
|
||||
|
||||
@state() private _error?: string;
|
||||
@@ -42,10 +45,15 @@ class DialogDeviceRegistryDetail extends LitElement {
|
||||
this._areaId = this._params.device.area_id || "";
|
||||
this._labels = this._params.device.labels || [];
|
||||
this._disabledBy = this._params.device.disabled_by;
|
||||
this._open = true;
|
||||
await this.updateComplete;
|
||||
}
|
||||
|
||||
public closeDialog(): void {
|
||||
this._open = false;
|
||||
}
|
||||
|
||||
private _dialogClosed(): void {
|
||||
this._error = "";
|
||||
this._params = undefined;
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
@@ -57,10 +65,12 @@ class DialogDeviceRegistryDetail extends LitElement {
|
||||
}
|
||||
const device = this._params.device;
|
||||
return html`
|
||||
<ha-dialog
|
||||
open
|
||||
@closed=${this.closeDialog}
|
||||
.heading=${computeDeviceNameDisplay(device, this.hass)}
|
||||
<ha-wa-dialog
|
||||
.hass=${this.hass}
|
||||
.open=${this._open}
|
||||
header-title=${computeDeviceNameDisplay(device, this.hass)}
|
||||
prevent-scrim-close
|
||||
@closed=${this._dialogClosed}
|
||||
>
|
||||
<div>
|
||||
${this._error
|
||||
@@ -68,6 +78,7 @@ class DialogDeviceRegistryDetail extends LitElement {
|
||||
: ""}
|
||||
<div class="form">
|
||||
<ha-textfield
|
||||
autofocus
|
||||
.value=${this._nameByUser}
|
||||
@input=${this._nameChanged}
|
||||
.label=${this.hass.localize(
|
||||
@@ -75,7 +86,6 @@ class DialogDeviceRegistryDetail extends LitElement {
|
||||
)}
|
||||
.placeholder=${device.name || ""}
|
||||
.disabled=${this._submitting}
|
||||
dialogInitialFocus
|
||||
></ha-textfield>
|
||||
<ha-area-picker
|
||||
.hass=${this.hass}
|
||||
@@ -131,22 +141,25 @@ class DialogDeviceRegistryDetail extends LitElement {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ha-button
|
||||
slot="secondaryAction"
|
||||
@click=${this.closeDialog}
|
||||
.disabled=${this._submitting}
|
||||
appearance="plain"
|
||||
>
|
||||
${this.hass.localize("ui.common.cancel")}
|
||||
</ha-button>
|
||||
<ha-button
|
||||
slot="primaryAction"
|
||||
@click=${this._updateEntry}
|
||||
.disabled=${this._submitting}
|
||||
>
|
||||
${this.hass.localize("ui.dialogs.device-registry-detail.update")}
|
||||
</ha-button>
|
||||
</ha-dialog>
|
||||
|
||||
<ha-dialog-footer slot="footer">
|
||||
<ha-button
|
||||
slot="secondaryAction"
|
||||
@click=${this.closeDialog}
|
||||
.disabled=${this._submitting}
|
||||
appearance="plain"
|
||||
>
|
||||
${this.hass.localize("ui.common.cancel")}
|
||||
</ha-button>
|
||||
<ha-button
|
||||
slot="primaryAction"
|
||||
@click=${this._updateEntry}
|
||||
.disabled=${this._submitting}
|
||||
>
|
||||
${this.hass.localize("ui.dialogs.device-registry-detail.update")}
|
||||
</ha-button>
|
||||
</ha-dialog-footer>
|
||||
</ha-wa-dialog>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,6 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
class=${classMap({
|
||||
"is-grid": this.layout === "grid",
|
||||
"is-panel": this.layout === "panel",
|
||||
"has-title": !!this._config.title,
|
||||
})}
|
||||
.narrow=${this._narrow}
|
||||
.events=${this._events}
|
||||
@@ -230,7 +229,6 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
padding: 0 8px 8px;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
@@ -241,25 +239,15 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
padding-left: 8px;
|
||||
padding-inline-start: 8px;
|
||||
direction: var(--direction);
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
ha-full-calendar {
|
||||
--calendar-height: 400px;
|
||||
height: var(--calendar-height);
|
||||
}
|
||||
|
||||
ha-full-calendar.is-grid,
|
||||
ha-full-calendar.is-panel {
|
||||
--calendar-height: calc(100% - 16px);
|
||||
}
|
||||
|
||||
ha-full-calendar.is-grid.has-title,
|
||||
ha-full-calendar.is-panel.has-title {
|
||||
--calendar-height: calc(
|
||||
100% - var(--ha-card-header-font-size, var(--ha-font-size-2xl)) - 22px
|
||||
);
|
||||
height: calc(100% - 16px);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
@@ -20,9 +20,11 @@ import type {
|
||||
import type {
|
||||
LovelaceCard,
|
||||
LovelaceCardEditor,
|
||||
LovelaceGridOptions,
|
||||
LovelaceHeaderFooter,
|
||||
} from "../types";
|
||||
import type { EntitiesCardConfig } from "./types";
|
||||
import { haStyleScrollbar } from "../../../resources/styles";
|
||||
|
||||
export const computeShowHeaderToggle = <
|
||||
T extends EntityConfig | LovelaceRowConfig,
|
||||
@@ -75,6 +77,8 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
|
||||
|
||||
private _hass?: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public layout?: string;
|
||||
|
||||
private _configEntities?: LovelaceRowConfig[];
|
||||
|
||||
private _showHeaderToggle?: boolean;
|
||||
@@ -139,6 +143,14 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
|
||||
return size;
|
||||
}
|
||||
|
||||
public getGridOptions(): LovelaceGridOptions {
|
||||
return {
|
||||
columns: 12,
|
||||
min_columns: 6,
|
||||
min_rows: this._config?.title || this._showHeaderToggle ? 3 : 2,
|
||||
};
|
||||
}
|
||||
|
||||
public setConfig(config: EntitiesCardConfig): void {
|
||||
if (!config.entities || !Array.isArray(config.entities)) {
|
||||
throw new Error("Entities must be specified");
|
||||
@@ -233,7 +245,7 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
|
||||
`}
|
||||
</h1>
|
||||
`}
|
||||
<div id="states" class="card-content">
|
||||
<div id="states" class="card-content ha-scrollbar">
|
||||
${this._configEntities!.map((entityConf) =>
|
||||
this._renderEntity(entityConf)
|
||||
)}
|
||||
@@ -246,69 +258,73 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
ha-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
static styles = [
|
||||
haStyleScrollbar,
|
||||
css`
|
||||
ha-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.card-header .name {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.card-header .name {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
#states {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--entities-card-row-gap, var(--card-row-gap, 8px));
|
||||
}
|
||||
#states {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--entities-card-row-gap, var(--card-row-gap, 8px));
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#states > div > * {
|
||||
overflow: clip visible;
|
||||
}
|
||||
#states > div > * {
|
||||
overflow: clip visible;
|
||||
}
|
||||
|
||||
#states > div {
|
||||
position: relative;
|
||||
}
|
||||
#states > div {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.icon {
|
||||
padding: 0px 18px 0px 8px;
|
||||
}
|
||||
.icon {
|
||||
padding: 0px 18px 0px 8px;
|
||||
}
|
||||
|
||||
.header {
|
||||
border-top-left-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
border-top-right-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
margin-bottom: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
border-top-left-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
border-top-right-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
margin-bottom: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.footer {
|
||||
border-bottom-left-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
border-bottom-right-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
margin-top: -16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
`;
|
||||
.footer {
|
||||
border-bottom-left-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
border-bottom-right-radius: var(
|
||||
--ha-card-border-radius,
|
||||
var(--ha-border-radius-lg)
|
||||
);
|
||||
margin-top: -16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
private _renderEntity(entityConf: LovelaceRowConfig): TemplateResult {
|
||||
const element = createRowElement(
|
||||
|
||||
@@ -5,6 +5,7 @@ import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/entity/state-badge";
|
||||
import "../../../components/ha-card";
|
||||
import "../../../components/ha-icon";
|
||||
@@ -18,7 +19,6 @@ import type {
|
||||
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
import { handleAction } from "../common/handle-action";
|
||||
import { hasAction, hasAnyAction } from "../common/has-action";
|
||||
@@ -252,11 +252,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
entityConf.name
|
||||
);
|
||||
const name = entityConf.name ?? computeStateName(stateObj);
|
||||
|
||||
return html`
|
||||
<div
|
||||
|
||||
@@ -3,27 +3,25 @@ import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
import { createSearchParam } from "../../../common/url/search-params";
|
||||
import "../../../components/chart/state-history-charts";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-card";
|
||||
import "../../../components/ha-icon-next";
|
||||
import {
|
||||
computeHistory,
|
||||
convertStatisticsToHistory,
|
||||
mergeHistoryResults,
|
||||
subscribeHistoryStatesTimeWindow,
|
||||
type HistoryResult,
|
||||
convertStatisticsToHistory,
|
||||
mergeHistoryResults,
|
||||
} from "../../../data/history";
|
||||
import { fetchStatistics } from "../../../data/recorder";
|
||||
import { getSensorNumericDeviceClasses } from "../../../data/sensor";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { hasConfigOrEntitiesChanged } from "../common/has-changed";
|
||||
import { processConfigEntities } from "../common/process-config-entities";
|
||||
import type { EntityConfig } from "../entity-rows/types";
|
||||
import type { LovelaceCard, LovelaceGridOptions } from "../types";
|
||||
import type { HistoryGraphCardConfig } from "./types";
|
||||
import { createSearchParam } from "../../../common/url/search-params";
|
||||
import { fetchStatistics } from "../../../data/recorder";
|
||||
|
||||
export const DEFAULT_HOURS_TO_SHOW = 24;
|
||||
|
||||
@@ -53,8 +51,6 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
|
||||
|
||||
private _entityIds: string[] = [];
|
||||
|
||||
private _entities: EntityConfig[] = [];
|
||||
|
||||
private _hoursToShow = DEFAULT_HOURS_TO_SHOW;
|
||||
|
||||
private _interval?: number;
|
||||
@@ -84,35 +80,21 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
|
||||
throw new Error("You must include at least one entity");
|
||||
}
|
||||
|
||||
this._entities = config.entities
|
||||
const configEntities = config.entities
|
||||
? processConfigEntities(config.entities)
|
||||
: [];
|
||||
this._entityIds = this._entities.map((entity) => entity.entity);
|
||||
|
||||
this._entityIds = [];
|
||||
configEntities.forEach((entity) => {
|
||||
this._entityIds.push(entity.entity);
|
||||
if (entity.name) {
|
||||
this._names[entity.entity] = entity.name;
|
||||
}
|
||||
});
|
||||
|
||||
this._hoursToShow = config.hours_to_show || DEFAULT_HOURS_TO_SHOW;
|
||||
|
||||
this._config = config;
|
||||
this._computeNames();
|
||||
}
|
||||
|
||||
private _computeNames() {
|
||||
if (!this.hass || !this._config) {
|
||||
return;
|
||||
}
|
||||
this._names = {};
|
||||
this._entities.forEach((entity) => {
|
||||
const stateObj = this.hass!.states[entity.entity];
|
||||
this._names[entity.entity] = stateObj
|
||||
? computeLovelaceEntityName(this.hass!, stateObj, entity.name)
|
||||
: entity.entity;
|
||||
});
|
||||
}
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
if (changedProps.has("hass")) {
|
||||
this._computeNames();
|
||||
}
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
|
||||
@@ -35,12 +35,20 @@ import {
|
||||
hasConfigOrEntitiesChanged,
|
||||
} from "../common/has-changed";
|
||||
import { processConfigEntities } from "../common/process-config-entities";
|
||||
import type { EntityConfig } from "../entity-rows/types";
|
||||
import type { LovelaceCard, LovelaceGridOptions } from "../types";
|
||||
import type { MapCardConfig, MapEntityConfig } from "./types";
|
||||
import type { MapCardConfig } from "./types";
|
||||
|
||||
export const DEFAULT_HOURS_TO_SHOW = 0;
|
||||
export const DEFAULT_ZOOM = 14;
|
||||
|
||||
interface MapEntityConfig extends EntityConfig {
|
||||
label_mode?: "state" | "attribute" | "name";
|
||||
attribute?: string;
|
||||
unit?: string;
|
||||
focus?: boolean;
|
||||
}
|
||||
|
||||
interface GeoEntity {
|
||||
entity_id: string;
|
||||
label_mode?: "state" | "attribute" | "name" | "icon";
|
||||
|
||||
@@ -20,15 +20,14 @@ import {
|
||||
} from "../../../data/recorder";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { computeCardSize } from "../common/compute-card-size";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import { createHeaderFooterElement } from "../create-element/create-header-footer-element";
|
||||
import type {
|
||||
LovelaceCard,
|
||||
LovelaceCardEditor,
|
||||
LovelaceGridOptions,
|
||||
LovelaceHeaderFooter,
|
||||
LovelaceGridOptions,
|
||||
} from "../types";
|
||||
import type { HuiErrorCard } from "./hui-error-card";
|
||||
import type { EntityCardConfig, StatisticCardConfig } from "./types";
|
||||
@@ -181,9 +180,7 @@ export class HuiStatisticCard extends LitElement implements LovelaceCard {
|
||||
|
||||
const stateObj = this.hass.states[this._config.entity];
|
||||
const name =
|
||||
(this._config.name
|
||||
? computeLovelaceEntityName(this.hass, stateObj, this._config.name)
|
||||
: "") ||
|
||||
this._config.name ||
|
||||
getStatisticLabel(this.hass, this._config.entity, this._metadata);
|
||||
|
||||
return html`
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { differenceInDays, subHours } from "date-fns";
|
||||
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { subHours, differenceInDays } from "date-fns";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import "../../../components/ha-card";
|
||||
import { getEnergyDataCollection } from "../../../data/energy";
|
||||
import {
|
||||
getSuggestedMax,
|
||||
getSuggestedPeriod,
|
||||
} from "./energy/common/energy-chart-options";
|
||||
import type {
|
||||
Statistics,
|
||||
StatisticsMetaData,
|
||||
@@ -17,16 +21,10 @@ import {
|
||||
getStatisticMetadata,
|
||||
} from "../../../data/recorder";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
import { hasConfigOrEntitiesChanged } from "../common/has-changed";
|
||||
import { processConfigEntities } from "../common/process-config-entities";
|
||||
import type { EntityConfig } from "../entity-rows/types";
|
||||
import type { LovelaceCard, LovelaceGridOptions } from "../types";
|
||||
import {
|
||||
getSuggestedMax,
|
||||
getSuggestedPeriod,
|
||||
} from "./energy/common/energy-chart-options";
|
||||
import type { StatisticsGraphCardConfig } from "./types";
|
||||
|
||||
export const DEFAULT_DAYS_TO_SHOW = 30;
|
||||
@@ -69,9 +67,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
|
||||
@state() private _unit?: string;
|
||||
|
||||
private _entities: EntityConfig[] = [];
|
||||
|
||||
private _entityIds: string[] = [];
|
||||
private _entities: string[] = [];
|
||||
|
||||
private _names: Record<string, string> = {};
|
||||
|
||||
@@ -152,10 +148,17 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
throw new Error("You must include at least one entity");
|
||||
}
|
||||
|
||||
this._entities = config.entities
|
||||
const configEntities = config.entities
|
||||
? processConfigEntities(config.entities, false)
|
||||
: [];
|
||||
this._entityIds = this._entities.map((ent) => ent.entity);
|
||||
|
||||
this._entities = [];
|
||||
configEntities.forEach((entity) => {
|
||||
this._entities.push(entity.entity);
|
||||
if (entity.name) {
|
||||
this._names[entity.entity] = entity.name;
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof config.stat_types === "string") {
|
||||
this._statTypes = [config.stat_types];
|
||||
@@ -165,20 +168,6 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
this._statTypes = config.stat_types;
|
||||
}
|
||||
this._config = config;
|
||||
this._computeNames();
|
||||
}
|
||||
|
||||
private _computeNames() {
|
||||
if (!this.hass || !this._config) {
|
||||
return;
|
||||
}
|
||||
this._names = {};
|
||||
this._entities.forEach((config) => {
|
||||
const stateObj = this.hass!.states[config.entity];
|
||||
this._names[config.entity] = stateObj
|
||||
? computeLovelaceEntityName(this.hass!, stateObj, config.name)
|
||||
: config.entity;
|
||||
});
|
||||
}
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||
@@ -220,10 +209,6 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
}
|
||||
|
||||
if (changedProps.has("hass")) {
|
||||
this._computeNames();
|
||||
}
|
||||
|
||||
if (
|
||||
changedProps.has("_config") &&
|
||||
oldConfig?.entities !== this._config.entities
|
||||
@@ -247,7 +232,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
clearInterval(this._interval);
|
||||
this._interval = 0; // block concurrent calls
|
||||
if (fetchMetadata) {
|
||||
await this._getStatisticsMetaData(this._entityIds);
|
||||
await this._getStatisticsMetaData(this._entities);
|
||||
}
|
||||
await this._getStatistics();
|
||||
// statistics are created every hour
|
||||
@@ -359,7 +344,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
}
|
||||
if (!unitClass && this._metadata) {
|
||||
const metadata = this._metadata[this._entityIds[0]];
|
||||
const metadata = this._metadata[this._entities[0]];
|
||||
unitClass = metadata?.unit_class;
|
||||
this._unit = unitClass
|
||||
? getDisplayUnit(this.hass!, metadata.statistic_id, metadata) ||
|
||||
@@ -371,15 +356,14 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
this.hass!,
|
||||
startDate,
|
||||
endDate,
|
||||
this._entityIds,
|
||||
this._entities,
|
||||
this._period,
|
||||
unitconfig,
|
||||
this._statTypes
|
||||
);
|
||||
|
||||
this._statistics = {};
|
||||
this._entities.forEach((entity) => {
|
||||
const id = entity.entity;
|
||||
this._entities.forEach((id) => {
|
||||
if (id in statistics) {
|
||||
this._statistics![id] = statistics[id];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import type { EnergySourceByType } from "../../../data/energy";
|
||||
import type { ActionConfig } from "../../../data/lovelace/config/action";
|
||||
import type { LovelaceCardConfig } from "../../../data/lovelace/config/card";
|
||||
import type { Statistic, StatisticType } from "../../../data/recorder";
|
||||
import type { MediaSelectorValue } from "../../../data/selector";
|
||||
import type { TimeFormat } from "../../../data/translation";
|
||||
import type { ForecastType } from "../../../data/weather";
|
||||
import type {
|
||||
@@ -30,6 +29,7 @@ import type {
|
||||
import type { LovelaceHeaderFooterConfig } from "../header-footer/types";
|
||||
import type { LovelaceHeadingBadgeConfig } from "../heading-badges/types";
|
||||
import type { HomeSummary } from "../strategies/home/helpers/home-summaries";
|
||||
import type { MediaSelectorValue } from "../../../data/selector";
|
||||
|
||||
export type AlarmPanelCardConfigState =
|
||||
| "arm_away"
|
||||
@@ -348,15 +348,7 @@ export interface LogbookCardConfig extends LovelaceCardConfig {
|
||||
state_filter?: string[];
|
||||
}
|
||||
|
||||
export interface MapEntityConfig extends EntityConfig {
|
||||
label_mode?: "state" | "attribute" | "name";
|
||||
attribute?: string;
|
||||
unit?: string;
|
||||
focus?: boolean;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface GeoLocationSourceConfig {
|
||||
interface GeoLocationSourceConfig {
|
||||
source: string;
|
||||
label_mode?: "name" | "state" | "attribute" | "icon";
|
||||
attribute?: string;
|
||||
@@ -371,7 +363,7 @@ export interface MapCardConfig extends LovelaceCardConfig {
|
||||
auto_fit?: boolean;
|
||||
fit_zones?: boolean;
|
||||
default_zoom?: number;
|
||||
entities?: (MapEntityConfig | string)[];
|
||||
entities?: (EntityConfig | string)[];
|
||||
hours_to_show?: number;
|
||||
geo_location_sources?: (GeoLocationSourceConfig | string)[];
|
||||
dark_mode?: boolean;
|
||||
@@ -443,7 +435,7 @@ export interface StatisticsGraphCardConfig extends EnergyCardBaseConfig {
|
||||
}
|
||||
|
||||
export interface StatisticCardConfig extends LovelaceCardConfig {
|
||||
name?: string | EntityNameItem | EntityNameItem[];
|
||||
name?: string;
|
||||
entities: (EntityConfig | string)[];
|
||||
period:
|
||||
| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { HassEntities, HassEntity } from "home-assistant-js-websocket";
|
||||
import { ASSIST_ENTITIES, SENSOR_ENTITIES } from "../../../common/const";
|
||||
import { SENSOR_ENTITIES, ASSIST_ENTITIES } from "../../../common/const";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
@@ -14,14 +14,12 @@ import type {
|
||||
GridSourceTypeEnergyPreference,
|
||||
} from "../../../data/energy";
|
||||
import { domainToName } from "../../../data/integration";
|
||||
import type { LovelaceBadgeConfig } from "../../../data/lovelace/config/badge";
|
||||
import type { LovelaceCardConfig } from "../../../data/lovelace/config/card";
|
||||
import type { LovelaceSectionConfig } from "../../../data/lovelace/config/section";
|
||||
import type { LovelaceViewConfig } from "../../../data/lovelace/config/view";
|
||||
import { computeUserInitials } from "../../../data/user";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { HELPER_DOMAINS } from "../../config/helpers/const";
|
||||
import type { EntityBadgeConfig } from "../badges/types";
|
||||
import type {
|
||||
AlarmPanelCardConfig,
|
||||
EntitiesCardConfig,
|
||||
@@ -33,7 +31,8 @@ import type {
|
||||
} from "../cards/types";
|
||||
import type { EntityConfig } from "../entity-rows/types";
|
||||
import type { ButtonsHeaderFooterConfig } from "../header-footer/types";
|
||||
import { computeLovelaceEntityName } from "./entity/compute-lovelace-entity-name";
|
||||
import type { LovelaceBadgeConfig } from "../../../data/lovelace/config/badge";
|
||||
import type { EntityBadgeConfig } from "../badges/types";
|
||||
|
||||
const HIDE_DOMAIN = new Set([
|
||||
"ai_task",
|
||||
@@ -126,13 +125,13 @@ export const computeSection = (
|
||||
});
|
||||
|
||||
export const computeCards = (
|
||||
hass: HomeAssistant,
|
||||
states: HassEntities,
|
||||
entityIds: string[],
|
||||
entityCardOptions: Partial<EntitiesCardConfig>,
|
||||
renderFooterEntities = true
|
||||
): LovelaceCardConfig[] => {
|
||||
const cards: LovelaceCardConfig[] = [];
|
||||
const states = hass.states;
|
||||
|
||||
// For entity card
|
||||
const entitiesConf: (string | EntityConfig)[] = [];
|
||||
|
||||
@@ -271,23 +270,19 @@ export const computeCards = (
|
||||
? states[a]
|
||||
? computeStateName(states[a])
|
||||
: ""
|
||||
: states[a.entity]
|
||||
? computeLovelaceEntityName(hass, states[a.entity], a.name)
|
||||
: "",
|
||||
: a.name || "",
|
||||
typeof b === "string"
|
||||
? states[b]
|
||||
? computeStateName(states[b])
|
||||
: ""
|
||||
: states[b.entity]
|
||||
? computeLovelaceEntityName(hass, states[b.entity], b.name)
|
||||
: ""
|
||||
: b.name || ""
|
||||
);
|
||||
});
|
||||
|
||||
// If we ended up with footer entities but no normal entities,
|
||||
// render the footer entities as normal entities.
|
||||
if (entitiesConf.length === 0 && footerEntities.length > 0) {
|
||||
return computeCards(hass, entityIds, entityCardOptions, false);
|
||||
return computeCards(states, entityIds, entityCardOptions, false);
|
||||
}
|
||||
|
||||
if (entitiesConf.length > 0 || footerEntities.length > 0) {
|
||||
@@ -365,14 +360,14 @@ const computeDefaultViewStates = (
|
||||
};
|
||||
|
||||
export const generateViewConfig = (
|
||||
hass: HomeAssistant,
|
||||
localize: LocalizeFunc,
|
||||
path: string,
|
||||
title: string | undefined,
|
||||
icon: string | undefined,
|
||||
entities: HassEntities
|
||||
): LovelaceViewConfig => {
|
||||
const ungroupedEntitites: Record<string, string[]> = {};
|
||||
const { localize } = hass;
|
||||
|
||||
// Organize ungrouped entities in ungrouped things
|
||||
for (const entityId of Object.keys(entities)) {
|
||||
const state = entities[entityId];
|
||||
@@ -475,7 +470,7 @@ export const generateViewConfig = (
|
||||
.forEach((domain) => {
|
||||
cards.push(
|
||||
...computeCards(
|
||||
hass,
|
||||
entities,
|
||||
ungroupedEntitites[domain].sort((a, b) =>
|
||||
stringCompare(
|
||||
computeStateName(entities[a]),
|
||||
@@ -503,17 +498,16 @@ export const generateViewConfig = (
|
||||
};
|
||||
|
||||
export const generateDefaultViewConfig = (
|
||||
hass: HomeAssistant,
|
||||
areaEntries: HomeAssistant["areas"],
|
||||
deviceEntries: HomeAssistant["devices"],
|
||||
entityEntries: HomeAssistant["entities"],
|
||||
entities: HassEntities,
|
||||
localize: LocalizeFunc,
|
||||
energyPrefs?: EnergyPreferences,
|
||||
areasPrefs?: AreasDisplayValue,
|
||||
hideEntitiesWithoutAreas?: boolean,
|
||||
hideEnergy?: boolean
|
||||
): LovelaceViewConfig => {
|
||||
const entities = hass.states;
|
||||
const areaEntries = hass.areas;
|
||||
const deviceEntries = hass.devices;
|
||||
const entityEntries = hass.entities;
|
||||
const states = computeDefaultViewStates(entities, entityEntries);
|
||||
const path = "default_view";
|
||||
const title = "Home";
|
||||
@@ -555,7 +549,7 @@ export const generateDefaultViewConfig = (
|
||||
|
||||
for (const groupEntity of splittedByGroups.groups) {
|
||||
groupCards.push(
|
||||
...computeCards(hass, groupEntity.attributes.entity_id, {
|
||||
...computeCards(entities, groupEntity.attributes.entity_id, {
|
||||
title: computeStateName(groupEntity),
|
||||
show_header_toggle: groupEntity.attributes.control !== "hidden",
|
||||
})
|
||||
@@ -563,7 +557,7 @@ export const generateDefaultViewConfig = (
|
||||
}
|
||||
|
||||
const config = generateViewConfig(
|
||||
hass,
|
||||
localize,
|
||||
path,
|
||||
title,
|
||||
icon,
|
||||
@@ -581,7 +575,7 @@ export const generateDefaultViewConfig = (
|
||||
const area = areaEntries[areaId];
|
||||
areaCards.push(
|
||||
...computeCards(
|
||||
hass,
|
||||
entities,
|
||||
areaEntities.map((entity) => entity.entity_id),
|
||||
{
|
||||
title: area.name,
|
||||
@@ -607,7 +601,7 @@ export const generateDefaultViewConfig = (
|
||||
const device = deviceEntries[deviceId];
|
||||
deviceCards.push(
|
||||
...computeCards(
|
||||
hass,
|
||||
entities,
|
||||
deviceEntities.map((entity) => entity.entity_id),
|
||||
{
|
||||
title:
|
||||
|
||||
@@ -2,12 +2,8 @@
|
||||
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
||||
import type { EntityConfig, LovelaceRowConfig } from "../entity-rows/types";
|
||||
|
||||
interface BaseEntityConfig {
|
||||
type: string;
|
||||
entity: string;
|
||||
}
|
||||
export const processConfigEntities = <
|
||||
T extends BaseEntityConfig | LovelaceRowConfig,
|
||||
T extends EntityConfig | LovelaceRowConfig,
|
||||
>(
|
||||
entities: (T | string)[],
|
||||
checkEntityId = true
|
||||
|
||||
@@ -45,13 +45,14 @@ export class HuiEntityEditor extends LitElement {
|
||||
this.hass.devices
|
||||
);
|
||||
|
||||
const name = this.hass.formatEntityName(
|
||||
stateObj,
|
||||
useDeviceName ? { type: "device" } : { type: "entity" }
|
||||
);
|
||||
|
||||
const isRTL = computeRTL(this.hass);
|
||||
|
||||
const primary =
|
||||
this.hass.formatEntityName(
|
||||
stateObj,
|
||||
useDeviceName ? { type: "device" } : { type: "entity" }
|
||||
) || item.entity;
|
||||
const primary = item.name || name || item.entity;
|
||||
|
||||
const secondary = this.hass.formatEntityName(
|
||||
stateObj,
|
||||
|
||||
@@ -4,19 +4,19 @@ import { customElement, property } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { DOMAINS_INPUT_ROW } from "../../../common/const";
|
||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||
import { toggleAttribute } from "../../../common/dom/toggle_attribute";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/entity/state-badge";
|
||||
import "../../../components/ha-relative-time";
|
||||
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import type { EntitiesCardEntityConfig } from "../cards/types";
|
||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { handleAction } from "../common/handle-action";
|
||||
import { hasAction, hasAnyAction } from "../common/has-action";
|
||||
import { createEntityNotFoundWarning } from "./hui-warning";
|
||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||
|
||||
@customElement("hui-generic-entity-row")
|
||||
export class HuiGenericEntityRow extends LitElement {
|
||||
@@ -59,11 +59,7 @@ export class HuiGenericEntityRow extends LitElement {
|
||||
const pointer = hasAnyAction(this.config);
|
||||
|
||||
const hasSecondary = this.secondaryText || this.config.secondary_info;
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass,
|
||||
stateObj,
|
||||
this.config.name
|
||||
);
|
||||
const name = this.config.name ?? computeStateName(stateObj);
|
||||
|
||||
return html`
|
||||
<div
|
||||
@@ -91,7 +87,7 @@ export class HuiGenericEntityRow extends LitElement {
|
||||
class="info ${classMap({ "text-content": !hasSecondary })}"
|
||||
.title=${name}
|
||||
>
|
||||
${name}
|
||||
${this.config.name || computeStateName(stateObj)}
|
||||
${hasSecondary
|
||||
? html`
|
||||
<div class="secondary">
|
||||
|
||||
@@ -296,7 +296,11 @@ export class HuiCreateDialogCard
|
||||
}
|
||||
|
||||
private _suggestCards(): void {
|
||||
const cardConfig = computeCards(this.hass, this._selectedEntities, {});
|
||||
const cardConfig = computeCards(
|
||||
this.hass.states,
|
||||
this._selectedEntities,
|
||||
{}
|
||||
);
|
||||
|
||||
let sectionOptions: Partial<LovelaceSectionConfig> = {};
|
||||
|
||||
|
||||
@@ -46,18 +46,20 @@ export class HuiGenericEntityRowEditor
|
||||
return [
|
||||
{ name: "entity", required: true, selector: { entity: {} } },
|
||||
{
|
||||
name: "name",
|
||||
selector: { entity_name: {} },
|
||||
context: { entity: "entity" },
|
||||
},
|
||||
{
|
||||
name: "icon",
|
||||
selector: {
|
||||
icon: {},
|
||||
},
|
||||
context: {
|
||||
icon_entity: "entity",
|
||||
},
|
||||
type: "grid",
|
||||
name: "",
|
||||
schema: [
|
||||
{ name: "name", selector: { text: {} } },
|
||||
{
|
||||
name: "icon",
|
||||
selector: {
|
||||
icon: {},
|
||||
},
|
||||
context: {
|
||||
icon_entity: "entity",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "secondary_info",
|
||||
|
||||
@@ -11,20 +11,20 @@ import {
|
||||
string,
|
||||
union,
|
||||
} from "superstruct";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import "../hui-sub-element-editor";
|
||||
import type { EditDetailElementEvent, SubElementEditorConfig } from "../types";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { ConfigEntity, GlanceCardConfig } from "../../cards/types";
|
||||
import "../../components/hui-entity-editor";
|
||||
import type { EntityConfig } from "../../entity-rows/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import "../hui-sub-element-editor";
|
||||
import { processEditorEntities } from "../process-editor-entities";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entitiesConfigStruct } from "../structs/entities-struct";
|
||||
import type { EditDetailElementEvent, SubElementEditorConfig } from "../types";
|
||||
import type { EntityConfig } from "../../entity-rows/types";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
@@ -42,17 +42,11 @@ const cardConfigStruct = assign(
|
||||
|
||||
const SUB_SCHEMA = [
|
||||
{ name: "entity", selector: { entity: {} }, required: true },
|
||||
{
|
||||
name: "name",
|
||||
selector: { entity_name: {} },
|
||||
context: {
|
||||
entity: "entity",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "grid",
|
||||
name: "",
|
||||
schema: [
|
||||
{ name: "name", selector: { text: {} } },
|
||||
{
|
||||
name: "icon",
|
||||
selector: {
|
||||
|
||||
@@ -45,13 +45,7 @@ const cardConfigStruct = assign(
|
||||
|
||||
const SUB_SCHEMA = [
|
||||
{ name: "entity", selector: { entity: {} }, required: true },
|
||||
{
|
||||
name: "name",
|
||||
selector: { entity_name: {} },
|
||||
context: {
|
||||
entity: "entity",
|
||||
},
|
||||
},
|
||||
{ name: "name", selector: { text: {} } },
|
||||
] as const;
|
||||
|
||||
@customElement("hui-history-graph-card-editor")
|
||||
|
||||
@@ -2,7 +2,6 @@ import { mdiPalette } from "@mdi/js";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import {
|
||||
array,
|
||||
assert,
|
||||
@@ -14,19 +13,19 @@ import {
|
||||
string,
|
||||
union,
|
||||
} from "superstruct";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import { hasLocation } from "../../../../common/entity/has_location";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import "../../../../components/ha-formfield";
|
||||
import "../../../../components/ha-selector/ha-selector-select";
|
||||
import "../../../../components/ha-switch";
|
||||
import type { SelectSelector } from "../../../../data/selector";
|
||||
import "../../../../components/ha-formfield";
|
||||
import "../../../../components/ha-switch";
|
||||
import "../../../../components/ha-selector/ha-selector-select";
|
||||
import type { HomeAssistant, ValueChangedEvent } from "../../../../types";
|
||||
import { DEFAULT_HOURS_TO_SHOW, DEFAULT_ZOOM } from "../../cards/hui-map-card";
|
||||
import type { MapCardConfig, MapEntityConfig } from "../../cards/types";
|
||||
import type { MapCardConfig } from "../../cards/types";
|
||||
import "../../components/hui-entity-editor";
|
||||
import type { EntityConfig } from "../../entity-rows/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
@@ -34,6 +33,7 @@ import { processEditorEntities } from "../process-editor-entities";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import type { EntitiesEditorEvent } from "../types";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
|
||||
export const mapEntitiesConfigStruct = union([
|
||||
object({
|
||||
@@ -223,9 +223,7 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
|
||||
})
|
||||
);
|
||||
|
||||
private _entitiesValueChanged(
|
||||
ev: EntitiesEditorEvent<MapEntityConfig>
|
||||
): void {
|
||||
private _entitiesValueChanged(ev: EntitiesEditorEvent): void {
|
||||
if (ev.detail && ev.detail.entities) {
|
||||
this._config = { ...this._config!, entities: ev.detail.entities };
|
||||
|
||||
|
||||
@@ -21,13 +21,12 @@ import type { StatisticCardConfig } from "../../cards/types";
|
||||
import { headerFooterConfigStructs } from "../../header-footer/structs";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entityNameStruct } from "../structs/entity-name-struct";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
name: optional(entityNameStruct),
|
||||
name: optional(string()),
|
||||
icon: optional(string()),
|
||||
unit: optional(string()),
|
||||
stat_type: optional(string()),
|
||||
@@ -145,15 +144,11 @@ export class HuiStatisticCardEditor
|
||||
}
|
||||
: { object: {} },
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
selector: { entity_name: {} },
|
||||
context: { entity: "entity" },
|
||||
},
|
||||
{
|
||||
type: "grid",
|
||||
name: "",
|
||||
schema: [
|
||||
{ name: "name", selector: { text: {} } },
|
||||
{
|
||||
name: "icon",
|
||||
selector: {
|
||||
|
||||
@@ -4,12 +4,11 @@ import {
|
||||
actionConfigStruct,
|
||||
actionConfigStructConfirmation,
|
||||
} from "./action-struct";
|
||||
import { entityNameStruct } from "./entity-name-struct";
|
||||
|
||||
export const entitiesConfigStruct = union([
|
||||
object({
|
||||
entity: string(),
|
||||
name: optional(entityNameStruct),
|
||||
name: optional(string()),
|
||||
icon: optional(string()),
|
||||
image: optional(string()),
|
||||
secondary_info: optional(string()),
|
||||
|
||||
@@ -43,10 +43,9 @@ export interface ConfigError {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface EntitiesEditorEvent<T extends EntityConfig = EntityConfig>
|
||||
extends CustomEvent {
|
||||
export interface EntitiesEditorEvent extends CustomEvent {
|
||||
detail: {
|
||||
entities?: T[];
|
||||
entities?: EntityConfig[];
|
||||
item?: any;
|
||||
};
|
||||
target: EventTarget | null;
|
||||
|
||||
@@ -111,7 +111,11 @@ export class HuiUnusedEntities extends LitElement {
|
||||
}
|
||||
|
||||
private _addToLovelaceView(): void {
|
||||
const cardConfig = computeCards(this.hass, this._selectedEntities, {});
|
||||
const cardConfig = computeCards(
|
||||
this.hass.states,
|
||||
this._selectedEntities,
|
||||
{}
|
||||
);
|
||||
const sectionConfig = computeSection(this._selectedEntities, {});
|
||||
|
||||
if (this.lovelace.config.views.length === 1) {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { format } from "date-fns";
|
||||
import type { PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import "../../../components/ha-date-input";
|
||||
import "../../../components/ha-time-input";
|
||||
import { setDateTimeValue } from "../../../data/datetime";
|
||||
import { format } from "date-fns";
|
||||
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity";
|
||||
import { setDateTimeValue } from "../../../data/datetime";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
import type { EntityConfig, LovelaceRow } from "./types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import "../../../components/ha-time-input";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
|
||||
@customElement("hui-datetime-entity-row")
|
||||
class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
||||
@@ -53,12 +53,6 @@ class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
||||
const time = dateObj ? format(dateObj, "HH:mm:ss") : undefined;
|
||||
const date = dateObj ? format(dateObj, "yyyy-MM-dd") : undefined;
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
|
||||
return html`
|
||||
<hui-generic-entity-row
|
||||
.hass=${this.hass}
|
||||
@@ -67,7 +61,7 @@ class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
||||
>
|
||||
<div>
|
||||
<ha-date-input
|
||||
.label=${name}
|
||||
.label=${this._config.name || computeStateName(stateObj)}
|
||||
.locale=${this.hass.locale}
|
||||
.value=${date}
|
||||
.disabled=${unavailable}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/ha-date-input";
|
||||
import "../../../components/ha-time-input";
|
||||
import { isUnavailableState, UNKNOWN } from "../../../data/entity";
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
stateToIsoDateString,
|
||||
} from "../../../data/input_datetime";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
@@ -47,11 +47,7 @@ class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
const name = this._config.name || computeStateName(stateObj);
|
||||
|
||||
return html`
|
||||
<hui-generic-entity-row
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/ha-list-item";
|
||||
import "../../../components/ha-select";
|
||||
import { UNAVAILABLE } from "../../../data/entity";
|
||||
@@ -10,7 +11,6 @@ import type { InputSelectEntity } from "../../../data/input_select";
|
||||
import { setInputSelectOption } from "../../../data/input_select";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import type { EntitiesCardEntityConfig } from "../cards/types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
@@ -51,12 +51,6 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
|
||||
return html`
|
||||
<hui-generic-entity-row
|
||||
.hass=${this.hass}
|
||||
@@ -64,7 +58,7 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
||||
hide-name
|
||||
>
|
||||
<ha-select
|
||||
.label=${name}
|
||||
.label=${this._config.name || computeStateName(stateObj)}
|
||||
.value=${stateObj.state}
|
||||
.options=${stateObj.attributes.options}
|
||||
.disabled=${
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/ha-textfield";
|
||||
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity";
|
||||
import { setValue } from "../../../data/input_text";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
@@ -43,12 +43,6 @@ class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
|
||||
return html`
|
||||
<hui-generic-entity-row
|
||||
.hass=${this.hass}
|
||||
@@ -56,7 +50,7 @@ class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
|
||||
hide-name
|
||||
>
|
||||
<ha-textfield
|
||||
.label=${name}
|
||||
.label=${this._config.name || computeStateName(stateObj)}
|
||||
.disabled=${stateObj.state === UNAVAILABLE}
|
||||
.value=${stateObj.state}
|
||||
.minlength=${stateObj.attributes.min}
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/ha-list-item";
|
||||
import "../../../components/ha-select";
|
||||
import { UNAVAILABLE } from "../../../data/entity";
|
||||
@@ -10,7 +11,6 @@ import type { SelectEntity } from "../../../data/select";
|
||||
import { setSelectOption } from "../../../data/select";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import type { EntitiesCardEntityConfig } from "../cards/types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
@@ -51,12 +51,6 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
|
||||
return html`
|
||||
<hui-generic-entity-row
|
||||
.hass=${this.hass}
|
||||
@@ -64,7 +58,7 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
|
||||
hide-name
|
||||
>
|
||||
<ha-select
|
||||
.label=${name}
|
||||
.label=${this._config.name || computeStateName(stateObj)}
|
||||
.value=${stateObj.state}
|
||||
.options=${stateObj.attributes.options}
|
||||
.disabled=${stateObj.state === UNAVAILABLE}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/ha-textfield";
|
||||
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity";
|
||||
import type { TextEntity } from "../../../data/text";
|
||||
@@ -10,7 +11,6 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
import type { EntityConfig, LovelaceRow } from "./types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
|
||||
@customElement("hui-text-entity-row")
|
||||
class HuiTextEntityRow extends LitElement implements LovelaceRow {
|
||||
@@ -46,12 +46,6 @@ class HuiTextEntityRow extends LitElement implements LovelaceRow {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
|
||||
return html`
|
||||
<hui-generic-entity-row
|
||||
.hass=${this.hass}
|
||||
@@ -59,7 +53,7 @@ class HuiTextEntityRow extends LitElement implements LovelaceRow {
|
||||
hide-name
|
||||
>
|
||||
<ha-textfield
|
||||
.label=${name}
|
||||
.label=${this._config.name || computeStateName(stateObj)}
|
||||
.disabled=${stateObj.state === UNAVAILABLE}
|
||||
.value=${stateObj.state}
|
||||
.minlength=${stateObj.attributes.min}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import { isUnavailableState } from "../../../data/entity";
|
||||
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
|
||||
import type { ForecastEvent, WeatherEntity } from "../../../data/weather";
|
||||
@@ -23,7 +24,6 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||
import "../components/hui-generic-entity-row";
|
||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||
import type { LovelaceRow } from "./types";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
|
||||
@customElement("hui-weather-entity-row")
|
||||
class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
||||
@@ -119,12 +119,6 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
||||
const forecastData = getForecast(stateObj.attributes, this._forecastEvent);
|
||||
const forecast = forecastData?.forecast;
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
|
||||
return html`
|
||||
<div
|
||||
class="icon-image ${classMap({
|
||||
@@ -161,7 +155,7 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
||||
hasDoubleClick: hasAction(this._config!.double_tap_action),
|
||||
})}
|
||||
>
|
||||
${name}
|
||||
${this._config.name || computeStateName(stateObj)}
|
||||
${hasSecondary
|
||||
? html`
|
||||
<div class="secondary">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { EntityNameItem } from "../../../common/entity/compute_entity_name_display";
|
||||
import type {
|
||||
ActionConfig,
|
||||
ConfirmationRestrictionConfig,
|
||||
@@ -11,7 +10,7 @@ import type { TimestampRenderingFormat } from "../components/types";
|
||||
export interface EntityConfig {
|
||||
entity: string;
|
||||
type?: string;
|
||||
name?: string | EntityNameItem | EntityNameItem[];
|
||||
name?: string;
|
||||
icon?: string;
|
||||
image?: string;
|
||||
}
|
||||
|
||||
@@ -321,7 +321,6 @@ class HUIRoot extends LitElement {
|
||||
.id="button-${index}"
|
||||
.path=${item.icon}
|
||||
slot="trigger"
|
||||
.label=${label}
|
||||
></ha-icon-button>
|
||||
${item.subItems
|
||||
.filter((subItem) => subItem.visible)
|
||||
@@ -341,6 +340,9 @@ class HUIRoot extends LitElement {
|
||||
`
|
||||
)}
|
||||
</ha-button-menu>
|
||||
<ha-tooltip placement="bottom" .for="button-${index}">
|
||||
${label}
|
||||
</ha-tooltip>
|
||||
`
|
||||
: html`
|
||||
<ha-icon-button
|
||||
@@ -348,8 +350,10 @@ class HUIRoot extends LitElement {
|
||||
.id="button-${index}"
|
||||
.path=${item.icon}
|
||||
@click=${item.buttonAction}
|
||||
.label=${label}
|
||||
></ha-icon-button>
|
||||
<ha-tooltip placement="bottom" .for="button-${index}">
|
||||
${label}
|
||||
</ha-tooltip>
|
||||
`;
|
||||
result.push(button);
|
||||
});
|
||||
|
||||
@@ -2,15 +2,15 @@ import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import "../../../components/ha-button";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import "../../../components/ha-state-icon";
|
||||
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
|
||||
import "../../../components/ha-button";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
|
||||
import { handleAction } from "../common/handle-action";
|
||||
import { hasAction } from "../common/has-action";
|
||||
import type { ButtonRowConfig, LovelaceRow } from "../entity-rows/types";
|
||||
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
|
||||
|
||||
@customElement("hui-button-row")
|
||||
export class HuiButtonRow extends LitElement implements LovelaceRow {
|
||||
@@ -49,11 +49,8 @@ export class HuiButtonRow extends LitElement implements LovelaceRow {
|
||||
? this.hass.states[this._config.entity]
|
||||
: undefined;
|
||||
|
||||
const name = computeLovelaceEntityName(
|
||||
this.hass!,
|
||||
stateObj,
|
||||
this._config.name
|
||||
);
|
||||
const name =
|
||||
this._config.name ?? (stateObj ? computeStateName(stateObj) : "");
|
||||
|
||||
return html`
|
||||
<ha-state-icon
|
||||
|
||||
@@ -44,7 +44,10 @@ export class OriginalStatesViewStrategy extends ReactiveElement {
|
||||
// User can override default view. If they didn't, we will add one
|
||||
// that contains all entities.
|
||||
const view = generateDefaultViewConfig(
|
||||
hass,
|
||||
hass.areas,
|
||||
hass.devices,
|
||||
hass.entities,
|
||||
hass.states,
|
||||
localize,
|
||||
energyPrefs,
|
||||
config.areas,
|
||||
|
||||
Reference in New Issue
Block a user