Fix indentation in readme

This commit is contained in:
Thomas Lovén 2019-12-10 21:45:02 +01:00
parent 3d88f953d3
commit fddaed38c3
3 changed files with 100 additions and 106 deletions

200
README.md
View File

@ -48,49 +48,49 @@ If the state of `<entity>` doesn't match any `<state>`, the `<card>` for the `<d
If the `entity` parameter is set to an entity id, which card is displayed will depend on the state of that entity. If the `entity` parameter is set to an entity id, which card is displayed will depend on the state of that entity.
```yaml ```yaml
cards: cards:
- type: entities - type: entities
entities: entities:
- input_select.home_mode - input_select.home_mode
- type: custom:state-switch - type: custom:state-switch
entity: input_select.home_mode entity: input_select.home_mode
states: states:
Home: Home:
type: vertical-stack type: vertical-stack
cards: cards:
- type: entities - type: entities
title: Lights
entities:
- light.bed_light
- light.ceiling_lights
- light.kitchen_lights
- type: picture-glance
camera_image: camera.demo_camera
entities: []
Away:
type: alarm-panel
entity: alarm_control_panel.alarm
Guests:
type: glance
title: Lights title: Lights
entities: entities:
- light.bed_light - light.bed_light
- light.ceiling_lights - light.ceiling_lights
- light.kitchen_lights - light.kitchen_lights
- type: picture-glance
camera_image: camera.demo_camera
entities: []
Away:
type: alarm-panel
entity: alarm_control_panel.alarm
Guests:
type: glance
title: Lights
entities:
- light.bed_light
- light.ceiling_lights
- light.kitchen_lights
``` ```
Note that the words `on` and `off` are magic in yaml, so if the entity is e.g. a switch, you need to quote the keys in the `states:` mapping: Note that the words `on` and `off` are magic in yaml, so if the entity is e.g. a switch, you need to quote the keys in the `states:` mapping:
```yaml ```yaml
states: states:
"on": "on":
type: markdown type: markdown
content:> content:>
Light is on Light is on
"off": "off":
type: markdown type: markdown
content:> content:>
Light is off Light is off
``` ```
### hash ### hash
@ -99,69 +99,67 @@ If the `entity` parameter is set to `hash`, which card is displayed will depend
This allows for controlling the view on a browser-window to browser-window basis, and without needing a controlling entity. This allows for controlling the view on a browser-window to browser-window basis, and without needing a controlling entity.
```yaml ```yaml
cards: type: horizontal-stack
- type: horizontal-stack cards:
cards: - type: entity-button
- type: entity-button entity: light.my_dummy
entity: light.my_dummy tap_action:
tap_action: action: navigate
action: navigate navigation_path: "#p1"
navigation_path: "#p1" - type: entity-button
- type: entity-button entity: light.my_dummy
entity: light.my_dummy tap_action:
tap_action: action: navigate
action: navigate navigation_path: "#p2"
navigation_path: "#p2" - type: entity-button
- type: entity-button entity: light.my_dummy
entity: light.my_dummy tap_action:
tap_action: action: navigate
action: navigate navigation_path: "#p2"
navigation_path: "#p2" - type: custom:state-switch
- type: custom:state-switch entity: hash
entity: hash default: p1
default: p1 states:
states: p1:
p1: type: markdown
type: markdown content: |
content: | # Page 1
# Page 1 p2:
p2: type: markdown
type: markdown content: |
content: | # Page 2
# Page 2 p3:
p3: type: markdown
type: markdown content: |
content: | # Page 3
# Page 3
``` ```
### user ### user
If the `entity` parameter is set to `user`, which card is displayed will depend on the currently logged in users username. If the `entity` parameter is set to `user`, which card is displayed will depend on the currently logged in users username.
```yaml ```yaml
cards: type: custom:state-switch
- type: custom:state-switch entity: user
entity: user default: default
default: default states:
states: A:
A: type: entities
type: entities title: User A stuff
title: User A stuff entities:
entities: - light.bed_light
- light.bed_light - light.ceiling_lights
- light.ceiling_lights - light.kitchen_lights
- light.kitchen_lights B:
B: type: glance
type: glance title: User B stuff
title: User B stuff entities:
entities: - light.bed_light
- light.bed_light - light.ceiling_lights
- light.ceiling_lights - light.kitchen_lights
- light.kitchen_lights default:
default: type: markdown
type: markdown content: >
content: > ## Unknown user
## Unknown user
``` ```
### group ### group
@ -173,17 +171,17 @@ If the `entity` parameter is set to `deviceID`, which card is displayed will dep
See [browser_mod](https://github.com/thomasloven/hass-browser_mod#devices) for a description on how deviceIDs work. See [browser_mod](https://github.com/thomasloven/hass-browser_mod#devices) for a description on how deviceIDs work.
```yaml ```yaml
- type: custom:state-switch type: custom:state-switch
entity: deviceID entity: deviceID
states: states:
'9c2aaf6f-ed26e3c1': '9c2aaf6f-ed26e3c1':
type: markdown type: markdown
content: > content: >
Desktop Desktop
'c8a4981c-d69c5e3c': 'c8a4981c-d69c5e3c':
type: markdown type: markdown
content: > content: >
Mobile Mobile
``` ```
### mediaquery ### mediaquery

View File

@ -27,7 +27,6 @@ class StateSwitch extends LitElement {
} }
if(config.entity === 'mediaquery') { if(config.entity === 'mediaquery') {
for(const q in this.cards) { for(const q in this.cards) {
console.log("Register " + q);
window.matchMedia(q).addEventListener("change", this.update_state.bind(this)); window.matchMedia(q).addEventListener("change", this.update_state.bind(this));
} }
} }
@ -50,11 +49,8 @@ class StateSwitch extends LitElement {
break; break;
case "mediaquery": case "mediaquery":
for(const q in this.cards) { for(const q in this.cards) {
console.log("Check " + q);
console.log(window.matchMedia(q));
if(window.matchMedia(q).matches) { if(window.matchMedia(q).matches) {
newstate = q; newstate = q;
console.log(newstate);
break; break;
} }
} }

View File

@ -1,4 +1,4 @@
!function(e){var t={};function s(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,s),r.l=!0,r.exports}s.m=e,s.c=t,s.d=function(e,t,o){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(s.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(o,r,function(t){return e[t]}.bind(null,r));return o},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";s.r(t);const o=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),r=o.prototype.html;o.prototype.css;function n(){return document.querySelector("home-assistant").hass}const a="custom:";function i(e,t){const s=document.createElement("hui-error-card");return s.setConfig({type:"error",error:e,origConfig:t}),s}function c(e,t){if(!t||"object"!=typeof t||!t.type)return i(`No ${e} type configured`,t);let s=t.type;if(s=s.startsWith(a)?s.substr(a.length):`hui-${s}-${e}`,customElements.get(s))return function(e,t){const s=document.createElement(e);try{s.setConfig(t)}catch(e){return i(e,t)}return s}(s,t);const o=i(`Custom element doesn't exist: ${s}.`,t);o.style.display="None";const r=setTimeout(()=>{o.style.display=""},2e3);return customElements.whenDefined(s).then(()=>{clearTimeout(r),function(e,t,s=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},s)s.dispatchEvent(e);else{var o=document.querySelector("home-assistant");(o=(o=(o=(o=(o=(o=(o=(o=(o=(o=(o=o&&o.shadowRoot)&&o.querySelector("home-assistant-main"))&&o.shadowRoot)&&o.querySelector("app-drawer-layout partial-panel-resolver"))&&o.shadowRoot||o)&&o.querySelector("ha-panel-lovelace"))&&o.shadowRoot)&&o.querySelector("hui-root"))&&o.shadowRoot)&&o.querySelector("ha-app-layout #view"))&&o.firstElementChild)&&o.dispatchEvent(e)}}("ll-rebuild",{},o)}),o}function u(e){return c("card",e)}let l=function(){if(window.fully&&"function"==typeof fully.getDeviceId)return fully.getDeviceId();if(!localStorage["lovelace-player-device-id"]){const e=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);localStorage["lovelace-player-device-id"]=`${e()}${e()}-${e()}${e()}`}return localStorage["lovelace-player-device-id"]}();customElements.define("state-switch",class extends o{static get properties(){return{hass:{},state:{}}}setConfig(e){this._config=e,this.state=void 0,this.cards={};for(let t in e.states)this.cards[t]=u(e.states[t]),this.cards[t].hass=n();if("hash"===e.entity&&window.addEventListener("location-changed",()=>this.updated(new Map)),"mediaquery"===e.entity)for(const e in this.cards)console.log("Register "+e),window.matchMedia(e).addEventListener("change",this.update_state.bind(this))}update_state(){let e=void 0;switch(this._config.entity){case"user":e=this.hass&&this.hass.user&&this.hass.user.name||void 0;break;case"group":e=this.hass&&this.hass.user&&this.hass.user.is_admin?"admin":"user";case"deviceID":case"browser":e=l;break;case"hash":e=location.hash.substr(1);break;case"mediaquery":for(const t in this.cards)if(console.log("Check "+t),console.log(window.matchMedia(t)),window.matchMedia(t).matches){e=t,console.log(e);break}break;default:e=this.hass.states[this._config.entity],e=e?e.state:void 0}void 0!==e&&this.cards.hasOwnProperty(e)||(e=this._config.default),this.state=e}updated(e){if(e.has("hass"))for(let e in this.cards)this.cards[e].hass=this.hass;e.has("state")||this.update_state()}render(){return r` !function(e){var t={};function s(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,s),o.l=!0,o.exports}s.m=e,s.c=t,s.d=function(e,t,r){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)s.d(r,o,function(t){return e[t]}.bind(null,o));return r},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";s.r(t);const r=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),o=r.prototype.html;r.prototype.css;function a(){return document.querySelector("home-assistant").hass}const i="custom:";function n(e,t){const s=document.createElement("hui-error-card");return s.setConfig({type:"error",error:e,origConfig:t}),s}function c(e,t){if(!t||"object"!=typeof t||!t.type)return n(`No ${e} type configured`,t);let s=t.type;if(s=s.startsWith(i)?s.substr(i.length):`hui-${s}-${e}`,customElements.get(s))return function(e,t){const s=document.createElement(e);try{s.setConfig(t)}catch(e){return n(e,t)}return s}(s,t);const r=n(`Custom element doesn't exist: ${s}.`,t);r.style.display="None";const o=setTimeout(()=>{r.style.display=""},2e3);return customElements.whenDefined(s).then(()=>{clearTimeout(o),function(e,t,s=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},s)s.dispatchEvent(e);else{var r=document.querySelector("home-assistant");(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=(r=r&&r.shadowRoot)&&r.querySelector("home-assistant-main"))&&r.shadowRoot)&&r.querySelector("app-drawer-layout partial-panel-resolver"))&&r.shadowRoot||r)&&r.querySelector("ha-panel-lovelace"))&&r.shadowRoot)&&r.querySelector("hui-root"))&&r.shadowRoot)&&r.querySelector("ha-app-layout #view"))&&r.firstElementChild)&&r.dispatchEvent(e)}}("ll-rebuild",{},r)}),r}function u(e){return c("card",e)}let d=function(){if(window.fully&&"function"==typeof fully.getDeviceId)return fully.getDeviceId();if(!localStorage["lovelace-player-device-id"]){const e=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);localStorage["lovelace-player-device-id"]=`${e()}${e()}-${e()}${e()}`}return localStorage["lovelace-player-device-id"]}();customElements.define("state-switch",class extends r{static get properties(){return{hass:{},state:{}}}setConfig(e){this._config=e,this.state=void 0,this.cards={};for(let t in e.states)this.cards[t]=u(e.states[t]),this.cards[t].hass=a();if("hash"===e.entity&&window.addEventListener("location-changed",()=>this.updated(new Map)),"mediaquery"===e.entity)for(const e in this.cards)window.matchMedia(e).addEventListener("change",this.update_state.bind(this))}update_state(){let e=void 0;switch(this._config.entity){case"user":e=this.hass&&this.hass.user&&this.hass.user.name||void 0;break;case"group":e=this.hass&&this.hass.user&&this.hass.user.is_admin?"admin":"user";case"deviceID":case"browser":e=d;break;case"hash":e=location.hash.substr(1);break;case"mediaquery":for(const t in this.cards)if(window.matchMedia(t).matches){e=t;break}break;default:e=this.hass.states[this._config.entity],e=e?e.state:void 0}void 0!==e&&this.cards.hasOwnProperty(e)||(e=this._config.default),this.state=e}updated(e){if(e.has("hass"))for(let e in this.cards)this.cards[e].hass=this.hass;e.has("state")||this.update_state()}render(){return o`
<div id="root"> <div id="root">
${this.cards[this.state]} ${this.cards[this.state]}
</div> </div>