Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Dev to Master (#47)
Browse files Browse the repository at this point in the history
* add ignore_entity_settings & entity_settings overwrite user settings

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md
  • Loading branch information
maykar authored Jan 8, 2021
1 parent 45d3106 commit a883914
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
61 changes: 32 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ resources:
## Simple Lovelace Config
The following config method will be ignored if any [query strings/cache](#query-strings) are used or a [conditional config](#conditional-lovelace-config) has a match.

* `kiosk_mode:` has 3 options: `kiosk`, `hide_header`, and `hide_sidebar`. Set any option to true to activate.
* `kiosk_mode:` has 4 options: `kiosk`, `hide_header`, `hide_sidebar`, and `ignore_entity_settings`.
* Set any config option to true to activate.
* `kiosk: true` sets `hide_header` and `hide_sidebar` to true, no need to set either when it's used.
* `ignore_entity_settings` is useful only in [conditional configs](#conditional-lovelace-config) and will cause `entity_settings` to be ignored.

```
kiosk_mode:
Expand All @@ -73,12 +75,11 @@ views:
## Conditional Lovelace Config
Contitional configs take priority and if a condition matches all other config options/methods are ignored.
These use the same options as above, but placed under one of the following user/entity conditions:<br><br>
These use the same options as above, but placed under one of the following user/entity conditions:
**admin_settings:**<br>
Sets the config for every admin user.<br><br>
*Overwritten by entity_settings & user_settings.*<br>
### admin_settings:
Sets the config for every admin user.<br>
*Overwritten by user_settings & entity_settings ( unless `ignore_entity_settings` is used ).*<br>
```
kiosk_mode:
Expand All @@ -87,49 +88,51 @@ kiosk_mode:
```
<br>
**non_admin_settings:**<br>
Sets the config for every regular user.<br><br>
*Overwritten by entity_settings & user_settings.*<br>
### non_admin_settings:
Sets the config for every regular user.<br>
*Overwritten by user_settings & entity_settings ( unless `ignore_entity_settings` is used ).*<br>
```
kiosk_mode:
non_admin_settings:
hide_header: true
ignore_entity_settings: true
```
<br>
**entity_settings:**<br>
Dynamically change config on any entity's state. Under `entity:` list the entity followed by the state that will enable the config below. For more complex logic use this with a template sensor.<br><br>
*Overwritten by user_settings.*<br>
### user_settings:
Sets the config for specific users. **This uses a user's name, not their username (if they're different)**.<br>
*Overwritten by entity_settings if `ignore_entity_settings` is not used.*<br>
```
kiosk_mode:
entity_settings:
- entity:
input_boolean.hide_sidebar: 'on'
user_settings:
- users:
- "ryan meek"
- "maykar"
hide_sidebar: true
- entity:
input_boolean.hide_header: 'on'
hide_header: true
- entity:
input_boolean.kiosk: 'on'
- users:
- "the wife"
kiosk: true
ignore_entity_settings: true
```
<br>
**user_settings:**<br>
Sets the config for specific users. **This uses a user's name, not their username (if they're different)**.<br><br>
*Takes priority over all other config settings.*<br>
### entity_settings:
Dynamically change config on any entity's state. Under `entity:` list the entity followed by the state that will enable the config below. For more complex logic use this with a template sensor.<br>
*Takes priority over all other config settings unless they use `ignore_entity_settings`.*<br>
```
kiosk_mode:
user_settings:
- users:
- "ryan meek"
- "maykar"
entity_settings:
- entity:
input_boolean.hide_sidebar: 'on'
hide_sidebar: true
- users:
- "the wife"
- entity:
sensor.hide_header: 'on'
hide_header: true
- entity:
input_text.kiosk: 'true'
kiosk: true
```
<br>
Expand Down
24 changes: 14 additions & 10 deletions kiosk-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function kioskMode(lovelace, config) {
const nonAdminConfig = config.non_admin_settings;
const entityConfig = config.entity_settings;
let userConfig = config.user_settings;
let ignoreEntity = false;

// Retrieve localStorage values & query string options.
let hideHeader = cached("kmHeader") || queryString(["kiosk", "hide_header"]);
Expand All @@ -85,14 +86,26 @@ function kioskMode(lovelace, config) {
if (adminConfig && hass.user.is_admin) {
hideHeader = adminConfig.kiosk || adminConfig.hide_header;
hideSidebar = adminConfig.kiosk || adminConfig.hide_sidebar;
ignoreEntity = adminConfig.ignore_entity_settings;
}

if (nonAdminConfig && !hass.user.is_admin) {
hideHeader = nonAdminConfig.kiosk || nonAdminConfig.hide_header;
hideSidebar = nonAdminConfig.kiosk || nonAdminConfig.hide_sidebar;
ignoreEntity = nonAdminConfig.ignore_entity_settings;
}

if (entityConfig) {
if (userConfig) {
for (let conf of array(userConfig)) {
if (array(conf.users).some((x) => x.toLowerCase() == hass.user.name.toLowerCase())) {
hideHeader = conf.kiosk || conf.hide_header;
hideSidebar = conf.kiosk || conf.hide_sidebar;
ignoreEntity = conf.ignore_entity_settings;
}
}
}

if (entityConfig && !ignoreEntity) {
for (let conf of entityConfig) {
const entity = Object.keys(conf.entity)[0];
const state = conf.entity[entity];
Expand All @@ -105,15 +118,6 @@ function kioskMode(lovelace, config) {
}
}

if (userConfig) {
for (let conf of array(userConfig)) {
if (array(conf.users).some((x) => x.toLowerCase() == hass.user.name.toLowerCase())) {
hideHeader = conf.kiosk || conf.hide_header;
hideSidebar = conf.kiosk || conf.hide_sidebar;
}
}
}

if (hideHeader) {
addStyle("#view{min-height:100vh !important}app-header{display:none}", huiRoot);
if (queryString("cache")) setCache("kmHeader", "true");
Expand Down

0 comments on commit a883914

Please sign in to comment.