Skip to content

Commit

Permalink
Fix issue with null values in data
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Ware <[email protected]>
  • Loading branch information
Scott Ware committed Dec 21, 2024
1 parent d532375 commit bec8c2d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
33 changes: 18 additions & 15 deletions lib/glow_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,23 @@ def process_data(self, data):
if 'cumulative' in data['electricitymeter']['energy']['export']:
elec_exp = data['electricitymeter']['energy']['export']['cumulative']

if elec_exp > 0:
if self.cache:
self.elec_exp = elec_exp
else:
status["elec_exp"] = elec_exp
if elec_exp is not None:
if elec_exp > 0:
if self.cache:
self.elec_exp = elec_exp
else:
status["elec_exp"] = elec_exp

if 'import' in data['electricitymeter']['energy']:
if 'cumulative' in data['electricitymeter']['energy']['import']:
elec_imp = data['electricitymeter']['energy']['import']['cumulative']

if elec_imp > 0:
if self.cache:
self.elec_imp = elec_imp
else:
status["elec_imp"] = elec_imp
if elec_imp is not None:
if elec_imp > 0:
if self.cache:
self.elec_imp = elec_imp
else:
status["elec_imp"] = elec_imp

if 'power' in data['electricitymeter']:
if 'value' in data['electricitymeter']['power']:
Expand All @@ -70,11 +72,12 @@ def process_data(self, data):
if 'cumulative' in data['gasmeter']['energy']['import']:
gas_mtr = data['gasmeter']['energy']['import']['cumulative']

if gas_mtr > 0:
if self.cache:
self.gas_mtr = gas_mtr
else:
status["gas_mtr"] = gas_mtr
if gas_mtr is not None:
if gas_mtr > 0:
if self.cache:
self.gas_mtr = gas_mtr
else:
status["gas_mtr"] = gas_mtr

else:
if 'elecMtr' in data:
Expand Down
25 changes: 14 additions & 11 deletions lib/hass_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,33 @@ def process_data(self, data):
if 'cumulative' in data['electricitymeter']['energy']['export']:
elec_exp = data['electricitymeter']['energy']['export']['cumulative']

if elec_exp > 0:
electric_export = True
if elec_exp is not None:
if elec_exp > 0:
electric_export = True

if not self.electric_import and 'import' in data['electricitymeter']['energy']:
if 'cumulative' in data['electricitymeter']['energy']['import']:
elec_imp = data['electricitymeter']['energy']['import']['cumulative']

if elec_imp > 0:
electric_import = True
if elec_imp is not None:
if elec_imp > 0:
electric_import = True

if 'gasmeter' in data:
if 'energy' in data['gasmeter']:
if not self.gas_meter and 'import' in data['gasmeter']['energy']:
if 'cumulative' in data['gasmeter']['energy']['import']:
gas_mtr = data['gasmeter']['energy']['import']['cumulative']

if gas_mtr > 0:
gas_meter = True
gas_units = data['gasmeter']['energy']['import']['units']
if gas_mtr is not None:
if gas_mtr > 0:
gas_meter = True
gas_units = data['gasmeter']['energy']['import']['units']

if gas_units == "kWh":
gas_class = "energy"
else:
gas_class = "gas"
if gas_units == "kWh":
gas_class = "energy"
else:
gas_class = "gas"
else:
if 'elecMtr' in data:
if '0702' in data['elecMtr']:
Expand Down
30 changes: 30 additions & 0 deletions test/local_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@
}
}
}
},
{
"name": "gas_null",
"topic": "glow/A1234BC5DE67/SENSOR/gasmeter",
"payload": {
"gasmeter": {
"timestamp": "1970-01-01T00:00:00Z",
"energy": {
"import": {
"cumulative": null,
"day": null,
"week": null,
"month": null,
"units": "kWh",
"cumulativevol": null,
"cumulativevolunits": "",
"dayvol": null,
"weekvol": null,
"monthvol": null,
"dayweekmonthvolunits": "",
"mprn": "read pending",
"supplier": "---",
"price": {
"unitrate": null,
"standingcharge": null
}
}
}
}
}
}
]
}

0 comments on commit bec8c2d

Please sign in to comment.