Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: crash when using invtypemap and MIN inverter #568

Open
egguy opened this issue Jul 22, 2024 · 0 comments · May be fixed by #569
Open

BUG: crash when using invtypemap and MIN inverter #568

egguy opened this issue Jul 22, 2024 · 0 comments · May be fixed by #569

Comments

@egguy
Copy link
Contributor

egguy commented Jul 22, 2024

Hi, I maintain a grott add-on for HA and I have multiple user reporting a crash.

bug ref: egguy/addon-grott#32

It took me quite a while to understand the origin but after some users posted the back trace, I could reproduce it.

The problem

Randomly, the add-on stop working, as reported by multiple user. A user posted a stack trace:

File "/app/grottproxy.py", line 238, in on_recv
procdata(conf,data)
^^^^^^^^^^^^^^^^^^^
File "/app/grottdata.py", line 220, in procdata
for keyword in conf.recorddict[layout].keys() :
~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'T06NNNNMIN'

Minimal reproduction

Requirements

  • 1 data packet with a known serial inverter

grott.int

[Generic]
invtypemap = {"INVERTERSERIAL": "TES"}

Procedure

  1. Start grott with the ini
  2. Send the data packet.

The cause

When the invtypemap, grott compose the layout from the packet type: e.g T06NNNN then add the prefix found in the dict invtypemap.

There is a layout for T06NNNNXMIN which is the nominal case, but sporadically, the inverter sends a shorter packet.

In this case, the if ((ndata > 375) is false and the 'X' is not appended.

This generates a layout T06NNNNMIN, which doesn't exist (unlike the T06NNNNXMIN).

grottdata.py:220 trust blindly the layout will be present and crash grott.

A way to solve this is to check before doing conf.recorddict[layout] by using a if layout not in conf.recorddict

Patch

I made a quick patch which skips the layout parsing if the layout doesn't exist. I'm going to see If I can generate a MR

Index: grottdata.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/grottdata.py b/grottdata.py
--- a/grottdata.py	(revision f52ece051b17efd4a1f57fa8a3e0d6cfeca5adf5)
+++ b/grottdata.py	(date 1721649080279)
@@ -198,15 +198,19 @@
                     # Update the conf.layout like done earlier
                     conf.layout = layout
 
+        layout_exists = layout in conf.recorddict
+
         if conf.verbose: 
            print("\t - " + 'Growatt new layout processing')
            print("\t\t - " + "decrypt       : ",conf.decrypt)
            print("\t\t - " + "offset        : ", conf.offset)
            print("\t\t - " + "record layout : ", layout)
+           print("\t\t - " + "layout exists : ", layout_exists)
            print()
 
-        
-        
+        if not layout_exists:
+            return  # No valid layout found, no further processing
+
         try:
             #v270 try if logstart and log fields are defined, if yes prepare log fields 
             logstart = conf.recorddict[layout]["logstart"]["value"] 

Regards

@egguy egguy linked a pull request Jul 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant