mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 10:46:35 +00:00
Fixes select input in statistic card editor (#15254)
This commit is contained in:
parent
eb49785557
commit
f332edc87d
@ -90,9 +90,9 @@ export class HuiStatisticCardEditor
|
|||||||
if (!config || !config.period) {
|
if (!config || !config.period) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
for (const period of Object.values(periods)) {
|
for (const [periodKey, period] of Object.entries(periods)) {
|
||||||
if (deepEqual(period, config.period)) {
|
if (deepEqual(period, config.period)) {
|
||||||
return { ...config, period };
|
return { ...config, period: periodKey };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
@ -102,7 +102,7 @@ export class HuiStatisticCardEditor
|
|||||||
(
|
(
|
||||||
entity: string,
|
entity: string,
|
||||||
icon: string,
|
icon: string,
|
||||||
periodVal: any,
|
selectedPeriodKey: string | undefined,
|
||||||
entityState: HassEntity,
|
entityState: HassEntity,
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
metadata?: StatisticsMetaData
|
metadata?: StatisticsMetaData
|
||||||
@ -130,22 +130,22 @@ export class HuiStatisticCardEditor
|
|||||||
{
|
{
|
||||||
name: "period",
|
name: "period",
|
||||||
required: true,
|
required: true,
|
||||||
selector: Object.values(periods).includes(periodVal)
|
selector:
|
||||||
? {
|
selectedPeriodKey &&
|
||||||
select: {
|
Object.keys(periods).includes(selectedPeriodKey)
|
||||||
multiple: false,
|
? {
|
||||||
options: Object.entries(periods).map(
|
select: {
|
||||||
([periodKey, period]) => ({
|
multiple: false,
|
||||||
value: period,
|
options: Object.keys(periods).map((periodKey) => ({
|
||||||
|
value: periodKey,
|
||||||
label:
|
label:
|
||||||
localize(
|
localize(
|
||||||
`ui.panel.lovelace.editor.card.statistic.periods.${periodKey}`
|
`ui.panel.lovelace.editor.card.statistic.periods.${periodKey}`
|
||||||
) || periodKey,
|
) || periodKey,
|
||||||
})
|
})),
|
||||||
),
|
},
|
||||||
},
|
}
|
||||||
}
|
: { object: {} },
|
||||||
: { object: {} },
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "grid",
|
type: "grid",
|
||||||
@ -183,7 +183,7 @@ export class HuiStatisticCardEditor
|
|||||||
const schema = this._schema(
|
const schema = this._schema(
|
||||||
this._config.entity,
|
this._config.entity,
|
||||||
this._config.icon,
|
this._config.icon,
|
||||||
data.period,
|
typeof data.period === "string" ? data.period : undefined,
|
||||||
entityState,
|
entityState,
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
this._metadata
|
this._metadata
|
||||||
@ -212,6 +212,14 @@ export class HuiStatisticCardEditor
|
|||||||
private async _valueChanged(ev: CustomEvent) {
|
private async _valueChanged(ev: CustomEvent) {
|
||||||
const config = ev.detail.value as StatisticCardConfig;
|
const config = ev.detail.value as StatisticCardConfig;
|
||||||
Object.keys(config).forEach((k) => config[k] === "" && delete config[k]);
|
Object.keys(config).forEach((k) => config[k] === "" && delete config[k]);
|
||||||
|
|
||||||
|
if (typeof config.period === "string") {
|
||||||
|
const period = periods[config.period];
|
||||||
|
if (period) {
|
||||||
|
config.period = period;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
config.stat_type &&
|
config.stat_type &&
|
||||||
config.entity &&
|
config.entity &&
|
||||||
@ -227,12 +235,14 @@ export class HuiStatisticCardEditor
|
|||||||
config.stat_type = "change";
|
config.stat_type = "change";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.stat_type && config.entity) {
|
if (!config.stat_type && config.entity) {
|
||||||
const metadata = (
|
const metadata = (
|
||||||
await getStatisticMetadata(this.hass!, [config.entity])
|
await getStatisticMetadata(this.hass!, [config.entity])
|
||||||
)?.[0];
|
)?.[0];
|
||||||
config.stat_type = metadata?.has_sum ? "change" : "mean";
|
config.stat_type = metadata?.has_sum ? "change" : "mean";
|
||||||
}
|
}
|
||||||
|
|
||||||
fireEvent(this, "config-changed", { config });
|
fireEvent(this, "config-changed", { config });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user