From 505beff6dec82b9b79a3e6c2a9264a0ebf9205f5 Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Wed, 11 Oct 2023 20:01:10 +0200 Subject: [PATCH 1/3] Do not register non-existent inverter inputs in HA Fixes #8 --- app/src/infos.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/src/infos.py b/app/src/infos.py index 376f066..9e324d0 100644 --- a/app/src/infos.py +++ b/app/src/infos.py @@ -13,9 +13,9 @@ class Infos: 'controller':{ 'name':'Controller', 'mdl':0x00092f90, 'mf':0x000927c0, 'sw':0x00092ba8}, 'inverter': {'via':'controller', 'name':'Micro Inverter', 'mdl':0x00000032, 'mf':0x00000014, 'sw':0x0000001e}, 'input_pv1': {'via':'inverter', 'name':'Module PV1'}, - 'input_pv2': {'via':'inverter', 'name':'Module PV2'}, - 'input_pv3': {'via':'inverter', 'name':'Module PV3'}, - 'input_pv4': {'via':'inverter', 'name':'Module PV4'}, + 'input_pv2': {'via':'inverter', 'name':'Module PV2', 'dep':{'reg':0x00095b50, 'gte': 2}}, + 'input_pv3': {'via':'inverter', 'name':'Module PV3', 'dep':{'reg':0x00095b50, 'gte': 3}}, + 'input_pv4': {'via':'inverter', 'name':'Module PV4', 'dep':{'reg':0x00095b50, 'gte': 4}}, } __info_defs={ @@ -25,6 +25,7 @@ class Infos: 0x00092f90: {'name':['collector', 'Chip_Model'], 'level': logging.DEBUG, 'unit': ''}, 0x00095a88: {'name':['collector', 'Trace_URL'], 'level': logging.DEBUG, 'unit': ''}, 0x00095aec: {'name':['collector', 'Logger_URL'], 'level': logging.DEBUG, 'unit': ''}, + 0x00095b50: {'name':['collector', 'No_Inputs'], 'level': logging.DEBUG, 'unit': ''}, # inverter values used for device registration: 0x0000000a: {'name':['inverter', 'Product_Name'], 'level': logging.DEBUG, 'unit': ''}, @@ -112,7 +113,17 @@ class Infos: return None # unknwon idx, not in __info_defs - + def ignore_this_device(self, dep) -> bool: + if 'reg' in dep: + value = self.dev_value(dep['reg']) + if not value: return True + + if 'gte' in dep: + return not value >= dep['gte'] + elif 'less_eq' in dep: + return not value <= dep['less_eq'] + return True + def ha_confs(self, prfx="tsun/garagendach/", snr='123', sug_area =''): '''Generator function yields a json register struct for home-assistant auto configuration and a unique entity string @@ -159,6 +170,10 @@ class Infos: # attr['dev'] = {'name':'Microinverter','mdl':'MS-600','ids':[f'inverter_{snr}'],'mf':'TSUN','sa': 'auf Garagendach'} if 'dev' in ha: device = self.__info_devs[ha['dev']] + + if 'dep' in device and self.ignore_this_device(device['dep']): + continue + dev = {} # the same name fpr 'name' and 'suggested area', so we get dedicated devices in home assistant with short value name and headline From f0e9c67a065aa4ef762c453a216e40fa29373c8f Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Wed, 11 Oct 2023 20:22:33 +0200 Subject: [PATCH 2/3] fix issue #8 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed675c6..9478712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- fix issue [#8](https://github.com/s-allius/tsun-gen3-proxy/issues/8) + ## [0.3.0] - 2023-10-10 ❗Due to the definition of values for diagnostics, the MQTT devices of controller and inverter should be deleted in the Home Assistant before updating to version '0.3.0'. After the update, these are automatically created again. The measurement data is retained. From 8edbd7928fbae5cfd86bdab85b96190b28524d59 Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Wed, 11 Oct 2023 21:01:57 +0200 Subject: [PATCH 3/3] add docstring --- app/src/infos.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/infos.py b/app/src/infos.py index 9e324d0..69afcdd 100644 --- a/app/src/infos.py +++ b/app/src/infos.py @@ -113,7 +113,10 @@ class Infos: return None # unknwon idx, not in __info_defs - def ignore_this_device(self, dep) -> bool: + def ignore_this_device(self, dep:dict) -> bool: + '''Checks the equation in the dep dict + + returns 'False' only if the equation is valid; 'True' in any other case''' if 'reg' in dep: value = self.dev_value(dep['reg']) if not value: return True