From 2b409eaaa4e877652e204f93229e005abb5e8dc9 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:37:56 +0000 Subject: [PATCH] Fixes (#429) * Add version info to auto-generated dashboard * Update dynamic-entities-card.yaml --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- apps/predbat/predbat.py | 26 +++++++++++++++++--------- dynamic-entities-card.yaml | 7 +++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 9fe6375e..5be5293e 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -16,7 +16,7 @@ import appdaemon.plugins.hass.hassapi as hass import adbase as ad -THIS_VERSION = "v7.14.1" +THIS_VERSION = "v7.14.3" TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z" TIME_FORMAT_OCTOPUS = "%Y-%m-%d %H:%M:%S%z" @@ -3100,7 +3100,9 @@ def record_status(self, message, debug="", had_errors=False, notify=False, extra self.call_notify("Predbat status change to: " + message + extra) self.dashboard_item( - self.prefix + ".status", state=message, attributes={"friendly_name": "Status", "icon": "mdi:information", "last_updated": datetime.now(), "debug": debug} + self.prefix + ".status", + state=message, + attributes={"friendly_name": "Status", "icon": "mdi:information", "last_updated": datetime.now(), "debug": debug, "version": THIS_VERSION}, ) if had_errors: self.had_errors = True @@ -5762,7 +5764,7 @@ def publish_discharge_limit(self, discharge_window, discharge_limits, best): state=discharge_limit_percent, attributes={ "results": discharge_limit_time, - "rate" : discharge_average, + "rate": discharge_average, "friendly_name": "Predicted discharge limit best", "state_class": "measurement", "unit_of_measurement": "%", @@ -5810,7 +5812,7 @@ def publish_discharge_limit(self, discharge_window, discharge_limits, best): state=discharge_limit_percent, attributes={ "results": discharge_limit_time, - "rate" : discharge_average, + "rate": discharge_average, "friendly_name": "Predicted discharge limit", "state_class": "measurement", "unit_of_measurement": "%", @@ -5912,7 +5914,7 @@ def publish_charge_limit(self, charge_limit, charge_window, charge_limit_percent "state_class": "measurement", "unit_of_measurement": "%", "icon": "mdi:battery-charging", - "rate" : charge_average_first, + "rate": charge_average_first, }, ) self.dashboard_item( @@ -5960,7 +5962,7 @@ def publish_charge_limit(self, charge_limit, charge_window, charge_limit_percent "state_class": "measurement", "unit_of_measurement": "%", "icon": "mdi:battery-charging", - "rate" : charge_average_first, + "rate": charge_average_first, }, ) self.dashboard_item( @@ -8506,6 +8508,12 @@ def fetch_sensor_data(self): elif self.octopus_intelligent_charging: octopus_ready_time = self.get_arg("octopus_ready_time", None) octopus_limit = self.get_arg("octopus_charge_limit", None) + if octopus_limit: + try: + octopus_limit = float(octopus_limit) + except ValueError: + self.log("Warn: octopus_limit is set to a bad value {} in apps.yaml, must be a number".format(octopus_limit)) + octopus_limit = None if octopus_limit: octopus_limit = self.dp2(float(octopus_limit) * self.car_charging_battery_size[0] / 100.0) self.car_charging_limit[0] = min(self.car_charging_limit[0], octopus_limit) @@ -8574,7 +8582,7 @@ def fetch_sensor_data(self): saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_penny) / octopoints_per_penny # Octopoints per pence if code: self.log("Joining Octopus saving event code {} start {} end {} price per kWh {}".format(code, start, end, saving_rate)) - self.call_service("octopus_energy/join_octoplus_saving_session_event", event_code = code, entity_id = entity_id) + self.call_service("octopus_energy/join_octoplus_saving_session_event", event_code=code, entity_id=entity_id) if joined_events: for event in joined_events: @@ -9246,7 +9254,7 @@ def create_entity_list(self): """ text = "" - text += "# Predbat Dashboard\n" + text += "# Predbat Dashboard - {}\n".format(THIS_VERSION) text += "type: entities\n" text += "Title: Predbat\n" text += "entities:\n" @@ -9580,4 +9588,4 @@ def run_time_loop_balance(self, cb_args): except Exception as e: self.log("ERROR: Exception raised {}".format(e)) self.record_status("ERROR: Exception raised {}".format(e)) - raise e \ No newline at end of file + raise e diff --git a/dynamic-entities-card.yaml b/dynamic-entities-card.yaml index 21f36695..1b0bc5bb 100644 --- a/dynamic-entities-card.yaml +++ b/dynamic-entities-card.yaml @@ -1,8 +1,11 @@ type: vertical-stack title: Predbat 🦇 cards: - - type: entity - entity: predbat.status + - type: entities + entities: + - entity: predbat.status + - entity: update.predbat_version + - entity: select.predbat_mode - type: custom:collapsable-cards title: 🔀 Control defaultOpen: false