Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with config and state updates across instances #48

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions config-entity-functions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import * as constants from "./constants.js";

const required_entries = [
"inverter_count",
"battery_soc",
"battery_flow",
"home_consumption",
"grid_flow"
]

export function buildConfig(config) {
let new_config = constants.base_config;
function deepcopy(value) {
if (!(!!value && typeof value == 'object')) {
return value;
}
if (Object.prototype.toString.call(value) == '[object Date]') {
return new Date(value.getTime());
}
if (Array.isArray(value)) {
return value.map(deepcopy);
}
const result = {};
Object.keys(value).forEach(
function(key) { result[key] = deepcopy(value[key]); });
return result;
}

config = deepcopy(config);
const new_config = deepcopy(constants.base_config)

new_config.title = config.title;

// Check inverter count
let inverter_count = parseInt(config.inverter_count);
Expand Down Expand Up @@ -165,7 +192,7 @@ export function getEntitiesState(config, hass, config_entity, index) {
}
return "-";
} catch (error) {
throw new Error(`Invalid entity: ${entity_name}`);
handleEntityError(entity_name, config_entity);
}
}

Expand Down Expand Up @@ -197,7 +224,7 @@ export function getEntitiesAttribute(config, hass, config_entity, attribute_name
return "-";
}
} catch (error) {
throw new Error(`Invalid entity: ${entity_name}`);
handleEntityError(entity_name, config_entity);
}
}

Expand All @@ -211,7 +238,13 @@ export function getEntitiesUnit(config, hass, config_entity, index) {
}
return "";
} catch (error) {
throw new Error(`Invalid entity: ${entity_name}`);
handleEntityError(entity_name, config_entity);
}
}

const handleEntityError = (config_entry, entity_name) => {
if (required_entries.includes(config_entry)) {
throw new Error(`Invalid entity: ${entity_name} for config_entry`) ;
}
}

Expand Down
23 changes: 6 additions & 17 deletions html-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ export function generateStyles(config) {
`;
}

export const card_base = `
<ha-card>
<div id="taskbar-grid" class="status-grid">
</div>
<div id="card-grid" class="diagram-grid">
</div>
<div id="datetime-info" class="update-time">
</div>
</ha-card>
`;

export function generateStatus(config) {
let text_box_full = ``;
let status_message_full = ``;
Expand Down Expand Up @@ -245,9 +234,9 @@ export function generateStatus(config) {
}

export function generateGrid(config) {
var cells = ``;
var refresh_button_left = ``;
var refresh_button_right = ``;
let cells = ``;
let refresh_button_left = ``;
let refresh_button_right = ``;

// Refresh button
if (config.refresh_button.left) {
Expand Down Expand Up @@ -331,9 +320,9 @@ export function generateGrid(config) {
}

export function generateDateTime(config) {
var date_time_info = ``;
let date_time_info = ``;
if (config.update_time.is_used) {
var date_time_info = `
let date_time_info = `
<p id="time-info">Last update at: -</p>
`;
if (config.update_time.show_last_update) {
Expand All @@ -346,7 +335,7 @@ export function generateDateTime(config) {
}

export function generateArrows() {
var inner_html = ``;
let inner_html = ``;
for (let i = 1; i < 5; i++) {
inner_html += `<div class="arrow-${i}"><img src="${constants.getBase64Data("arrow")}"></div>`;
}
Expand Down
Loading