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

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maykar authored Jan 10, 2021
1 parent 4d4ec66 commit 6fbb8a0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions kiosk-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const ha = document.querySelector("home-assistant");
const main = ha.shadowRoot.querySelector("home-assistant-main").shadowRoot;
const panel = main.querySelector("partial-panel-resolver");
const drawerLayout = main.querySelector("app-drawer-layout");
const user = ha.hass.user;
let llAttempts = 0;
window.kiosk_entities = [];

Expand Down Expand Up @@ -33,7 +34,7 @@ function queryString(keywords) {

// Set localStorage item.
function setCache(k, v) {
array(k).forEach((x) => window.localStorage.setItem(x, v))
array(k).forEach((x) => window.localStorage.setItem(x, v));
}

// Retrieve localStorage item as bool.
Expand Down Expand Up @@ -65,9 +66,9 @@ function removeStyle(elements) {

function kioskMode(lovelace, config) {
llAttempts = 0;
const hass = ha.hass;
const huiRoot = lovelace.shadowRoot.querySelector("hui-root").shadowRoot;
const appToolbar = huiRoot.querySelector("app-toolbar");
const states = ha.hass.states;
const adminConfig = config.admin_settings;
const nonAdminConfig = config.non_admin_settings;
const entityConfig = config.entity_settings;
Expand All @@ -83,21 +84,21 @@ function kioskMode(lovelace, config) {
hideHeader = queryStringsSet ? hideHeader : config.kiosk || config.hide_header;
hideSidebar = queryStringsSet ? hideSidebar : config.kiosk || config.hide_sidebar;

if (adminConfig && hass.user.is_admin) {
if (adminConfig && 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) {
if (nonAdminConfig && !user.is_admin) {
hideHeader = nonAdminConfig.kiosk || nonAdminConfig.hide_header;
hideSidebar = nonAdminConfig.kiosk || nonAdminConfig.hide_sidebar;
ignoreEntity = nonAdminConfig.ignore_entity_settings;
}

if (userConfig) {
for (let conf of array(userConfig)) {
if (array(conf.users).some((x) => x.toLowerCase() == hass.user.name.toLowerCase())) {
if (array(conf.users).some((x) => x.toLowerCase() == user.name.toLowerCase())) {
hideHeader = conf.kiosk || conf.hide_header;
hideSidebar = conf.kiosk || conf.hide_sidebar;
ignoreEntity = conf.ignore_entity_settings;
Expand All @@ -110,7 +111,7 @@ function kioskMode(lovelace, config) {
const entity = Object.keys(conf.entity)[0];
const state = conf.entity[entity];
if (!window.kiosk_entities.includes(entity)) window.kiosk_entities.push(entity);
if (hass.states[entity].state == state) {
if (states[entity].state == state) {
if ("hide_header" in conf) hideHeader = conf.hide_header;
if ("hide_sidebar" in conf) hideSidebar = conf.hide_sidebar;
if ("kiosk" in conf) hideHeader = hideSidebar = conf.kiosk;
Expand Down

0 comments on commit 6fbb8a0

Please sign in to comment.