From 94df6ac59b12c5b4cd3338fbc38d2359c82aa593 Mon Sep 17 00:00:00 2001 From: Addie Janssen <55428983+addiejanssen@users.noreply.github.com> Date: Fri, 9 Oct 2020 16:07:21 +0200 Subject: [PATCH] Update plugin.py Make sure for lookup values, that the key exists in the lookup table. --- plugin.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index b2258b8..eed5551 100644 --- a/plugin.py +++ b/plugin.py @@ -6,11 +6,10 @@ # Source: https://github.com/addiejanssen/domoticz-solaredge-modbustcp-plugin # Author: Addie Janssen (https://addiejanssen.com) # License: MIT -# Version: 1.0.0 # """ - + @@ -331,8 +330,14 @@ class BasePlugin: if unit[Column.LOOKUP]: Domoticz.Debug("-> looking up...") - lookup = unit[Column.LOOKUP] - value = lookup[inverter_values[unit[Column.MODBUSNAME]]] + + lookup_table = unit[Column.LOOKUP] + to_lookup = inverter_values[unit[Column.MODBUSNAME]] + + if to_lookup in lookup_table: + value = lookup_table[to_lookup] + else: + value = "Key not found in lookup table: {}".format(to_lookup) # When a math object is setup for the unit, update the samples in it and get the calculated value.