Skip to content

Commit

Permalink
V2025.01.02b60
Browse files Browse the repository at this point in the history
More work on issue #103
  • Loading branch information
petergridge authored Jan 8, 2025
1 parent 9080fac commit 9750631
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion custom_components/irrigationprogram/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/petergridge/irrigation-v5/issues",
"requirements": [],
"version": "V2025.01.02b23"
"version": "V2025.01.02b60"
}
3 changes: 0 additions & 3 deletions custom_components/irrigationprogram/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

_LOGGER = logging.getLogger(__name__)



async def async_setup_entry(
hass: HomeAssistant,
config_entry: MyConfigEntry,
Expand Down Expand Up @@ -83,7 +81,6 @@ async def async_setup_entry(
programs.append(program)
async_add_entities(programs)


class ProgramConfig(SwitchEntity, RestoreEntity):

_attr_has_entity_name = True
Expand Down
85 changes: 41 additions & 44 deletions custom_components/irrigationprogram/www/irrigation-card.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
class IrrigationCard extends HTMLElement {


setConfig(config) {
if (this.lastElementChild) this.removeChild(this.lastElementChild);
const cardConfig = Object.assign({}, config);
if (!cardConfig.card) cardConfig.card = {};
if (!cardConfig.card.type) cardConfig.card.type = "entities";
if (!cardConfig.entities_vars)
cardConfig.entities_vars = { type: "entity" };
const element = document.createElement('hui-entities-card');
this._config = JSON.parse(JSON.stringify(cardConfig));
customElements.whenDefined("card-mod").then(() => {
customElements
.get("card-mod")
.applyToElement(element, "card-mod-card", this._config.card_mod.style);
});

this.appendChild(element);
}

set hass(hass) {

const config = this._config;
config.card.title = config.title;
//https://www.home-assistant.io/lovelace/header-footer/
config.card.header = config.header;
config.card.footer = config.footer;
config.card.icon = config.icon;
config.card.theme = config.theme;
// https://www.home-assistant.io/lovelace/header-footer/
// config.card.header = config.header;
// config.card.footer = config.footer;
// config.card.icon = config.icon;
// config.card.theme = config.theme;
config.card.show_header_toggle = false;
config.card.state_color = true;
let doErrors = [];
Expand All @@ -36,7 +16,7 @@ class IrrigationCard extends HTMLElement {
let zones = [];
let entities = [];

console.log("editor:constructor()");
console.log("card:constructor()");

const x = hass.states[config.program];
if (!x) {
Expand All @@ -47,6 +27,7 @@ class IrrigationCard extends HTMLElement {
});
} else {
validconfig = "valid";
console.log("valide program");
}

if (validconfig === "valid") {
Expand All @@ -57,16 +38,30 @@ class IrrigationCard extends HTMLElement {
});
config.card.title = "ERROR: " + config.program;
validconfig = "invalid";
console.log("Invalid version");
}
}

function doRenderProgram(hass) {
if (validconfig === "valid") {
console.log("call doRenderProgram()");
config.card.entities = doRenderProgram(hass);
console.log("call setConfig");
} else {
config.card.entities = doErrors;
}

this.lastElementChild.setConfig(config.card);
this.lastElementChild.hass = hass;

// Functions

function doRenderProgram(hass) {
console.log("doRenderProgram()");
// Build the Card
if (config.show_program === true) {
let showconfig = hass.states[config.program].attributes["show_config"]

var buttons = [];
const buttons = [];
buttons.length = 0;
//Add button group
buttons.push({
Expand All @@ -87,7 +82,7 @@ class IrrigationCard extends HTMLElement {
}
});

var buttons1 = [];
const buttons1 = [];
buttons1.length = 0;
buttons1.push({
entity: config.program,
Expand Down Expand Up @@ -249,7 +244,6 @@ class IrrigationCard extends HTMLElement {
}
});


let zonestatus = hass.states[zone].attributes["status"]

var condition = [{ entity: zonestatus, state: ["off"]} ]
Expand Down Expand Up @@ -280,22 +274,25 @@ class IrrigationCard extends HTMLElement {
add_entity(zone, condition, "ignore_sensors", entities)
} //AddZone

//------------------------------------------------------------

} //doRenderProgram

if (validconfig === "valid") {
config.card.entities = doRenderProgram(hass);
} else {
config.card.entities = doErrors;
}
try {
this.lastElementChild.setConfig(config.card);
}
catch (err) {
console.log("setConfig() failed ignored");
}
this.lastElementChild.hass = hass;
}

setConfig(config) {
if (this.lastElementChild) this.removeChild(this.lastElementChild);
const cardConfig = Object.assign({}, config);
if (!cardConfig.card) cardConfig.card = {};
if (!cardConfig.card.type) cardConfig.card.type = "entities";
if (!cardConfig.entities_vars)
cardConfig.entities_vars = { type: "entity" };
const element = document.createElement('hui-entities-card');
this._config = JSON.parse(JSON.stringify(cardConfig));
customElements.whenDefined("card-mod").then(() => {
customElements
.get("card-mod")
.applyToElement(element, "card-mod-card", this._config.card_mod.style);
});
this.appendChild(element);
}

static getConfigElement() {
Expand Down

0 comments on commit 9750631

Please sign in to comment.