Skip to content

Commit

Permalink
do not fail the sensor attribute when building an entity address (#457)
Browse files Browse the repository at this point in the history
* do not fail the sensor attribute when building an entity address fails. Do warn.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* changelog entry

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Jul 8, 2022
1 parent cc70d03 commit 16aa4bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -4,13 +4,13 @@ repos:
hooks:
- id: flake8
name: flake8 (code linting)
language_version: python3.8
language_version: python3.9
- repo: https://github.com/psf/black
rev: 22.3.0 # New version tags can be found here: https://github.com/psf/black/tags
hooks:
- id: black
name: black (code formatting)
language_version: python3.8
language_version: python3.9
- repo: local
hooks:
- id: mypy
Expand Down
2 changes: 2 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -12,11 +12,13 @@ New features

Bugfixes
-----------
* Do not fail asset page if entity addresses cannot be built [see `PR #457 <http://www.github.com/FlexMeasures/flexmeasures/pull/457>`_]

Infrastructure / Support
----------------------
* Allow access tokens to be passed as env vars as well [see `PR #443 <http://www.github.com/FlexMeasures/flexmeasures/pull/443>`_]


v0.10.1 | June XX, 2022
===========================

Expand Down
14 changes: 12 additions & 2 deletions flexmeasures/data/models/time_series.py
@@ -1,6 +1,7 @@
from typing import Any, List, Dict, Optional, Union, Type, Tuple
from datetime import datetime as datetime_type, timedelta
import json
from flask import current_app

import pandas as pd
from sqlalchemy.ext.declarative import declared_attr
Expand All @@ -24,7 +25,10 @@
collect_time_series_data,
aggregate_values,
)
from flexmeasures.utils.entity_address_utils import build_entity_address
from flexmeasures.utils.entity_address_utils import (
EntityAddressException,
build_entity_address,
)
from flexmeasures.utils.unit_utils import is_energy_unit, is_power_unit
from flexmeasures.data.models.annotations import (
Annotation,
Expand Down Expand Up @@ -112,7 +116,13 @@ def __acl__(self):

@property
def entity_address(self) -> str:
return build_entity_address(dict(sensor_id=self.id), "sensor")
try:
return build_entity_address(dict(sensor_id=self.id), "sensor")
except EntityAddressException as eae:
current_app.logger.warn(
f"Problems generating entity address for sensor {self}: {eae}"
)
return "no entity address available"

@property
def location(self) -> Optional[Tuple[float, float]]:
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/entity_address_utils.py
Expand Up @@ -325,7 +325,7 @@ def build_ea_scheme_and_naming_authority(
"FLEXMEASURES_HOSTS_AND_AUTH_START", {}
)[config_var_domain_key]
else:
raise Exception(
raise EntityAddressException(
f"Could not find out when authority for {config_var_domain_key} started. Is FLEXMEASURES_HOSTS_AND_AUTH_START configured for it?"
)
regex = r"^\d{4}-\d{2}$"
Expand Down

0 comments on commit 16aa4bd

Please sign in to comment.