Skip to content

Commit

Permalink
Fix exception when accessing header data
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Aug 17, 2021
1 parent b9860da commit 4d57873
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pyfronius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,24 @@ async def _current_data(self, fun, spec, spec_name, *spec_formattings):
"Device type {} not supported by the fronius device".format(spec_name)
)

# no error should be thrown here, ever
sensor.update(Fronius._status_data(res))
try:
sensor.update(Fronius._status_data(res))
except (TypeError, KeyError):
# break if Data is empty
_LOGGER.info(
"No header data returned from {} ({})".format(spec, spec_formattings)
)
try:
# TODO use update here as well
sensor = fun(sensor, res["Body"]["Data"])
fun(sensor, res["Body"]["Data"])
except (TypeError, KeyError):
# LoggerInfo oddly deviates from the default scheme
try:
sensor = fun(sensor, res["Body"]["LoggerInfo"])
fun(sensor, res["Body"]["LoggerInfo"])
except (TypeError, KeyError):
# break if Data is empty
_LOGGER.info(
"No data returned from {} ({})".format(spec, spec_formattings)
"No body data returned from {} ({})".format(spec, spec_formattings)
)
return sensor

Expand Down

0 comments on commit 4d57873

Please sign in to comment.