From a88391485879fa70101f18eb4a6cf2dedca962e7 Mon Sep 17 00:00:00 2001
From: Ryan Meek <25127328+maykar@users.noreply.github.com>
Date: Fri, 8 Jan 2021 16:18:24 -0500
Subject: [PATCH] Dev to Master (#47)
* add ignore_entity_settings & entity_settings overwrite user settings
* Update README.md
* Update README.md
* Update README.md
* Update README.md
* Update README.md
---
README.md | 61 +++++++++++++++++++++++++++------------------------
kiosk-mode.js | 24 +++++++++++---------
2 files changed, 46 insertions(+), 39 deletions(-)
diff --git a/README.md b/README.md
index 3b9663a..8ec48b5 100644
--- a/README.md
+++ b/README.md
@@ -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:
@@ -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:
-These use the same options as above, but placed under one of the following user/entity conditions:
-
-**admin_settings:**
-Sets the config for every admin user.
-*Overwritten by entity_settings & user_settings.*
+### admin_settings:
+Sets the config for every admin user.
+*Overwritten by user_settings & entity_settings ( unless `ignore_entity_settings` is used ).*
```
kiosk_mode:
@@ -87,49 +88,51 @@ kiosk_mode:
```
-**non_admin_settings:**
-Sets the config for every regular user.
-*Overwritten by entity_settings & user_settings.*
+### non_admin_settings:
+Sets the config for every regular user.
+*Overwritten by user_settings & entity_settings ( unless `ignore_entity_settings` is used ).*
```
kiosk_mode:
non_admin_settings:
hide_header: true
+ ignore_entity_settings: true
```
-**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.
-*Overwritten by user_settings.*
+### user_settings:
+Sets the config for specific users. **This uses a user's name, not their username (if they're different)**.
+*Overwritten by entity_settings if `ignore_entity_settings` is not used.*
```
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
```
-**user_settings:**
-Sets the config for specific users. **This uses a user's name, not their username (if they're different)**.
-*Takes priority over all other config settings.*
+### 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.
+*Takes priority over all other config settings unless they use `ignore_entity_settings`.*
```
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
```
diff --git a/kiosk-mode.js b/kiosk-mode.js
index 4dbe351..9c8f301 100644
--- a/kiosk-mode.js
+++ b/kiosk-mode.js
@@ -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"]);
@@ -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];
@@ -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");