mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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
|
||||
: unit;
|
||||
};
|
||||
|
||||
export const isExternalStatistic = (statisticsId: string): boolean =>
|
||||
statisticsId.includes(":");
|
||||
|
@ -21,6 +21,7 @@ import type { HaRadio } from "../../../../components/ha-radio";
|
||||
import {
|
||||
getStatisticMetadata,
|
||||
getDisplayUnit,
|
||||
isExternalStatistic,
|
||||
} from "../../../../data/recorder";
|
||||
|
||||
@customElement("dialog-energy-gas-settings")
|
||||
@ -86,7 +87,7 @@ export class DialogEnergyGasSettings
|
||||
: "ft³ or m³");
|
||||
|
||||
const externalSource =
|
||||
this._source.stat_cost && this._source.stat_cost.includes(":");
|
||||
this._source.stat_cost && isExternalStatistic(this._source.stat_cost);
|
||||
|
||||
return html`
|
||||
<ha-dialog
|
||||
@ -274,7 +275,7 @@ export class DialogEnergyGasSettings
|
||||
} else {
|
||||
this._pickedDisplayUnit = undefined;
|
||||
}
|
||||
if (ev.detail.value.includes(":") && this._costs !== "statistic") {
|
||||
if (isExternalStatistic(ev.detail.value) && this._costs !== "statistic") {
|
||||
this._costs = "no-costs";
|
||||
}
|
||||
this._source = {
|
||||
|
@ -32,6 +32,7 @@ import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entitiesConfigStruct } from "../structs/entities-struct";
|
||||
import {
|
||||
getStatisticMetadata,
|
||||
isExternalStatistic,
|
||||
StatisticsMetaData,
|
||||
statisticsMetaHasType,
|
||||
} from "../../../../data/recorder";
|
||||
@ -132,9 +133,8 @@ export class HuiStatisticsGraphCardEditor
|
||||
disabled:
|
||||
period === "5minute" &&
|
||||
// External statistics don't support 5-minute statistics.
|
||||
// External statistics is formatted as <domain>:<object_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> {
|
||||
const config = { ...this._config!, entities: ev.detail.value };
|
||||
if (
|
||||
config.entities?.some((statistic_id) => statistic_id.includes(":")) &&
|
||||
config.entities?.some((statistic_id) =>
|
||||
isExternalStatistic(statistic_id)
|
||||
) &&
|
||||
config.period === "5minute"
|
||||
) {
|
||||
delete config.period;
|
||||
|
Loading…
x
Reference in New Issue
Block a user