Repository: nickw444/nessclient

Issue:
Ness D16XCEL & HomeAssistant : ValueError: 20 is not a valid PanelVersionUpdate.Model
Running ness_alarm inside HomeAssistant

I have a Ness D16XCEL (K-9323) . 

I get loads of warnings about being unable to decode the version. 

The HA logs state:

"Failed to decode packet
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/nessclient/client.py", line 134, in _recv_loop
    event = BaseEvent.decode(pkt)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/nessclient/event.py", line 39, in decode
    return StatusUpdate.decode(packet)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/nessclient/event.py", line 173, in decode
    return PanelVersionUpdate.decode(packet)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/nessclient/event.py", line 458, in decode
    model = PanelVersionUpdate.Model(int(packet.data[2:4], 16))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/enum.py", line 744, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/enum.py", line 1158, in __new__
    raise ve_exc
ValueError: 20 is not a valid PanelVersionUpdate.Model"

So I guess we need to add a version for I think 0x07 to the Model strings in PanelVersionUpdate to reflect the DX16XCEL ?

Discussion:
@ozadr1an: Some example frames I receive from the panel are:
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
870083613297002407010034204c
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
870003610005002407010034545c
820003601714b53b
87008361000400240701003455dc
8200036000180003
8200036014000007
8700836101040024070100350629
8700836101050024070100350727
8700836100050024070100350827
8700836100040024070100350927
820003601714b53b
8700036101050024070100351995
87000361329700240701003520cb
8200036000080013
8200036014000007
870003610006002407010035248a
8700036101040024070100352689
870003610106002407010035327b
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
8700036100060024070100355559
87000361010600240701003601ab
820003600000001b
8200036014000007
820003601714b53b
870083613297002407010036204a
820003600000001b
8200036014000007
820003601714b53b
8700036100060024070100363479
82000360002000fb
8200036014000007
870003610106002407010036515b
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
87000361329700240701003720c9
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
8700036100060024070100393476
820003601714b53b
82000360002000fb
8200036014000007
87008361010600240701003952d7
820003601714b53b
8700036100060024070100395456
8700036101060024070100395851
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
870003610006002407010040485b
820003601714b53b
87008361010600240701004055cd
820003600000001b
8200036014000007
870083610006002407010041130f
820003601714b53b
8700036101060024070100412081
8700036100060024070100412181
82000360002000fb
8200036014000007
870003610106002407010041257c
870003610006002407010041336f
820003601714b53b
87008361010600240701004141e0
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
870003610006002407010042079a
820003601714b53b
870083610106002407010042160a
870083613297002407010042203e
820003600000001b
8200036014000007
87008361000600240701004227fa
820003601714b53b
870003610106002407010042356b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
870083610006002407010043041c
8700836100040024070100430919
870083610106002407010043130c
820003601714b53b
870003610005002407010043158c
870003610104002407010043178a
8700036101050024070100432080
87000361329700240701004320bd
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
870083613297002407010044203c
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
820003600000001b
8200036014000007
820003601714b53b
87000361329700240701004520bb
820003600000001b
8200036014000007
820003601714b53b
@nickw444: > So I guess we need to add a version for I think 0x07 to the Model strings in PanelVersionUpdate to reflect the DX16XCEL ?

Sounds about right. Would you be able to raise a pull request to do this that also includes a test? Thanks@ozadr1an: I can probably do that. I'll have to figure out the test bit - I dont often test my code, but when I do, I do it in Prod ;) 
Lol.  Let me hack around and find out ... 

Also, I was wrong... its actually 0x14 I needed to add into event.py:

class PanelVersionUpdate(StatusUpdate):
    class Model(Enum):                                                    
        D16X = 0x00
        D16X_3G = 0x04         
        D16XCEL = 0x14     
@ozadr1an: Ok - I've submitted a PR that updates event.py with the PanelVersionUpdate and also edited the test to include a test .. 

I think thats what you wanted ?@nickw444: Yep perfect, I'll take a look

Solution patch:
diff --git a/nessclient/event.py b/nessclient/event.py
index db549c5..b1da395 100644
--- a/nessclient/event.py
+++ b/nessclient/event.py
@@ -431,6 +431,7 @@ class PanelVersionUpdate(StatusUpdate):
     class Model(Enum):
         D16X = 0x00
         D16X_3G = 0x04
+        D16XCEL = 0x14
 
     def __init__(
         self,


Test patch:
diff --git a/nessclient_tests/test_event.py b/nessclient_tests/test_event.py
index 85e09eb..51db809 100644
--- a/nessclient_tests/test_event.py
+++ b/nessclient_tests/test_event.py
@@ -234,6 +234,11 @@ class PanelVersionUpdateTestCase(unittest.TestCase):
         event = PanelVersionUpdate.decode(pkt)
         self.assertEqual(event.model, PanelVersionUpdate.Model.D16X_3G)
 
+    def test_4g_model(self):
+        pkt = make_packet(CommandType.USER_INTERFACE, "161400")
+        event = PanelVersionUpdate.decode(pkt)
+        self.assertEqual(event.model, PanelVersionUpdate.Model.D16XCEL)
+
     def test_sw_version(self):
         pkt = make_packet(CommandType.USER_INTERFACE, "160086")
         event = PanelVersionUpdate.decode(pkt)