Skip to content

Commit

Permalink
stateengine: re-fix time handling
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Sep 27, 2024
1 parent f78a5b1 commit 2f18d59
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions stateengine/StateEngineValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,28 @@ def __init__(self, abitem, name, allow_value_list=False, value_type=None):
self.__valid_valuetypes = ["value", "regex", "eval", "var", "item", "template", "struct"]
if value_type == "str":
self.__cast_func = StateEngineTools.cast_str
self.__cast = "str"
elif value_type == "regex":
self.__cast_func = self.cast_regex
self.__cast = "regex"
elif value_type == "num":
self.__cast_func = StateEngineTools.cast_num
self.__cast = "num"
elif value_type == "item":
self.__cast_func = self.cast_item
self.__cast = "item"
elif value_type == "bool":
self.__cast_func = StateEngineTools.cast_bool
self.__cast = "bool"
elif value_type == "time":
self.__cast_func = StateEngineTools.cast_time
self.__cast = "time"
elif value_type == "list":
self.__cast_func = StateEngineTools.cast_list
self.__cast = "list"
else:
self.__cast_func = None
self.__cast = None

def __repr__(self):
return "{}".format(self.get())
Expand Down Expand Up @@ -156,6 +164,7 @@ def __resetvalue(self):
self.__struct = None
self.__varname = None
self.__template = None
self.__cast = None
self._additional_sources = []
self.__listorder = []
self.__type_listorder = []
Expand All @@ -170,6 +179,8 @@ def set(self, value, name="", reset=True, copyvalue=True, returnvalue=False):
value = copy.copy(value)
if reset:
self.__resetvalue()
if name:
self.__cast = name
returnvalues = []
if isinstance(value, list):
source = []
Expand Down Expand Up @@ -273,7 +284,7 @@ def set(self, value, name="", reset=True, copyvalue=True, returnvalue=False):
except Exception:
cond1 = False
cond2 = False
if name == "time" and cond1 and cond2:
if (name == "time" or self.__cast == "time") and cond1 and cond2:
field_value = value
source = "value"
elif field_value == "":
Expand Down Expand Up @@ -324,7 +335,7 @@ def set(self, value, name="", reset=True, copyvalue=True, returnvalue=False):
except Exception:
cond1 = False
cond2 = False
if name == "time" and cond1 and cond2:
if (name == "time" or self.__cast == "time") and cond1 and cond2:
field_value[i] = '{}:{}'.format(source[i], field_value[i])
s = "value"
elif field_value[i] == "":
Expand Down

0 comments on commit 2f18d59

Please sign in to comment.