-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6f2641
commit b8c48b9
Showing
16 changed files
with
133 additions
and
32 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "card-mod", | ||
"render_readme": true, | ||
"homeassistant": "2023.4.0b0" | ||
"homeassistant": "2023.4.0b5" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const ID_STORAGE_KEY = "browser_mod-browser-id"; | ||
export function BrowserID() { | ||
if (document.querySelector("hc-main")) return "CAST"; | ||
if (localStorage[ID_STORAGE_KEY]) return localStorage[ID_STORAGE_KEY]; | ||
return ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export async function hass_base_el() { | ||
await Promise.race([ | ||
customElements.whenDefined("home-assistant"), | ||
customElements.whenDefined("hc-main"), | ||
]); | ||
|
||
const element = customElements.get("home-assistant") | ||
? "home-assistant" | ||
: "hc-main"; | ||
|
||
while (!document.querySelector(element)) | ||
await new Promise((r) => window.setTimeout(r, 100)); | ||
return document.querySelector(element); | ||
} | ||
|
||
export async function hass() { | ||
const base: any = await hass_base_el(); | ||
while (!base.hass) await new Promise((r) => window.setTimeout(r, 100)); | ||
return base.hass; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const TIMEOUT_ERROR = "SELECTTREE-TIMEOUT"; | ||
|
||
export async function await_element(el, hard = false) { | ||
if (el.localName?.includes("-")) | ||
await customElements.whenDefined(el.localName); | ||
if (el.updateComplete) await el.updateComplete; | ||
if (hard) { | ||
if (el.pageRendered) await el.pageRendered; | ||
if (el._panelState) { | ||
let rounds = 0; | ||
while (el._panelState !== "loaded" && rounds++ < 5) | ||
await new Promise((r) => setTimeout(r, 100)); | ||
} | ||
} | ||
} | ||
|
||
async function _selectTree(root, path, all = false) { | ||
let el = [root]; | ||
if (typeof path === "string") { | ||
path = path.split(/(\$| )/); | ||
} | ||
while (path[path.length - 1] === "") path.pop(); | ||
for (const [i, p] of path.entries()) { | ||
const e = el[0]; | ||
if (!e) return null; | ||
|
||
if (!p.trim().length) continue; | ||
|
||
await_element(e); | ||
el = p === "$" ? [e.shadowRoot] : e.querySelectorAll(p); | ||
} | ||
return all ? el : el[0]; | ||
} | ||
|
||
export async function selectTree(root, path, all = false, timeout = 10000) { | ||
return Promise.race([ | ||
_selectTree(root, path, all), | ||
new Promise((_, reject) => | ||
setTimeout(() => reject(new Error(TIMEOUT_ERROR)), timeout) | ||
), | ||
]).catch((err) => { | ||
if (!err.message || err.message !== TIMEOUT_ERROR) throw err; | ||
return null; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const _load_yaml2json = async () => { | ||
if (customElements.get("developer-tools-event")) return; | ||
|
||
await customElements.whenDefined("partial-panel-resolver"); | ||
const ppr: any = document.createElement("partial-panel-resolver"); | ||
|
||
ppr.hass = { | ||
panels: [ | ||
{ | ||
url_path: "tmp", | ||
component_name: "developer-tools", | ||
}, | ||
], | ||
}; | ||
ppr._updateRoutes(); | ||
|
||
await ppr.routerOptions.routes.tmp.load(); | ||
|
||
await customElements.whenDefined("developer-tools-router"); | ||
const dtr: any = document.createElement("developer-tools-router"); | ||
await dtr.routerOptions.routes.event.load(); | ||
}; | ||
|
||
export const yaml2json = async (yaml) => { | ||
await _load_yaml2json(); | ||
const el: any = document.createElement("developer-tools-event"); | ||
return el._computeParsedEventData(yaml); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters