Various fixes
This commit is contained in:
parent
e34e67aa6a
commit
6e12de2156
@ -1,30 +1,39 @@
|
|||||||
customElements.define('card-tools',
|
customElements.define('card-tools',
|
||||||
class {
|
class {
|
||||||
static CUSTOM_TYPE_PREFIX() { return "custom:"}
|
static get CUSTOM_TYPE_PREFIX() { return "custom:"}
|
||||||
static version() { return "0.3"}
|
static get version() { return "0.3"}
|
||||||
|
|
||||||
static v() {return version};
|
|
||||||
|
|
||||||
static checkVersion(v) {
|
static checkVersion(v) {
|
||||||
if (this.version() < v) {
|
if (this.version < v) {
|
||||||
throw new Error(`Old version of card-tools found. Get the latest version of card-tools.js from https://github.com/thomasloven/lovelace-card-tools`);
|
throw new Error(`Old version of card-tools found. Get the latest version of card-tools.js from https://github.com/thomasloven/lovelace-card-tools`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static litElement() {
|
static get LitElement() {
|
||||||
return Object.getPrototypeOf(customElements.get('home-assistant-main'));
|
return Object.getPrototypeOf(customElements.get('home-assistant-main'));
|
||||||
}
|
}
|
||||||
|
static litElement() { // Backwards compatibility - deprecated
|
||||||
static litHtml() {
|
return this.LitElement;
|
||||||
return this.litElement().prototype.html;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static get litCSS() {
|
static get LitHtml() {
|
||||||
|
return this.litElement().prototype.html;
|
||||||
|
}
|
||||||
|
static litHtml() { // Backwards compatibility - deprecated
|
||||||
|
return this.LitHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get LitCSS() {
|
||||||
return this.litElement().prototype.css;
|
return this.litElement().prototype.css;
|
||||||
}
|
}
|
||||||
|
|
||||||
static hass() {
|
static get hass() {
|
||||||
return document.querySelector('home-assistant').hass;
|
var hass = function() { // Backwards compatibility - deprecated
|
||||||
|
return hass;
|
||||||
|
}
|
||||||
|
for (var k in document.querySelector('home-assistant').hass)
|
||||||
|
hass[k] = document.querySelector('home-assistant').hass[k];
|
||||||
|
return hass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fireEvent(ev, detail, entity=null) {
|
static fireEvent(ev, detail, entity=null) {
|
||||||
@ -66,7 +75,7 @@ class {
|
|||||||
ll.current_view = root
|
ll.current_view = root
|
||||||
.shadowRoot.querySelector("ha-app-layout #view")
|
.shadowRoot.querySelector("ha-app-layout #view")
|
||||||
.firstElementChild
|
.firstElementChild
|
||||||
. index;
|
.index;
|
||||||
return ll;
|
return ll;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -100,8 +109,8 @@ class {
|
|||||||
delete config.error;
|
delete config.error;
|
||||||
return _createError(err, config);
|
return _createError(err, config);
|
||||||
}
|
}
|
||||||
if(tag.startsWith(this.CUSTOM_TYPE_PREFIX()))
|
if(tag.startsWith(this.CUSTOM_TYPE_PREFIX))
|
||||||
tag = tag.substr(this.CUSTOM_TYPE_PREFIX().length);
|
tag = tag.substr(this.CUSTOM_TYPE_PREFIX.length);
|
||||||
else
|
else
|
||||||
tag = `hui-${tag}-${thing}`;
|
tag = `hui-${tag}-${thing}`;
|
||||||
|
|
||||||
@ -170,7 +179,7 @@ class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const type = config.type || "default";
|
const type = config.type || "default";
|
||||||
if(SPECIAL_TYPES.has(type) || type.startsWith(this.CUSTOM_TYPE_PREFIX()))
|
if(SPECIAL_TYPES.has(type) || type.startsWith(this.CUSTOM_TYPE_PREFIX))
|
||||||
return this.createThing("row", config);
|
return this.createThing("row", config);
|
||||||
|
|
||||||
const domain = config.entity.split(".", 1)[0];
|
const domain = config.entity.split(".", 1)[0];
|
||||||
@ -178,7 +187,7 @@ class {
|
|||||||
return this.createThing("entity-row", config);
|
return this.createThing("entity-row", config);
|
||||||
}
|
}
|
||||||
|
|
||||||
static deviceID() {
|
static get deviceID() {
|
||||||
const ID_STORAGE_KEY = 'lovelace-player-device-id';
|
const ID_STORAGE_KEY = 'lovelace-player-device-id';
|
||||||
if(window['fully'] && typeof fully.getDeviceId === "function")
|
if(window['fully'] && typeof fully.getDeviceId === "function")
|
||||||
return fully.getDeviceId();
|
return fully.getDeviceId();
|
||||||
@ -271,13 +280,14 @@ class {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static args() {
|
static args(script=null) {
|
||||||
var url = document.currentScript.src
|
script = script || document.currentScript;
|
||||||
|
var url = script.src;
|
||||||
url = url.substr(url.indexOf("?")+1)
|
url = url.substr(url.indexOf("?")+1)
|
||||||
let args = {};
|
let args = {};
|
||||||
url.split("&").forEach((a) => {
|
url.split("&").forEach((a) => {
|
||||||
if(a.indexOf("=")) {
|
if(a.indexOf("=")) {
|
||||||
var parts = a.split("=");
|
let parts = a.split("=");
|
||||||
args[parts[0]] = parts[1]
|
args[parts[0]] = parts[1]
|
||||||
} else {
|
} else {
|
||||||
args[a] = true;
|
args[a] = true;
|
||||||
@ -335,12 +345,21 @@ class {
|
|||||||
if (moreInfo) moreInfo.close()
|
if (moreInfo) moreInfo.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static logger(message, script=null) {
|
||||||
|
if(!('debug' in this.args(script))) return;
|
||||||
|
|
||||||
|
if(typeof message !== "string")
|
||||||
|
message = JSON.stringify(message);
|
||||||
|
console.log(`%cDEBUG:%c ${message}`,
|
||||||
|
"color: blue; font-weight: bold", "");
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Global definition of cardTools
|
// Global definition of cardTools
|
||||||
var cardTools = customElements.get('card-tools');
|
var cardTools = customElements.get('card-tools');
|
||||||
|
|
||||||
console.info(`%cCARD-TOOLS IS INSTALLED
|
console.info(`%cCARD-TOOLS IS INSTALLED
|
||||||
%cDeviceID: ${customElements.get('card-tools').deviceID()}`,
|
%cDeviceID: ${customElements.get('card-tools').deviceID}`,
|
||||||
"color: green; font-weight: bold",
|
"color: green; font-weight: bold",
|
||||||
"");
|
"");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user