Skip to content

Commit

Permalink
improve debug output if wrong sensor selected
Browse files Browse the repository at this point in the history
  • Loading branch information
mampfes committed Feb 11, 2024
1 parent 24bf452 commit f67b714
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion custom_components/epex_spot_sensor/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,13 @@ def _update_state_for_contigous(
)

def _get_marketdata(self):
marketdata = get_marketdata_from_sensor_attrs(self._sensor_attributes)
try:
marketdata = get_marketdata_from_sensor_attrs(self._sensor_attributes)
except KeyError as error:
_LOGGER.error(
f'Invalid price sensor "{self._entity_id}" selected for EPEX Spot Sensor "{self._attr_name}": {error}' # noqa:E501
)
return []

# now merge it with the cached info
marketdata = [*marketdata, *self._cached_marketdata]
Expand Down
7 changes: 3 additions & 4 deletions custom_components/epex_spot_sensor/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, entry):
self._price = x
self._price_uom = "pence/kWh"
else:
raise KeyError("No valid price field found. Check price sensor.")
raise KeyError("No valid price field found.")

def __repr__(self):
return f"{self.__class__.__name__}(start: {self._start_time.isoformat()}, end: {self._end_time.isoformat()}, marketprice: {self._price} {self._price_uom})" # noqa: E501
Expand All @@ -50,8 +50,7 @@ def get_marketdata_from_sensor_attrs(attributes):
"""Convert sensor attributes to market price list."""
try:
data = attributes["data"]
except (KeyError, TypeError):
_LOGGER.error("price sensor attributes invalid")
return []
except KeyError:
raise KeyError("'data' missing in sensor attributes")

return [Marketprice(e) for e in data]

0 comments on commit f67b714

Please sign in to comment.