Skip to content

Commit

Permalink
Merge branch 'master' into PyISY_beta
Browse files Browse the repository at this point in the history
  • Loading branch information
shbatm committed Nov 6, 2020
2 parents 766daee + 35c0514 commit ef78ab9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pyisy/variables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
_LOGGER,
ATTR_ID,
ATTR_INIT,
ATTR_PRECISION,
ATTR_TS,
ATTR_VAL,
ATTR_VAR,
Expand Down Expand Up @@ -120,19 +121,21 @@ def parse(self, xml):
vid = int(attr_from_element(feature, ATTR_ID))
vtype = int(attr_from_element(feature, TAG_TYPE))
init = value_from_xml(feature, ATTR_INIT)
prec = int(value_from_xml(feature, ATTR_PRECISION, 0))
val = value_from_xml(feature, ATTR_VAL)
ts_raw = value_from_xml(feature, ATTR_TS)
t_s = parser.parse(ts_raw)
vname = self.vnames[vtype].get(vid, "")

vobj = self.vobjs[vtype].get(vid)
if vobj is None:
vobj = Variable(self, vid, vtype, vname, init, val, t_s)
vobj = Variable(self, vid, vtype, vname, init, val, t_s, prec)
self.vids[vtype].append(vid)
self.vobjs[vtype][vid] = vobj
else:
vobj.init = init
vobj.status = val
vobj.prec = prec
vobj.last_edited = t_s

_LOGGER.info("ISY Loaded Variables")
Expand Down Expand Up @@ -165,6 +168,7 @@ def update_received(self, xmldoc):
vobj.init = int(value_from_xml(xmldoc, ATTR_INIT))
else:
vobj.status = int(value_from_xml(xmldoc, ATTR_VAL))
vobj.prec = int(value_from_xml(xmldoc, ATTR_PRECISION, 0))
vobj.last_edited = parser.parse(value_from_xml(xmldoc, ATTR_TS))

_LOGGER.debug("ISY Updated Variable: %s.%s", str(vtype), str(vid))
Expand Down
19 changes: 18 additions & 1 deletion pyisy/variables/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ATTR_INIT,
ATTR_LAST_CHANGED,
ATTR_LAST_UPDATE,
ATTR_PRECISION,
ATTR_SET,
ATTR_STATUS,
ATTR_TS,
Expand Down Expand Up @@ -35,7 +36,7 @@ class Variable:
:ivar val: Watched property that represents the value of the variable.
"""

def __init__(self, variables, vid, vtype, vname, init, status, ts):
def __init__(self, variables, vid, vtype, vname, init, status, ts, prec):
"""Initialize a Variable class."""
super().__init__()
self._id = vid
Expand All @@ -44,6 +45,7 @@ def __init__(self, variables, vid, vtype, vname, init, status, ts):
self._last_update = now()
self._last_changed = now()
self._name = vname
self._prec = prec
self._status = status
self._type = vtype
self._variables = variables
Expand Down Expand Up @@ -116,6 +118,20 @@ def name(self):
"""Return the Variable Name."""
return self._name

@property
def prec(self):
"""Return the Variable Precision."""
return self._prec

@prec.setter
def prec(self, value):
"""Set the current node state and notify listeners."""
if self._prec != value:
self._prec = value
self._last_changed = now()
self.status_events.notify(self.status_feedback)
return self._prec

@property
def status(self):
"""Return the current node state."""
Expand All @@ -137,6 +153,7 @@ def status_feedback(self):
TAG_ADDRESS: self.address,
ATTR_STATUS: self._status,
ATTR_INIT: self._init,
ATTR_PRECISION: self._prec,
ATTR_TS: self._last_edited,
ATTR_LAST_CHANGED: self._last_changed,
ATTR_LAST_UPDATE: self._last_update,
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pylint-strict-informational==0.1
black==20.8b1
codespell==1.17.1
flake8-docstrings==1.5.0
flake8==3.8.3
isort==5.5.2
flake8==3.8.4
isort==5.6.4
pydocstyle==5.1.1
pyupgrade==2.7.2
pyupgrade==2.7.3
pre-commit>=2.4.0

0 comments on commit ef78ab9

Please sign in to comment.