Skip to content

Commit

Permalink
Fix url call
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Nov 12, 2024
1 parent 1c255d6 commit 316a2d1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
22 changes: 21 additions & 1 deletion dist/hpsu-dashboard-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,29 @@ class HpsuDashboardCardEditor extends LitElement {
`;
}

isNumeric(value) {
return /^-?\d+$/.test(value);
}

makeURL(filename) {
const scriptUrl = import.meta.url;
const urlParams = new URLSearchParams(scriptUrl.split('?')[1]);
const hacsTag = urlParams.get('hacstag');

console.log("hacsTag: " + hacsTag);
console.log("isNumeric: " + this.isNumeric(hacsTag));

const url = this.isNumeric(hacsTag) ? `/hacsfiles/daikin-rotex-hpsu-dashboard/${filename}?${hacsTag}`:
`/local/daikin-rotex-hpsu-dashboard/${filename}?${new Date().getTime()}`;
console.log(url);
return url;
}

async loadModule() {
console.log(">> loadModule");
try {
const module = await import('/local/daikin-rotex-hpsu-dashboard/modules.js');
const url = this.makeURL("modules.js");
const module = await import(url);
return module.entities_configuration;
} catch (error) {
console.error("Modul konnte nicht geladen werden:", error);
Expand Down
40 changes: 28 additions & 12 deletions dist/hpsu-dashboard-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ class HPSUDashboardCard extends HTMLElement {
async render() {
//console.log(">> render");

const scriptUrl = import.meta.url;
const urlParams = new URLSearchParams(scriptUrl.split('?')[1]);
const hacsTag = urlParams.get('hacstag');

console.log("hacsTag: " + hacsTag);
console.log("isNumeric: " + this.isNumeric(hacsTag));

const url = this.isNumeric(hacsTag) ? "/hacsfiles/daikin-rotex-hpsu-dashboard/hpsu.svg?" + hacsTag:
"/local/daikin-rotex-hpsu-dashboard/hpsu.svg?" + new Date().getTime();
const url = this.makeURL("hpsu.svg");

console.log(url);

Expand Down Expand Up @@ -247,17 +239,25 @@ class HPSUDashboardCard extends HTMLElement {
}

updateOpacity() {
console.log(">> updateOpacity");
if (this.config && this.inititialized) {
const flowArrows = this.shadowRoot.querySelector(`#DHW-Flow-Arrows`);
const flowReturnArrows = this.shadowRoot.querySelector(`#DHW-Flow-Return-Arrows`);
const heatingArrows = this.shadowRoot.querySelector(`#Heating-Flow-Arrows`);

if (!flowArrows || !flowReturnArrows || !heatingArrows) return;

//console.log(this.config);

const flow_rate_id = this.config.entities['durchfluss'];
const mixer_id = this.config.entities['mischer'];
const bypass_id = this.config.entities['bypass'];

//console.log("flow_rate_id: " + flow_rate_id);
//console.log("mixer_id: " + mixer_id);
//console.log("bypass_id: " + bypass_id);
//console.log(this._hass.states);

const flowRate = flow_rate_id ? parseFloat(this._hass.states[flow_rate_id].state) : 0;
const mischerState = mixer_id ? parseFloat(this._hass.states[mixer_id].state) : 0;
const bpvState = bypass_id ? parseFloat(this._hass.states[bypass_id].state) : 0;
Expand Down Expand Up @@ -306,14 +306,30 @@ class HPSUDashboardCard extends HTMLElement {
return /^-?\d+$/.test(value);
}

makeURL(filename) {
const scriptUrl = import.meta.url;
const urlParams = new URLSearchParams(scriptUrl.split('?')[1]);
const hacsTag = urlParams.get('hacstag');

console.log("hacsTag: " + hacsTag);
console.log("isNumeric: " + this.isNumeric(hacsTag));

const url = this.isNumeric(hacsTag) ? `/hacsfiles/daikin-rotex-hpsu-dashboard/${filename}?${hacsTag}`:
`/local/daikin-rotex-hpsu-dashboard/${filename}?${new Date().getTime()}`;
console.log(url);
return url;
}

async loadModule() {
console.log(">> loadModule");
try {
const module = await import('/local/daikin-rotex-hpsu-dashboard/modules.js');
const url = this.makeURL("modules.js");
const module = await import(url);
return module.entities_configuration;
} catch (error) {
console.error("Modul konnte nicht geladen werden:", error);
}
}
}
}

customElements.define("hpsu-dashboard-card", HPSUDashboardCard);
customElements.define("hpsu-dashboard-card", HPSUDashboardCard);

0 comments on commit 316a2d1

Please sign in to comment.