Add mediaquery selector
This commit is contained in:
17
src/main.js
17
src/main.js
@@ -25,6 +25,12 @@ class StateSwitch extends LitElement {
|
||||
if(config.entity === 'hash') {
|
||||
window.addEventListener("location-changed", () => this.updated(new Map()));
|
||||
}
|
||||
if(config.entity === 'mediaquery') {
|
||||
for(const q in this.cards) {
|
||||
console.log("Register " + q);
|
||||
window.matchMedia(q).addEventListener("change", this.update_state.bind(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_state() {
|
||||
@@ -42,6 +48,17 @@ class StateSwitch extends LitElement {
|
||||
case "hash":
|
||||
newstate = location.hash.substr(1);
|
||||
break;
|
||||
case "mediaquery":
|
||||
for(const q in this.cards) {
|
||||
console.log("Check " + q);
|
||||
console.log(window.matchMedia(q));
|
||||
if(window.matchMedia(q).matches) {
|
||||
newstate = q;
|
||||
console.log(newstate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
newstate = this.hass.states[this._config.entity];
|
||||
newstate = newstate ? newstate.state : undefined;
|
||||
|
||||
Reference in New Issue
Block a user