Skip to content

Commit

Permalink
Fixes for force selector not changing correctly in all cases (#719)
Browse files Browse the repository at this point in the history
* Fixes for force selector not changing correctly in all cases

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] authored Feb 4, 2024
1 parent fb4bb9c commit a632d55
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import requests
import yaml

THIS_VERSION = "v7.15.13"
THIS_VERSION = "v7.15.14"
PREDBAT_FILES = ["predbat.py"]
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z"
Expand Down Expand Up @@ -10616,6 +10616,7 @@ def manual_select(self, config_item, value):
"""
item = self.config_index.get(config_item)
values = item.get("value", "")
values = values.replace("+", "")
values_list = []
if values:
values_list = values.split(",")
Expand All @@ -10628,7 +10629,10 @@ def manual_select(self, config_item, value):
values_list.remove(value)
else:
values_list.append(value)
self.expose_config(config_item, ",".join(values_list))
item_value = ",".join(values_list)
if item_value:
item_value = "+" + item_value
self.expose_config(config_item, item_value)
self.manual_times(config_item)

def manual_times(self, config_item):
Expand All @@ -10642,6 +10646,7 @@ def manual_times(self, config_item):
# Deconstruct the value into a list of minutes
item = self.config_index.get(config_item)
values = item.get("value", "")
values = values.replace("+", "")
values_list = []
if values:
values_list = values.split(",")
Expand All @@ -10663,6 +10668,8 @@ def manual_times(self, config_item):
minute_str = (self.midnight + timedelta(minutes=minute)).strftime("%H:%M:%S")
values_list.append(minute_str)
values = ",".join(values_list)
if values:
values = "+" + values

# Create the new dropdown
time_values = []
Expand All @@ -10671,14 +10678,14 @@ def manual_times(self, config_item):
if minute in time_overrides:
minute_str = "[" + minute_str + "]"
time_values.append(minute_str)

if values not in time_values:
time_values.append(values)
time_values.append("reset")
item["options"] = time_values
if not values:
values = None
item["value"] = None # Force update to expose
self.expose_config(config_item, values)
values = ""
self.expose_config(config_item, values, force=True)

if time_overrides:
time_txt = []
Expand Down Expand Up @@ -11259,7 +11266,7 @@ def get_ha_config(self, name, default):
return value, default
return None, default

def expose_config(self, name, value, quiet=True, event=False):
def expose_config(self, name, value, quiet=True, event=False, force=False):
"""
Share the config with HA
"""
Expand All @@ -11271,7 +11278,7 @@ def expose_config(self, name, value, quiet=True, event=False):
item["value"] = None
else:
entity = item.get("entity")
if entity and ((item.get("value") is None) or (value != item["value"])):
if entity and ((item.get("value") is None) or (value != item["value"]) or force):
if item.get("reset_inverter", False):
self.inverter_needs_reset = True
self.log("Set reset inverter true due to reset_inverter on item {}".format(name))
Expand Down

0 comments on commit a632d55

Please sign in to comment.