Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use collectionKey to target correct energy cards #37

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/energy-period-selector-plus-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ export class EnergyPeriodSelectorBase extends SubscribeMixin(LitElement) {
? endOfDay(customEndDate)
: this._endDate || endOfToday();

const energyCollection = getEnergyDataCollection(this.hass);
const energyCollection = getEnergyDataCollection(this.hass, {
key: this.collectionKey,
});
energyCollection.setPeriod(startDate, endDate);
energyCollection.refresh();
}
Expand All @@ -319,7 +321,9 @@ export class EnergyPeriodSelectorBase extends SubscribeMixin(LitElement) {

private _toggleCompare() {
this._compare = !this._compare;
const energyCollection = getEnergyDataCollection(this.hass);
const energyCollection = getEnergyDataCollection(this.hass, {
key: this.collectionKey,
});
energyCollection.setCompare(this._compare);
energyCollection.refresh();
}
Expand Down
2 changes: 1 addition & 1 deletion src/energy-period-selector-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class EnergyPeriodSelectorPlus extends LitElement implements LovelaceCard
logError(localize('common.invalid_configuration') || 'Invalid configuration');
return nothing;
}
const energyPeriodSelectorBase = html` <energy-period-selector-base .hass=${this.hass} ._config=${this._config}></energy-period-selector-base> `;
const energyPeriodSelectorBase = html` <energy-period-selector-base .hass=${this.hass} ._config=${this._config} .collectionKey=${this._config?.collection_key}></energy-period-selector-base> `;
return this._config?.card_background
? html` <ha-card .header=${this._config?.title}> ${energyPeriodSelectorBase}</ha-card> `
: html` ${energyPeriodSelectorBase} `;
Expand Down
4 changes: 2 additions & 2 deletions src/energy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ const getEnergyData = async (hass: HomeAssistant, prefs: EnergyPreferences, star
};

const _energyStats: Statistics | Promise<Statistics> = energyStatIds.length
? fetchStatistics(hass!, startMinHour, end, energyStatIds, period, energyUnits, ['sum'])
? fetchStatistics(hass!, startMinHour, end, energyStatIds, period, energyUnits, ['change'])
: {};
const _waterStats: Statistics | Promise<Statistics> = waterStatIds.length
? fetchStatistics(hass!, startMinHour, end, waterStatIds, period, waterUnits, ['sum'])
? fetchStatistics(hass!, startMinHour, end, waterStatIds, period, waterUnits, ['change'])
: {};

let statsCompare;
Expand Down
2 changes: 1 addition & 1 deletion src/energy/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface StatisticsUnitConfiguration {
volume?: 'L' | 'gal' | 'ft³' | 'm³';
}

const statisticTypes = ['last_reset', 'max', 'mean', 'min', 'state', 'sum'] as const;
const statisticTypes = ['last_reset', 'max', 'mean', 'min', 'state', 'sum', 'change'] as const;
export type StatisticsTypes = (typeof statisticTypes)[number][];

export interface StatisticsValidationResults {
Expand Down
Loading