Skip to content

Commit

Permalink
Fixes missing error handling of bacpypes read
Browse files Browse the repository at this point in the history
  • Loading branch information
bmario committed Aug 27, 2024
1 parent d63d974 commit 1b20caa
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions metricq_source_bacpypes/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def metadata(self) -> JsonDict:
def property_parameter(self) -> tuple[ObjectIdentifier, PropertyIdentifier]:
return self._property_parameter

async def update(
async def send_update(
self,
timestamp: Timestamp,
response: list[tuple[ObjectIdentifier, PropertyIdentifier, int | None, Any]],
Expand Down Expand Up @@ -226,17 +226,27 @@ async def _update(
app: Application,
) -> None:
timestamp = Timestamp.now()
response = await app.read_property_multiple(
self.device.bacnet_address,
list(chain(*[metric.property_parameter for metric in self._metrics])),
)

try:
response = await app.read_property_multiple(
self.device.bacnet_address,
list(chain(*[metric.property_parameter for metric in self._metrics])),
)
except Exception as e:
logger.exception("Failed to read property: {}", e)
return

if response is None:
logger.error("Failed to read property. Result is None.")
return

duration = Timestamp.now() - timestamp
logger.debug(f"Request finished successfully in {duration}")

# TODO insert small sleep and see if that helps align stuff

await asyncio.gather(
*(metric.update(timestamp, response) for metric in self._metrics)
*(metric.send_update(timestamp, response) for metric in self._metrics)
)


Expand Down

0 comments on commit 1b20caa

Please sign in to comment.