Skip to content

Commit 32ec944

Browse files
committedSep 28, 2020
wait for hass in ha_elements
1 parent cc88354 commit 32ec944

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed
 

‎src/build-header.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ export class CustomHeader {
174174
clickElement.dispatchEvent(new MouseEvent('click', { bubbles: false, cancelable: false }));
175175
};
176176
['click', 'touchend'].forEach(evt => listenElement.addEventListener(evt, clickIt, false));
177-
if (mobile) {
178-
listenElement.addEventListener('tap', clickIt, false);
179-
}
177+
if (mobile) listenElement.addEventListener('tap', clickIt, false);
180178
}
181179
}

‎src/custom-header.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ console.info(
4444
`${header} ${info} padding-bottom:6px; border-width: 0px 1px 1px 1px;`,
4545
);
4646

47-
let haElem = ha_elements();
48-
4947
const hideHeader = haElem => {
5048
if (!haElem || !haElem.appHeader) return;
5149
haElem.appHeader.style.display = 'none';
@@ -54,7 +52,7 @@ const hideHeader = haElem => {
5452
if (!window.location.href.includes('disable_ch')) hideHeader(ha_elements());
5553

5654
export const rebuild = () => {
57-
haElem = ha_elements();
55+
const haElem = ha_elements();
5856
if (
5957
document
6058
.querySelector('home-assistant')!
@@ -169,7 +167,7 @@ export const rebuild = () => {
169167
};
170168

171169
const rawConfigObserver = () => {
172-
haElem = ha_elements();
170+
const haElem = ha_elements();
173171
if (window['customHeaderRebuildMO']) window['customHeaderRebuildMO'].disconnect();
174172
if (window['customHeaderRawConfigExit']) window['customHeaderRawConfigExit'].disconnect();
175173
if (!haElem || !haElem.partialPanel) {

‎src/ha-elements.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ export const hass = getHass();
1010

1111
export const ha_elements = () => {
1212
const haElem = {};
13+
haElem.hass = getHass();
1314
haElem.lovelace = getLovelace();
1415
haElem.homeAssistant = document.querySelector('home-assistant');
1516
haElem.main = haElem.homeAssistant.shadowRoot.querySelector('home-assistant-main').shadowRoot;
16-
haElem.hass = getHass();
1717
haElem.partialPanel = haElem.main.querySelector('partial-panel-resolver');
1818
haElem.panel = haElem.main.querySelector('ha-panel-lovelace');
1919
if (!haElem.panel) return;
2020
haElem.root = haElem.panel.shadowRoot.querySelector('hui-root');
2121
if (!haElem.root) return;
2222
haElem.root = haElem.root.shadowRoot;
23-
2423
haElem.tabs = Array.from((haElem.root.querySelector('paper-tabs') || haElem.root).querySelectorAll('paper-tab'));
2524
haElem.tabContainer = haElem.root.querySelector('paper-tabs');
2625
haElem.menu = haElem.root.querySelector('ha-menu-button');
@@ -38,5 +37,4 @@ export const ha_elements = () => {
3837
haElem.sidebar.divider = haElem.sidebar.main.querySelector('div.divider');
3938
haElem.appHeader = haElem.root.querySelector('app-header');
4039
haElem.appLayout = haElem.root.querySelector('ha-app-layout');
41-
return haElem;
4240
};

0 commit comments

Comments
 (0)
Please sign in to comment.