Skip to content

Commit

Permalink
Enhanced message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherjulien committed Feb 27, 2023
1 parent a00e111 commit 055ad3c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion OWNd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" OWNd - an OpenWebNet daemon """ # pylint: disable=invalid-name
__version__ = "0.7.44"
__version__ = "0.7.45"
73 changes: 45 additions & 28 deletions OWNd/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class OWNMessage:
r"^\*#(?P<who>\d+)\*(?P<where>#?\d+)(?P<where_param>(?:#\d+)*)##$"
) # *#WHO*WHERE
_DIMENSION_WRITING = re.compile(
r"^\*#(?P<who>\d+)\*(?P<where>#?\d+)?(?P<where_param>(?:#\d+)*)?\*#(?P<dimension>\d+)(?P<dimension_param>(?:#\d+)*)?(?P<dimension_value>(?:\*\d+)+)##$" # pylint: disable=line-too-long
r"^\*#(?P<who>\d+)\*(?P<where>#?\d+)?(?P<where_param>(?:#\d+)*)?\*#(?P<dimension>\d+)(?P<dimension_param>(?:#\d+)*)?(?P<dimension_value>(?:\*\d*)+)##$" # pylint: disable=line-too-long
) # *#WHO*WHERE*#DIMENSION*VAL1*VALn##
_DIMENSION_REQUEST = re.compile(
r"^\*#(?P<who>\d+)\*(?P<where>#?\d+)?(?P<where_param>(?:#\d+)*)?\*(?P<dimension>\d+)##$"
) # *#WHO*WHERE*DIMENSION##
_DIMENSION_REQUEST_REPLY = re.compile(
r"^\*#(?P<who>\d+)\*(?P<where>#?\d+)?(?P<where_param>(?:#\d+)*)?\*(?P<dimension>\d+)(?P<dimension_param>(?:#\d+)*)?(?P<dimension_value>(?:\*\d+)+)##$" # pylint: disable=line-too-long
r"^\*#(?P<who>\d+)\*(?P<where>#?\d+)?(?P<where_param>(?:#\d+)*)?\*(?P<dimension>\d+)(?P<dimension_param>(?:#\d+)*)?(?P<dimension_value>(?:\*\d*)+)##$" # pylint: disable=line-too-long
) # *#WHO*WHERE*DIMENSION*VAL1*VALn##

""" Base class for all OWN messages """
Expand Down Expand Up @@ -341,6 +341,8 @@ def parse(cls, data):
return OWNCENPlusEvent(data)
elif _where.startswith("3"):
return OWNDryContactEvent(data)
elif _who > 1000:
return cls(data)

return data

Expand Down Expand Up @@ -1132,14 +1134,15 @@ def __init__(self, data):
self._hour = self._dimension_value[0]
self._minute = self._dimension_value[1]
self._second = self._dimension_value[2]
self._timezone = (
f"+{self._dimension_value[3][1:]}"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}"
)
self._time = datetime.time.fromisoformat(
f"{self._hour}:{self._minute}:{self._second}{self._timezone}:00"
)
# Timezone is sometimes missing from messages, assuming UTC
if self._dimension_value[3] is not None:
self._timezone = (
f"+{self._dimension_value[3][1:]}:00"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}:00"
)
else:
self._timezone = ""
self._human_readable_log = f"Gateway's internal time is: {self._hour}:{self._minute}:{self._second} UTC {self._timezone}." # pylint: disable=line-too-long

elif self._dimension == 1:
Expand Down Expand Up @@ -1203,16 +1206,20 @@ def __init__(self, data):
self._hour = self._dimension_value[0]
self._minute = self._dimension_value[1]
self._second = self._dimension_value[2]
self._timezone = (
f"+{self._dimension_value[3][1:]}"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}"
)
# Timezone is sometimes missing from messages, assuming UTC
if self._dimension_value[3] is not None:
self._timezone = (
f"+{self._dimension_value[3][1:]}:00"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}:00"
)
else:
self._timezone = ""
self._day = self._dimension_value[5]
self._month = self._dimension_value[6]
self._year = self._dimension_value[7]
self._datetime = datetime.datetime.fromisoformat(
f"{self._year}-{self._month}-{self._day}*{self._hour}:{self._minute}:{self._second}{self._timezone}:00" # pylint: disable=line-too-long
f"{self._year}-{self._month}-{self._day}*{self._hour}:{self._minute}:{self._second}{self._timezone}" # pylint: disable=line-too-long
)
self._human_readable_log = (
f"Gateway's internal datetime is: {self._datetime}."
Expand Down Expand Up @@ -1612,6 +1619,8 @@ def parse(cls, data):
return cls(data)
elif _where.startswith("3"):
return OWNDryContactCommand(data)
elif _who > 1000:
return cls(data)

return None

Expand Down Expand Up @@ -1855,13 +1864,17 @@ def __init__(self, data):
self._hour = self._dimension_value[0]
self._minute = self._dimension_value[1]
self._second = self._dimension_value[2]
self._timezone = (
f"+{self._dimension_value[3][1:]}"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}"
)
# Timezone is sometimes missing from messages, assuming UTC
if self._dimension_value[3] is not None:
self._timezone = (
f"+{self._dimension_value[3][1:]}:00"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}:00"
)
else:
self._timezone = ""
self._time = datetime.time.fromisoformat(
f"{self._hour}:{self._minute}:{self._second}{self._timezone}:00"
f"{self._hour}:{self._minute}:{self._second}{self._timezone}"
)
self._human_readable_log = (
f"Gateway broadcasting internal time: {self._time}."
Expand All @@ -1882,16 +1895,20 @@ def __init__(self, data):
self._hour = self._dimension_value[0]
self._minute = self._dimension_value[1]
self._second = self._dimension_value[2]
self._timezone = (
f"+{self._dimension_value[3][1:]}"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}"
)
# Timezone is sometimes missing from messages, assuming UTC
if self._dimension_value[3] is not None:
self._timezone = (
f"+{self._dimension_value[3][1:]}:00"
if self._dimension_value[3][0] == "0"
else f"-{self._dimension_value[3][1:]}:00"
)
else:
self._timezone = ""
self._day = self._dimension_value[5]
self._month = self._dimension_value[6]
self._year = self._dimension_value[7]
self._datetime = datetime.datetime.fromisoformat(
f"{self._year}-{self._month}-{self._day}*{self._hour}:{self._minute}:{self._second}{self._timezone}:00" # pylint: disable=line-too-long
f"{self._year}-{self._month}-{self._day}*{self._hour}:{self._minute}:{self._second}{self._timezone}" # pylint: disable=line-too-long
)
self._human_readable_log = (
f"Gateway broadcasting internal datetime: {self._datetime}."
Expand Down
Binary file removed dist/OWNd-0.7.44-py3-none-any.whl
Binary file not shown.
Binary file removed dist/OWNd-0.7.44.tar.gz
Binary file not shown.
Binary file added dist/OWNd-0.7.45-py3-none-any.whl
Binary file not shown.
Binary file added dist/OWNd-0.7.45.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="OWNd",
version="0.7.44",
version="0.7.45",
author="anotherjulien",
url="https://github.com/anotherjulien/OWNd",
author_email="[email protected]",
Expand Down

0 comments on commit 055ad3c

Please sign in to comment.