Skip to content

Commit

Permalink
Merge pull request #649 from maxwroc/ExcludeBinary
Browse files Browse the repository at this point in the history
Exclude binary sensors in default config
  • Loading branch information
maxwroc authored Jan 12, 2024
2 parents 24290c4 + b1bcc8d commit 4130752
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ filter:
include:
- name: "attributes.device_class"
value: "battery"
exclude:
- name: "entity_id"
value: "binary_sensor.*"
sort:
by: "state"
collapse: 8
Expand Down
26 changes: 3 additions & 23 deletions src/custom-elements/battery-state-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sharedStyles from "./shared.css"
import cardStyles from "./battery-state-card.css"
import { getIdsOfSortedBatteries } from "../sorting";
import { safeGetConfigArrayOfObjects } from "../utils";
import defaultConfig from "../default-config";


/**
Expand Down Expand Up @@ -55,7 +56,8 @@ export class BatteryStateCard extends LovelaceCard<IBatteryCardConfig> {
if (this.batteryProvider == undefined || configUpdated) {
// checking whether we should apply default config
if (Object.keys(this.config).length == 1) {
this.config = getDefaultConfig();
// cloning default config
this.config = { ... defaultConfig };
}

this.batteryProvider = new BatteryProvider(this.config);
Expand Down Expand Up @@ -124,26 +126,4 @@ export class BatteryStateCard extends LovelaceCard<IBatteryCardConfig> {
// +1 to account header
return size + 1;
}
}

const getDefaultConfig = () => <IBatteryStateCardConfig>{
sort: {
by: "state"
},
collapse: 8,
filter: {
include: [{
name: "attributes.device_class",
value: "battery"
}]
},
secondary_info: "{last_changed}",
bulk_rename: [
{ from: " Battery" },
{ from: " level" },
],
colors: {
steps: [ "#ff0000", "#ffff00", "#00ff00" ],
gradient: true,
}
}
25 changes: 25 additions & 0 deletions src/default-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default <IBatteryStateCardConfig>{
sort: {
by: "state"
},
collapse: 8,
filter: {
include: [{
name: "attributes.device_class",
value: "battery"
}],
exclude: [{
name: "entity_id",
value: "binary_sensor.*"
}]
},
secondary_info: "{last_changed}",
bulk_rename: [
{ from: " Battery" },
{ from: " level" },
],
colors: {
steps: [ "#ff0000", "#ffff00", "#00ff00" ],
gradient: true,
}
}

0 comments on commit 4130752

Please sign in to comment.