diff --git a/dist/bar.js b/dist/bar.js index ec25ca6..c22e59c 100644 --- a/dist/bar.js +++ b/dist/bar.js @@ -17,43 +17,46 @@ export const bar = { `; this.content = this.querySelector("div.card-content"); - - this.config.sensors.forEach((sensor) => { - let humidity = this._hass.states[sensor.humidity].state; - let temperature = this._hass.states[sensor.temperature].state; - let leafTemperature = temperature - (this.config.leaf_temperature_offset || 2); - if (sensor.leaf_temperature !== undefined) { - leafTemperature = this._hass.states[sensor.leaf_temperature].state; - } - let vpd; - if (sensor.vpd !== undefined) { - vpd = this._hass.states[sensor.vpd].state; - } else { - vpd = this.calculateVPD(this.toFixedNumber(leafTemperature), this.toFixedNumber(temperature), this.toFixedNumber(humidity)).toFixed(2); - } - - let card = this.content.querySelector(`ha-card[data-sensor="${sensor.name}"]`); - if (!card) { - card = document.createElement('ha-card'); - card.dataset.sensor = sensor.name; - card.className = 'vpd-card'; - } - // if sensor.name is not empty than show in the card - let html = `
`; - card.innerHTML = html; - this.content.appendChild(card); - }); + if (this._hass) { + this.config.sensors.forEach((sensor) => { + let humidity = this._hass.states[sensor.humidity].state; + let temperature = this._hass.states[sensor.temperature].state; + let leafTemperature = temperature - (this.config.leaf_temperature_offset || 2); + if (sensor.leaf_temperature !== undefined) { + if (this._hass.states[sensor.leaf_temperature] !== undefined) { + leafTemperature = this._hass.states[sensor.leaf_temperature].state; + } + } + let vpd; + if (sensor.vpd !== undefined) { + vpd = this._hass.states[sensor.vpd].state; + } else { + vpd = this.calculateVPD(this.toFixedNumber(leafTemperature), this.toFixedNumber(temperature), this.toFixedNumber(humidity)).toFixed(2); + } + + let card = this.content.querySelector(`ha-card[data-sensor="${sensor.name}"]`); + if (!card) { + card = document.createElement('ha-card'); + card.dataset.sensor = sensor.name; + card.className = 'vpd-card'; + } + // if sensor.name is not empty than show in the card + let html = ` `; + card.innerHTML = html; + this.content.appendChild(card); + }); + } } - + console.log() this.updateBars(); this.updateVPDLegend(); diff --git a/dist/ha-vpd-chart-editor.js b/dist/ha-vpd-chart-editor.js index 9a0ef56..c62fc44 100644 --- a/dist/ha-vpd-chart-editor.js +++ b/dist/ha-vpd-chart-editor.js @@ -165,7 +165,11 @@ export class HaVpdChartEditor extends HTMLElement { const index = target.getAttribute('data-index'); let value = target.value; if (this._vpd_phases[index].className !== value) { - this._config.vpd_phases[index].className = value; + if (Object.isExtensible(this._config.vpd_phases[index])) { + this._config.vpd_phases[index].className = value; + } else { + console.warn('Cannot define property on a non-extensible object'); + } fireEvent(this, 'config-changed', {config: this._config}); } } @@ -356,7 +360,13 @@ export class HaVpdChartEditor extends HTMLElement { configValues.forEach(({id, prop, type}) => { const element = this.shadowRoot.querySelector(`#${id}`); - if (element) element[type] = this[prop]; + if (element) { + if (Object.isExtensible(element)) { + element[type] = this[prop]; + } else { + console.warn('Cannot define property on a non-extensible object'); + } + } }); const minVPD = this.toFixedNumber(this.calculateVPD(this._max_temperature - this._leaf_temperature_offset, this._max_temperature, this._max_humidity)); diff --git a/dist/ha-vpd-chart.js b/dist/ha-vpd-chart.js index d8b42f9..3de62e9 100644 --- a/dist/ha-vpd-chart.js +++ b/dist/ha-vpd-chart.js @@ -1,5 +1,5 @@ // Set version for the card -window.vpdChartVersion = "1.3.8"; +window.vpdChartVersion = "1.3.9"; import {methods} from './methods.js'; import {chart} from './chart.js';