mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add isExternalStatistic helper (#13969)
This commit is contained in:
parent
9c923e45c5
commit
c12189b27f
@ -289,3 +289,6 @@ export const getDisplayUnit = (
|
|||||||
? statisticsMetaData?.statistics_unit_of_measurement
|
? statisticsMetaData?.statistics_unit_of_measurement
|
||||||
: unit;
|
: unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isExternalStatistic = (statisticsId: string): boolean =>
|
||||||
|
statisticsId.includes(":");
|
||||||
|
@ -21,6 +21,7 @@ import type { HaRadio } from "../../../../components/ha-radio";
|
|||||||
import {
|
import {
|
||||||
getStatisticMetadata,
|
getStatisticMetadata,
|
||||||
getDisplayUnit,
|
getDisplayUnit,
|
||||||
|
isExternalStatistic,
|
||||||
} from "../../../../data/recorder";
|
} from "../../../../data/recorder";
|
||||||
|
|
||||||
@customElement("dialog-energy-gas-settings")
|
@customElement("dialog-energy-gas-settings")
|
||||||
@ -86,7 +87,7 @@ export class DialogEnergyGasSettings
|
|||||||
: "ft³ or m³");
|
: "ft³ or m³");
|
||||||
|
|
||||||
const externalSource =
|
const externalSource =
|
||||||
this._source.stat_cost && this._source.stat_cost.includes(":");
|
this._source.stat_cost && isExternalStatistic(this._source.stat_cost);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
@ -274,7 +275,7 @@ export class DialogEnergyGasSettings
|
|||||||
} else {
|
} else {
|
||||||
this._pickedDisplayUnit = undefined;
|
this._pickedDisplayUnit = undefined;
|
||||||
}
|
}
|
||||||
if (ev.detail.value.includes(":") && this._costs !== "statistic") {
|
if (isExternalStatistic(ev.detail.value) && this._costs !== "statistic") {
|
||||||
this._costs = "no-costs";
|
this._costs = "no-costs";
|
||||||
}
|
}
|
||||||
this._source = {
|
this._source = {
|
||||||
|
@ -32,6 +32,7 @@ import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
|||||||
import { entitiesConfigStruct } from "../structs/entities-struct";
|
import { entitiesConfigStruct } from "../structs/entities-struct";
|
||||||
import {
|
import {
|
||||||
getStatisticMetadata,
|
getStatisticMetadata,
|
||||||
|
isExternalStatistic,
|
||||||
StatisticsMetaData,
|
StatisticsMetaData,
|
||||||
statisticsMetaHasType,
|
statisticsMetaHasType,
|
||||||
} from "../../../../data/recorder";
|
} from "../../../../data/recorder";
|
||||||
@ -132,9 +133,8 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
disabled:
|
disabled:
|
||||||
period === "5minute" &&
|
period === "5minute" &&
|
||||||
// External statistics don't support 5-minute statistics.
|
// External statistics don't support 5-minute statistics.
|
||||||
// External statistics is formatted as <domain>:<object_id>
|
|
||||||
statisticIds?.some((statistic_id) =>
|
statisticIds?.some((statistic_id) =>
|
||||||
statistic_id.includes(":")
|
isExternalStatistic(statistic_id)
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
@ -240,7 +240,9 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
private async _entitiesChanged(ev: CustomEvent): Promise<void> {
|
private async _entitiesChanged(ev: CustomEvent): Promise<void> {
|
||||||
const config = { ...this._config!, entities: ev.detail.value };
|
const config = { ...this._config!, entities: ev.detail.value };
|
||||||
if (
|
if (
|
||||||
config.entities?.some((statistic_id) => statistic_id.includes(":")) &&
|
config.entities?.some((statistic_id) =>
|
||||||
|
isExternalStatistic(statistic_id)
|
||||||
|
) &&
|
||||||
config.period === "5minute"
|
config.period === "5minute"
|
||||||
) {
|
) {
|
||||||
delete config.period;
|
delete config.period;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user