Filter duplicate entries in energy solar/battery/gas/water/devices (#17538)

This commit is contained in:
karwosts 2023-08-10 01:59:07 -07:00 committed by GitHub
parent 5dee92b214
commit 9e31b2bb29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 81 additions and 0 deletions

View File

@ -146,6 +146,9 @@ export class EnergyBatterySettings extends LitElement {
private _addSource() {
showEnergySettingsBatteryDialog(this, {
battery_sources: this.preferences.energy_sources.filter(
(src) => src.type === "battery"
) as BatterySourceTypeEnergyPreference[],
saveCallback: async (source) => {
await this._savePreferences({
...this.preferences,
@ -160,6 +163,9 @@ export class EnergyBatterySettings extends LitElement {
ev.currentTarget.closest(".row").source;
showEnergySettingsBatteryDialog(this, {
source: { ...origSource },
battery_sources: this.preferences.energy_sources.filter(
(src) => src.type === "battery"
) as BatterySourceTypeEnergyPreference[],
saveCallback: async (newSource) => {
await this._savePreferences({
...this.preferences,

View File

@ -116,6 +116,8 @@ export class EnergyDeviceSettings extends LitElement {
private _addDevice() {
showEnergySettingsDeviceDialog(this, {
device_consumptions: this.preferences
.device_consumption as DeviceConsumptionEnergyPreference[],
saveCallback: async (device) => {
await this._savePreferences({
...this.preferences,

View File

@ -136,6 +136,9 @@ export class EnergyGasSettings extends LitElement {
this.preferences,
this.statsMetadata
),
gas_sources: this.preferences.energy_sources.filter(
(src) => src.type === "gas"
) as GasSourceTypeEnergyPreference[],
saveCallback: async (source) => {
delete source.unit_of_measurement;
await this._savePreferences({
@ -157,6 +160,9 @@ export class EnergyGasSettings extends LitElement {
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) => {
await this._savePreferences({
...this.preferences,

View File

@ -149,6 +149,9 @@ export class EnergySolarSettings extends LitElement {
private _addSource() {
showEnergySettingsSolarDialog(this, {
info: this.info!,
solar_sources: this.preferences.energy_sources.filter(
(src) => src.type === "solar"
) as SolarSourceTypeEnergyPreference[],
saveCallback: async (source) => {
await this._savePreferences({
...this.preferences,
@ -164,6 +167,9 @@ export class EnergySolarSettings extends LitElement {
showEnergySettingsSolarDialog(this, {
info: this.info!,
source: { ...origSource },
solar_sources: this.preferences.energy_sources.filter(
(src) => src.type === "solar"
) as SolarSourceTypeEnergyPreference[],
saveCallback: async (newSource) => {
await this._savePreferences({
...this.preferences,

View File

@ -135,6 +135,9 @@ export class EnergyWaterSettings extends LitElement {
private _addSource() {
showEnergySettingsWaterDialog(this, {
water_sources: this.preferences.energy_sources.filter(
(src) => src.type === "water"
) as WaterSourceTypeEnergyPreference[],
saveCallback: async (source) => {
delete source.unit_of_measurement;
await this._savePreferences({
@ -151,6 +154,9 @@ export class EnergyWaterSettings extends LitElement {
showEnergySettingsWaterDialog(this, {
source: { ...origSource },
metadata: this.statsMetadata?.[origSource.stat_energy_from],
water_sources: this.preferences.energy_sources.filter(
(src) => src.type === "water"
) as WaterSourceTypeEnergyPreference[],
saveCallback: async (newSource) => {
await this._savePreferences({
...this.preferences,

View File

@ -32,6 +32,8 @@ export class DialogEnergyBatterySettings
@state() private _error?: string;
private _excludeList?: string[];
public async showDialog(
params: EnergySettingsBatteryDialogParams
): Promise<void> {
@ -42,12 +44,23 @@ export class DialogEnergyBatterySettings
this._energy_units = (
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
).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 {
this._params = undefined;
this._source = undefined;
this._error = undefined;
this._excludeList = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@ -85,6 +98,10 @@ export class DialogEnergyBatterySettings
.label=${this.hass.localize(
"ui.panel.config.energy.battery.dialog.energy_into_battery"
)}
.excludeStatistics=${[
...(this._excludeList || []),
this._source.stat_energy_from,
]}
@value-changed=${this._statisticToChanged}
dialogInitialFocus
></ha-statistic-picker>
@ -96,6 +113,10 @@ export class DialogEnergyBatterySettings
.label=${this.hass.localize(
"ui.panel.config.energy.battery.dialog.energy_out_of_battery"
)}
.excludeStatistics=${[
...(this._excludeList || []),
this._source.stat_energy_to,
]}
@value-changed=${this._statisticFromChanged}
></ha-statistic-picker>

View File

@ -32,6 +32,8 @@ export class DialogEnergyDeviceSettings
@state() private _error?: string;
private _excludeList?: string[];
public async showDialog(
params: EnergySettingsDeviceDialogParams
): Promise<void> {
@ -39,12 +41,16 @@ export class DialogEnergyDeviceSettings
this._energy_units = (
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
).units;
this._excludeList = this._params.device_consumptions.map(
(entry) => entry.stat_consumption
);
}
public closeDialog(): void {
this._params = undefined;
this._device = undefined;
this._error = undefined;
this._excludeList = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@ -81,6 +87,7 @@ export class DialogEnergyDeviceSettings
.label=${this.hass.localize(
"ui.panel.config.energy.device_consumption.dialog.device_consumption_energy"
)}
.excludeStatistics=${this._excludeList}
@value-changed=${this._statisticChanged}
dialogInitialFocus
></ha-statistic-picker>

View File

@ -49,6 +49,8 @@ export class DialogEnergyGasSettings
@state() private _error?: string;
private _excludeList?: string[];
public async showDialog(
params: EnergySettingsGasDialogParams
): Promise<void> {
@ -74,6 +76,9 @@ export class DialogEnergyGasSettings
this._gas_units = (
await getSensorDeviceClassConvertibleUnits(this.hass, "gas")
).units;
this._excludeList = this._params.gas_sources
.map((entry) => entry.stat_energy_from)
.filter((id) => id !== this._source?.stat_energy_from);
}
public closeDialog(): void {
@ -81,6 +86,7 @@ export class DialogEnergyGasSettings
this._source = undefined;
this._pickedDisplayUnit = undefined;
this._error = undefined;
this._excludeList = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@ -139,6 +145,7 @@ export class DialogEnergyGasSettings
.label=${this.hass.localize(
"ui.panel.config.energy.gas.dialog.gas_usage"
)}
.excludeStatistics=${this._excludeList}
@value-changed=${this._statisticChanged}
dialogInitialFocus
></ha-statistic-picker>

View File

@ -101,6 +101,7 @@ export class DialogEnergyGridFlowSettings
this._source = undefined;
this._pickedDisplayUnit = undefined;
this._error = undefined;
this._excludeList = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}

View File

@ -44,6 +44,8 @@ export class DialogEnergySolarSettings
@state() private _error?: string;
private _excludeList?: string[];
public async showDialog(
params: EnergySettingsSolarDialogParams
): Promise<void> {
@ -56,12 +58,16 @@ export class DialogEnergySolarSettings
this._energy_units = (
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
).units;
this._excludeList = this._params.solar_sources
.map((entry) => entry.stat_energy_from)
.filter((id) => id !== this._source?.stat_energy_from);
}
public closeDialog(): void {
this._params = undefined;
this._source = undefined;
this._error = undefined;
this._excludeList = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@ -97,6 +103,7 @@ export class DialogEnergySolarSettings
.label=${this.hass.localize(
"ui.panel.config.energy.solar.dialog.solar_production_energy"
)}
.excludeStatistics=${this._excludeList}
@value-changed=${this._statisticChanged}
dialogInitialFocus
></ha-statistic-picker>

View File

@ -44,6 +44,8 @@ export class DialogEnergyWaterSettings
@state() private _error?: string;
private _excludeList?: string[];
public async showDialog(
params: EnergySettingsWaterDialogParams
): Promise<void> {
@ -66,6 +68,9 @@ export class DialogEnergyWaterSettings
this._water_units = (
await getSensorDeviceClassConvertibleUnits(this.hass, "water")
).units;
this._excludeList = this._params.water_sources
.map((entry) => entry.stat_energy_from)
.filter((id) => id !== this._source?.stat_energy_from);
}
public closeDialog(): void {
@ -73,6 +78,7 @@ export class DialogEnergyWaterSettings
this._source = undefined;
this._error = undefined;
this._pickedDisplayUnit = undefined;
this._excludeList = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@ -128,6 +134,7 @@ export class DialogEnergyWaterSettings
.label=${this.hass.localize(
"ui.panel.config.energy.water.dialog.water_usage"
)}
.excludeStatistics=${this._excludeList}
@value-changed=${this._statisticChanged}
dialogInitialFocus
></ha-statistic-picker>

View File

@ -44,11 +44,13 @@ export interface EnergySettingsGridFlowToDialogParams {
export interface EnergySettingsSolarDialogParams {
info: EnergyInfo;
source?: SolarSourceTypeEnergyPreference;
solar_sources: SolarSourceTypeEnergyPreference[];
saveCallback: (source: SolarSourceTypeEnergyPreference) => Promise<void>;
}
export interface EnergySettingsBatteryDialogParams {
source?: BatterySourceTypeEnergyPreference;
battery_sources: BatterySourceTypeEnergyPreference[];
saveCallback: (source: BatterySourceTypeEnergyPreference) => Promise<void>;
}
@ -56,16 +58,19 @@ export interface EnergySettingsGasDialogParams {
source?: GasSourceTypeEnergyPreference;
allowedGasUnitClass?: EnergyGasUnitClass;
metadata?: StatisticsMetaData;
gas_sources: GasSourceTypeEnergyPreference[];
saveCallback: (source: GasSourceTypeEnergyPreference) => Promise<void>;
}
export interface EnergySettingsWaterDialogParams {
source?: WaterSourceTypeEnergyPreference;
metadata?: StatisticsMetaData;
water_sources: WaterSourceTypeEnergyPreference[];
saveCallback: (source: WaterSourceTypeEnergyPreference) => Promise<void>;
}
export interface EnergySettingsDeviceDialogParams {
device_consumptions: DeviceConsumptionEnergyPreference[];
saveCallback: (device: DeviceConsumptionEnergyPreference) => Promise<void>;
}