Skip to content

Commit

Permalink
fix: Support hiding builtin sensors
Browse files Browse the repository at this point in the history
Add a show field on sensors to control hide/show, with the intention to
make this field support templates as well.

```yaml
- id: state
  show: false
```
  • Loading branch information
nervetattoo committed Apr 24, 2021
1 parent 7bc58c4 commit cbe0b65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main.ts
Expand Up @@ -263,6 +263,7 @@ export default class SimpleThermostat extends LitElement {
id: sensor?.id ?? String(index),
label: sensor?.label,
template: sensor.template,
show: sensor?.show !== false,
entityId,
context,
} as PreparedSensor
Expand Down Expand Up @@ -360,16 +361,18 @@ export default class SimpleThermostat extends LitElement {

let sensorsHtml
if (this.config.version === 3) {
sensorsHtml = this.sensors.map((spec: PreparedSensor) => {
return renderTemplated({
...spec,
variables: this.config.variables,
hass: this._hass,
config: this.config,
localize: this.localize,
openEntityPopover: this.openEntityPopover,
sensorsHtml = this.sensors
.filter((spec: PreparedSensor) => spec.show !== false)
.map((spec: PreparedSensor) => {
return renderTemplated({
...spec,
variables: this.config.variables,
hass: this._hass,
config: this.config,
localize: this.localize,
openEntityPopover: this.openEntityPopover,
})
})
})
sensorsHtml = wrapSensors(this.config, sensorsHtml)
} else {
sensorsHtml = this.showSensors
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Expand Up @@ -11,6 +11,7 @@ export interface ConfigSensor {
unit?: string
decimals?: number
template?: string
show?: boolean
type?: 'relativetime' | 'template'
}

Expand All @@ -25,6 +26,7 @@ export interface PreparedSensor {
label: string | false
entityId: string
template: string
show: boolean
context: LooseObject
}

Expand Down

0 comments on commit cbe0b65

Please sign in to comment.