mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Filter duplicate entries in energy solar/battery/gas/water/devices (#17538)
This commit is contained in:
parent
5dee92b214
commit
9e31b2bb29
@ -146,6 +146,9 @@ export class EnergyBatterySettings extends LitElement {
|
|||||||
|
|
||||||
private _addSource() {
|
private _addSource() {
|
||||||
showEnergySettingsBatteryDialog(this, {
|
showEnergySettingsBatteryDialog(this, {
|
||||||
|
battery_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "battery"
|
||||||
|
) as BatterySourceTypeEnergyPreference[],
|
||||||
saveCallback: async (source) => {
|
saveCallback: async (source) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
@ -160,6 +163,9 @@ export class EnergyBatterySettings extends LitElement {
|
|||||||
ev.currentTarget.closest(".row").source;
|
ev.currentTarget.closest(".row").source;
|
||||||
showEnergySettingsBatteryDialog(this, {
|
showEnergySettingsBatteryDialog(this, {
|
||||||
source: { ...origSource },
|
source: { ...origSource },
|
||||||
|
battery_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "battery"
|
||||||
|
) as BatterySourceTypeEnergyPreference[],
|
||||||
saveCallback: async (newSource) => {
|
saveCallback: async (newSource) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
|
@ -116,6 +116,8 @@ export class EnergyDeviceSettings extends LitElement {
|
|||||||
|
|
||||||
private _addDevice() {
|
private _addDevice() {
|
||||||
showEnergySettingsDeviceDialog(this, {
|
showEnergySettingsDeviceDialog(this, {
|
||||||
|
device_consumptions: this.preferences
|
||||||
|
.device_consumption as DeviceConsumptionEnergyPreference[],
|
||||||
saveCallback: async (device) => {
|
saveCallback: async (device) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
|
@ -136,6 +136,9 @@ export class EnergyGasSettings extends LitElement {
|
|||||||
this.preferences,
|
this.preferences,
|
||||||
this.statsMetadata
|
this.statsMetadata
|
||||||
),
|
),
|
||||||
|
gas_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "gas"
|
||||||
|
) as GasSourceTypeEnergyPreference[],
|
||||||
saveCallback: async (source) => {
|
saveCallback: async (source) => {
|
||||||
delete source.unit_of_measurement;
|
delete source.unit_of_measurement;
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
@ -157,6 +160,9 @@ export class EnergyGasSettings extends LitElement {
|
|||||||
origSource.stat_energy_from
|
origSource.stat_energy_from
|
||||||
),
|
),
|
||||||
metadata: this.statsMetadata?.[origSource.stat_energy_from],
|
metadata: this.statsMetadata?.[origSource.stat_energy_from],
|
||||||
|
gas_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "gas"
|
||||||
|
) as GasSourceTypeEnergyPreference[],
|
||||||
saveCallback: async (newSource) => {
|
saveCallback: async (newSource) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
|
@ -149,6 +149,9 @@ export class EnergySolarSettings extends LitElement {
|
|||||||
private _addSource() {
|
private _addSource() {
|
||||||
showEnergySettingsSolarDialog(this, {
|
showEnergySettingsSolarDialog(this, {
|
||||||
info: this.info!,
|
info: this.info!,
|
||||||
|
solar_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "solar"
|
||||||
|
) as SolarSourceTypeEnergyPreference[],
|
||||||
saveCallback: async (source) => {
|
saveCallback: async (source) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
@ -164,6 +167,9 @@ export class EnergySolarSettings extends LitElement {
|
|||||||
showEnergySettingsSolarDialog(this, {
|
showEnergySettingsSolarDialog(this, {
|
||||||
info: this.info!,
|
info: this.info!,
|
||||||
source: { ...origSource },
|
source: { ...origSource },
|
||||||
|
solar_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "solar"
|
||||||
|
) as SolarSourceTypeEnergyPreference[],
|
||||||
saveCallback: async (newSource) => {
|
saveCallback: async (newSource) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
|
@ -135,6 +135,9 @@ export class EnergyWaterSettings extends LitElement {
|
|||||||
|
|
||||||
private _addSource() {
|
private _addSource() {
|
||||||
showEnergySettingsWaterDialog(this, {
|
showEnergySettingsWaterDialog(this, {
|
||||||
|
water_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "water"
|
||||||
|
) as WaterSourceTypeEnergyPreference[],
|
||||||
saveCallback: async (source) => {
|
saveCallback: async (source) => {
|
||||||
delete source.unit_of_measurement;
|
delete source.unit_of_measurement;
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
@ -151,6 +154,9 @@ export class EnergyWaterSettings extends LitElement {
|
|||||||
showEnergySettingsWaterDialog(this, {
|
showEnergySettingsWaterDialog(this, {
|
||||||
source: { ...origSource },
|
source: { ...origSource },
|
||||||
metadata: this.statsMetadata?.[origSource.stat_energy_from],
|
metadata: this.statsMetadata?.[origSource.stat_energy_from],
|
||||||
|
water_sources: this.preferences.energy_sources.filter(
|
||||||
|
(src) => src.type === "water"
|
||||||
|
) as WaterSourceTypeEnergyPreference[],
|
||||||
saveCallback: async (newSource) => {
|
saveCallback: async (newSource) => {
|
||||||
await this._savePreferences({
|
await this._savePreferences({
|
||||||
...this.preferences,
|
...this.preferences,
|
||||||
|
@ -32,6 +32,8 @@ export class DialogEnergyBatterySettings
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _excludeList?: string[];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
params: EnergySettingsBatteryDialogParams
|
params: EnergySettingsBatteryDialogParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -42,12 +44,23 @@ export class DialogEnergyBatterySettings
|
|||||||
this._energy_units = (
|
this._energy_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
||||||
).units;
|
).units;
|
||||||
|
const allSources: string[] = [];
|
||||||
|
this._params.battery_sources.forEach((entry) => {
|
||||||
|
allSources.push(entry.stat_energy_from);
|
||||||
|
allSources.push(entry.stat_energy_to);
|
||||||
|
});
|
||||||
|
this._excludeList = allSources.filter(
|
||||||
|
(id) =>
|
||||||
|
id !== this._source?.stat_energy_from &&
|
||||||
|
id !== this._source?.stat_energy_to
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
this._source = undefined;
|
this._source = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
|
this._excludeList = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +98,10 @@ export class DialogEnergyBatterySettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.battery.dialog.energy_into_battery"
|
"ui.panel.config.energy.battery.dialog.energy_into_battery"
|
||||||
)}
|
)}
|
||||||
|
.excludeStatistics=${[
|
||||||
|
...(this._excludeList || []),
|
||||||
|
this._source.stat_energy_from,
|
||||||
|
]}
|
||||||
@value-changed=${this._statisticToChanged}
|
@value-changed=${this._statisticToChanged}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
@ -96,6 +113,10 @@ export class DialogEnergyBatterySettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.battery.dialog.energy_out_of_battery"
|
"ui.panel.config.energy.battery.dialog.energy_out_of_battery"
|
||||||
)}
|
)}
|
||||||
|
.excludeStatistics=${[
|
||||||
|
...(this._excludeList || []),
|
||||||
|
this._source.stat_energy_to,
|
||||||
|
]}
|
||||||
@value-changed=${this._statisticFromChanged}
|
@value-changed=${this._statisticFromChanged}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ export class DialogEnergyDeviceSettings
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _excludeList?: string[];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
params: EnergySettingsDeviceDialogParams
|
params: EnergySettingsDeviceDialogParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -39,12 +41,16 @@ export class DialogEnergyDeviceSettings
|
|||||||
this._energy_units = (
|
this._energy_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
||||||
).units;
|
).units;
|
||||||
|
this._excludeList = this._params.device_consumptions.map(
|
||||||
|
(entry) => entry.stat_consumption
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
this._device = undefined;
|
this._device = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
|
this._excludeList = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +87,7 @@ export class DialogEnergyDeviceSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.device_consumption.dialog.device_consumption_energy"
|
"ui.panel.config.energy.device_consumption.dialog.device_consumption_energy"
|
||||||
)}
|
)}
|
||||||
|
.excludeStatistics=${this._excludeList}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
@ -49,6 +49,8 @@ export class DialogEnergyGasSettings
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _excludeList?: string[];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
params: EnergySettingsGasDialogParams
|
params: EnergySettingsGasDialogParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -74,6 +76,9 @@ export class DialogEnergyGasSettings
|
|||||||
this._gas_units = (
|
this._gas_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "gas")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "gas")
|
||||||
).units;
|
).units;
|
||||||
|
this._excludeList = this._params.gas_sources
|
||||||
|
.map((entry) => entry.stat_energy_from)
|
||||||
|
.filter((id) => id !== this._source?.stat_energy_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
@ -81,6 +86,7 @@ export class DialogEnergyGasSettings
|
|||||||
this._source = undefined;
|
this._source = undefined;
|
||||||
this._pickedDisplayUnit = undefined;
|
this._pickedDisplayUnit = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
|
this._excludeList = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +145,7 @@ export class DialogEnergyGasSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.gas.dialog.gas_usage"
|
"ui.panel.config.energy.gas.dialog.gas_usage"
|
||||||
)}
|
)}
|
||||||
|
.excludeStatistics=${this._excludeList}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
@ -101,6 +101,7 @@ export class DialogEnergyGridFlowSettings
|
|||||||
this._source = undefined;
|
this._source = undefined;
|
||||||
this._pickedDisplayUnit = undefined;
|
this._pickedDisplayUnit = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
|
this._excludeList = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ export class DialogEnergySolarSettings
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _excludeList?: string[];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
params: EnergySettingsSolarDialogParams
|
params: EnergySettingsSolarDialogParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -56,12 +58,16 @@ export class DialogEnergySolarSettings
|
|||||||
this._energy_units = (
|
this._energy_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
||||||
).units;
|
).units;
|
||||||
|
this._excludeList = this._params.solar_sources
|
||||||
|
.map((entry) => entry.stat_energy_from)
|
||||||
|
.filter((id) => id !== this._source?.stat_energy_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
this._source = undefined;
|
this._source = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
|
this._excludeList = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +103,7 @@ export class DialogEnergySolarSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.solar.dialog.solar_production_energy"
|
"ui.panel.config.energy.solar.dialog.solar_production_energy"
|
||||||
)}
|
)}
|
||||||
|
.excludeStatistics=${this._excludeList}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
@ -44,6 +44,8 @@ export class DialogEnergyWaterSettings
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _excludeList?: string[];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
params: EnergySettingsWaterDialogParams
|
params: EnergySettingsWaterDialogParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -66,6 +68,9 @@ export class DialogEnergyWaterSettings
|
|||||||
this._water_units = (
|
this._water_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "water")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "water")
|
||||||
).units;
|
).units;
|
||||||
|
this._excludeList = this._params.water_sources
|
||||||
|
.map((entry) => entry.stat_energy_from)
|
||||||
|
.filter((id) => id !== this._source?.stat_energy_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
@ -73,6 +78,7 @@ export class DialogEnergyWaterSettings
|
|||||||
this._source = undefined;
|
this._source = undefined;
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
this._pickedDisplayUnit = undefined;
|
this._pickedDisplayUnit = undefined;
|
||||||
|
this._excludeList = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +134,7 @@ export class DialogEnergyWaterSettings
|
|||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.water.dialog.water_usage"
|
"ui.panel.config.energy.water.dialog.water_usage"
|
||||||
)}
|
)}
|
||||||
|
.excludeStatistics=${this._excludeList}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
@ -44,11 +44,13 @@ export interface EnergySettingsGridFlowToDialogParams {
|
|||||||
export interface EnergySettingsSolarDialogParams {
|
export interface EnergySettingsSolarDialogParams {
|
||||||
info: EnergyInfo;
|
info: EnergyInfo;
|
||||||
source?: SolarSourceTypeEnergyPreference;
|
source?: SolarSourceTypeEnergyPreference;
|
||||||
|
solar_sources: SolarSourceTypeEnergyPreference[];
|
||||||
saveCallback: (source: SolarSourceTypeEnergyPreference) => Promise<void>;
|
saveCallback: (source: SolarSourceTypeEnergyPreference) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EnergySettingsBatteryDialogParams {
|
export interface EnergySettingsBatteryDialogParams {
|
||||||
source?: BatterySourceTypeEnergyPreference;
|
source?: BatterySourceTypeEnergyPreference;
|
||||||
|
battery_sources: BatterySourceTypeEnergyPreference[];
|
||||||
saveCallback: (source: BatterySourceTypeEnergyPreference) => Promise<void>;
|
saveCallback: (source: BatterySourceTypeEnergyPreference) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,16 +58,19 @@ export interface EnergySettingsGasDialogParams {
|
|||||||
source?: GasSourceTypeEnergyPreference;
|
source?: GasSourceTypeEnergyPreference;
|
||||||
allowedGasUnitClass?: EnergyGasUnitClass;
|
allowedGasUnitClass?: EnergyGasUnitClass;
|
||||||
metadata?: StatisticsMetaData;
|
metadata?: StatisticsMetaData;
|
||||||
|
gas_sources: GasSourceTypeEnergyPreference[];
|
||||||
saveCallback: (source: GasSourceTypeEnergyPreference) => Promise<void>;
|
saveCallback: (source: GasSourceTypeEnergyPreference) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EnergySettingsWaterDialogParams {
|
export interface EnergySettingsWaterDialogParams {
|
||||||
source?: WaterSourceTypeEnergyPreference;
|
source?: WaterSourceTypeEnergyPreference;
|
||||||
metadata?: StatisticsMetaData;
|
metadata?: StatisticsMetaData;
|
||||||
|
water_sources: WaterSourceTypeEnergyPreference[];
|
||||||
saveCallback: (source: WaterSourceTypeEnergyPreference) => Promise<void>;
|
saveCallback: (source: WaterSourceTypeEnergyPreference) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EnergySettingsDeviceDialogParams {
|
export interface EnergySettingsDeviceDialogParams {
|
||||||
|
device_consumptions: DeviceConsumptionEnergyPreference[];
|
||||||
saveCallback: (device: DeviceConsumptionEnergyPreference) => Promise<void>;
|
saveCallback: (device: DeviceConsumptionEnergyPreference) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user