Skip to content

Commit

Permalink
Fixed finally block issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
smartechru committed Feb 9, 2021
1 parent 077de87 commit 3433a08
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/n3rgy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def do_read_consumption(config_entry):
end = None # end date/time of the period in the format YYYYMMDDHHmm
live_env = DEFAULT_LIVE_ENVIRONMENT # live environment

# return value
data = None

# check the input data
if config_entry.data:
host = config_entry.data.get(CONF_HOST)
Expand Down Expand Up @@ -135,14 +138,12 @@ def do_read_consumption(config_entry):
# create n3rgy data api instance
api = N3rgyDataApi(host, api_key, property_id)
data = api.read_consumption(start, end)
return data

except ValueError as ex:
# error handling
_LOGGER.warning(f"Failed to initialize API: {str(ex)}")
finally:
_LOGGER.warning("Failed to read power consumption data")
return None
return data


class N3rgySensor(Entity):
Expand Down

0 comments on commit 3433a08

Please sign in to comment.