Skip to content

Commit

Permalink
Fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Feb 28, 2022
1 parent 5acd90b commit 3ba1ae4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class StateSwitch extends LitElement {
}
this.cardsInitialized = true;
this.update_state();
this._updateVisibility();
}

update_state() {
Expand Down Expand Up @@ -129,6 +130,18 @@ class StateSwitch extends LitElement {
for (const k in this.cards) this.cards[k].hass = hass;
}

_updateVisibility() {
if (this.cards[this.state]) {
this.classList.remove("no-match");
this.style.setProperty("display", "");
this.removeAttribute("hidden");
} else {
this.classList.add("no-match");
this.style.setProperty("display", "none");
this.setAttribute("hidden", "");
}
}

updated(changedProperties) {
if (!changedProperties.has("state")) {
this.update_state();
Expand All @@ -145,12 +158,8 @@ class StateSwitch extends LitElement {
}
if (this.cards[this.state]) {
this.cards[this.state].classList.add("visible");
this.classList.remove("no-match");
this.style.setProperty("display", "");
} else {
this.classList.add("no-match");
this.style.setProperty("display", "none");
}
this._updateVisibility();
}
}

Expand Down
1 change: 1 addition & 0 deletions test/lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ title: state-switch
views:
- !include views/1-standard.yaml
- !include views/2-transitions.yaml
- !include views/3-layouts.yaml
- title: test
cards:
- type: entities
Expand Down
33 changes: 33 additions & 0 deletions test/views/3-layouts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
title: Layouts
cards:
- type: entities
entities:
- light.bed_light
- type: grid
cards:
- type: markdown
content: Left
- type: custom:state-switch
entity: light.bed_light
states:
"on":
type: markdown
content: Middle
- type: markdown
content: right
- type: custom:layout-card
layout_type: custom:horizontal-layout
layout:
width: 100
reflows: true
cards:
- type: markdown
content: Left
- type: custom:state-switch
entity: light.bed_light
states:
"on":
type: markdown
content: Middle
- type: markdown
content: Right

0 comments on commit 3ba1ae4

Please sign in to comment.