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

Processing exclude filter after entity update #682

Merged
merged 1 commit into from
Feb 11, 2024
Merged
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
10 changes: 4 additions & 6 deletions src/battery-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ export class BatteryProvider {
this.processIncludes(hass);
}

this.processExcludes(hass);

const updateComplete = Object.keys(this.batteries).map(id => {
const battery = this.batteries[id];
battery.hass = hass;
return battery.cardUpdated;
});

await Promise.all(updateComplete);

this.processExcludes();
}

/**
Expand Down Expand Up @@ -214,9 +214,8 @@ export class BatteryProvider {

/**
* Removes or hides batteries based on filter.exclude config.
* @param hass Home Assistant instance
*/
private processExcludes(hass: HomeAssistant) {
private processExcludes() {
if (this.exclude == undefined) {
return;
}
Expand All @@ -228,9 +227,8 @@ export class BatteryProvider {
const battery = this.batteries[entityId];
let isHidden = false;
for (let filter of filters) {
const entityState = hass.states[entityId];
// we want to show batteries for which entities are missing in HA
if (entityState !== undefined && filter.isValid(entityState, battery.state)) {
if (filter.isValid(battery.entityData, battery.state)) {
if (filter.is_permanent) {
// permanent filters have conditions based on static values so we can safely
// remove such battery to avoid updating them unnecessarily
Expand Down
2 changes: 1 addition & 1 deletion src/custom-elements/battery-state-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class BatteryStateEntity extends LovelaceCard<IBatteryEntityConfig> {
/**
* Raw entity data
*/
public entityData: IMap<any>;
public entityData: IMap<any> = {};

/**
* Numeric representation of the state
Expand Down
Loading