Skip to content

Commit

Permalink
smartmeter: error handling for item creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Dec 16, 2024
1 parent 1bb135c commit f6905c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions smartmeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@ def create_items(self, data: dict = {}, file: str = '') -> bool:
data = self.obis_results

try:
id = data['1-0:96.1.0*255']['value']
except (IndexError, AttributeError):
id = int(time.time())
id = data['1-0:96.1.0*255'][0]['value']
except (KeyError, IndexError, AttributeError):
try:
id = data['1-0:0.0.9*255'][0]['value']
except (KeyError, IndexError, AttributeError):
id = int(time.time())

if not file:
dir = self._sh._items_dir
Expand All @@ -209,7 +212,9 @@ def create_items(self, data: dict = {}, file: str = '') -> bool:
result = {}
for nr, code in enumerate(data):
item = f'item_{nr}'
d = data[code]
if len(data[code]) == 0:
continue
d = data[code][0]
name = d.get('name', '')
unit = d.get('unit')
if isinstance(d['value'], str):
Expand Down
2 changes: 1 addition & 1 deletion smartmeter/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugin:
version: '0.0.1' # Plugin version
sh_minversion: '1.10' # minimum shNG version to use this plugin
py_minversion: '3.9' # minimum Python version to use for this plugin, due to f-strings
type: gateway # plugin type (gateway, interface, protocol, system, web)
type: interface # plugin type (gateway, interface, protocol, system, web)
description:
de: 'Unterstützung für Smartmeter, die DLMS (Device Language Message Specification, IEC 62056-21) oder SML (Smart Message Language) nutzen und OBIS Codes liefern'
en: 'Support for smartmeter using DLMS (Device Language Message Specification, IEC 62056-21) or SML (Smart Message Language) and delivering OBIS codes'
Expand Down

0 comments on commit f6905c1

Please sign in to comment.