From a00c6822ced5a7eeac1e1f8140d35cc18f77add8 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 1 Jan 2025 08:23:51 +0100 Subject: [PATCH] proper variable initialization --- .gitignore | 1 + ClientMsg.py | 3 +++ ModelUrlMsg.py | 7 ++++--- NameMsg.py | 6 +++--- NetworkIdMsg.py | 2 ++ ThingMsg.py | 9 +++++---- test/__pycache__/thing_test.cpython-312.pyc | Bin 1823 -> 0 bytes 7 files changed, 18 insertions(+), 10 deletions(-) delete mode 100644 test/__pycache__/thing_test.cpython-312.pyc diff --git a/.gitignore b/.gitignore index 96403d3..e5ddc82 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/* +test/__pycache__/* \ No newline at end of file diff --git a/ClientMsg.py b/ClientMsg.py index 6451d8e..a431436 100644 --- a/ClientMsg.py +++ b/ClientMsg.py @@ -8,10 +8,13 @@ class ClientMsg(IMessage): id = 0xA0 length = 2 + network_id = None + ## Create a Client message # # @param network_id The network id of the local participant. Use 0 if it is unknown def __init__(self, network_id): + if isinstance(network_id, int): self.network_id = network_id elif isinstance(network_id, bytes): diff --git a/ModelUrlMsg.py b/ModelUrlMsg.py index 863c1a2..bd670e2 100644 --- a/ModelUrlMsg.py +++ b/ModelUrlMsg.py @@ -3,6 +3,10 @@ from Messages import IMessage class ModelUrlMsg(IMessage): id = 0x90 length = 4 + + network_id = None + thing_id = None + url = None def __init__(self, data, thing = None): if isinstance(data, bytes): @@ -15,9 +19,6 @@ class ModelUrlMsg(IMessage): if thing is not None: self.thing_id = thing.id self.url = thing.model_url - else: - self.thing_id = None - self.url = None def Serialize(self, buffer_ref): if self.network_id is None or self.thing_id is None or self.url is None: diff --git a/NameMsg.py b/NameMsg.py index b799196..5acb8bd 100644 --- a/NameMsg.py +++ b/NameMsg.py @@ -4,6 +4,9 @@ class NameMsg(IMessage): id = 0x91 length = 4 + thing_id = None + name = None + def __init__(self, data, thing = None): if isinstance(data, bytes): self.network_id = data[1] @@ -15,9 +18,6 @@ class NameMsg(IMessage): if thing is not None: self.thing_id = thing.id self.name = thing.name - else: - self.thing_id = None - self.name = None def Serialize(self, buffer_ref): if self.network_id is None or self.thing_id is None or self.name is None: diff --git a/NetworkIdMsg.py b/NetworkIdMsg.py index d289042..280fae5 100644 --- a/NetworkIdMsg.py +++ b/NetworkIdMsg.py @@ -7,6 +7,8 @@ class NetworkIdMsg(IMessage): id = 0xA1 length = 2 + network_id = None + ## Create a network id message # # @param network_id The network id assigned to the remote participant. diff --git a/ThingMsg.py b/ThingMsg.py index 8c0ddcf..b97f597 100644 --- a/ThingMsg.py +++ b/ThingMsg.py @@ -4,6 +4,11 @@ class ThingMsg(IMessage): id = 0x80 length = 5 + network_id = None + thing_id = None + thing_type = None + parent_id = None + def __init__(self, data, thing=None): if isinstance(data, bytes): self.network_id = data[1] @@ -16,10 +21,6 @@ class ThingMsg(IMessage): self.thing_id = thing.id self.thing_type = thing.type self.parent_id = thing.parent_id - else: - self.thing_id = None - self.thing_type = None - self.parent_id = None def Serialize(self, buffer_ref): if self.network_id is None or self.thing_id is None: diff --git a/test/__pycache__/thing_test.cpython-312.pyc b/test/__pycache__/thing_test.cpython-312.pyc deleted file mode 100644 index 98a11fc52943161c27af47e7d5913401a2c899ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1823 zcmbtUOK%%h6h3zzjvo^{JQAmI8}eu+EQp6xl~8$9il~4E4Oyfc3u$C|rpdTtd$@BA z*f^+2LAX*Sin2%$3%YC-egHoKiIq!Gt*I+j0wlV#a93Gz&e)EriI57{^10{S^StMN zbAB2hj{>gGqGBVY0Q^eAV5xnkyN%2)m|!vovb~*U8Oo9)6{W1i=uCFxqMVf(NbnAr z$~Ks)1%>b+*l^#Mdwf>4LT2ddivavt3D7n^v>9;weTG4mRatuM5y`7*=Bw+Qc4-5d z*jkPYJ8!$WlE@F-XlH$)JB`dP#;1z2lF7CqE1MEhr7EWtKN3V*w>*&_xR56{1E|pM zX*}HpailYuDSa>ROJoGF#YF!)0E1$;Br#|m6e!Nf8rYdi4ehq%x>Oh&F+s5|@Aq>u z80I*xp?|lm%Ueoat}CWm!x&ewN`Ce!t6_!MzgII7pWRrlLKV`X)x*g0*;g~K;BVPx zvjAzykJ#>tX>!Z+e8nwu@#qh1m)&>{l_5^O;nY4~5q8n?LlxJ|3CoXM4)ztt@k2fK zj_NC(cdKUETTg)_OCUZfFm~<6mjlwVNLt zgcsV#C$1;K6sexSYFQ6Z7)8~+l|bTL0XfoW!-he3GYmg!70D&)rJ$cD-d(jJE2=v8@vpTRSln%~}~$fW^nkG+VkEzBe)7oS1(MD0I$&qBUxFovj5`1T