Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fig bug: broken (dev) CLI command for adding a Sensor #176

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -24,6 +24,7 @@ New features
Bugfixes
-----------
* Fix (dev) CLI command for adding a GenericAssetType [see `PR #173 <http://www.github.com/SeitaBV/flexmeasures/pull/173>`_]
* Fix (dev) CLI command for adding a Sensor [see `PR #176 <http://www.github.com/SeitaBV/flexmeasures/pull/176>`_]

Infrastructure / Support
----------------------
Expand Down
16 changes: 14 additions & 2 deletions flexmeasures/data/models/time_series.py
Expand Up @@ -39,10 +39,22 @@ class Sensor(db.Model, tb.SensorDBMixin):
),
)

def __init__(self, name: str, generic_asset: GenericAsset, **kwargs):
def __init__(
self,
name: str,
generic_asset: Optional[GenericAsset] = None,
generic_asset_id: Optional[int] = None,
**kwargs,
):
assert (generic_asset is None) ^ (
generic_asset_id is None
), "Either generic_asset_id or generic_asset must be set."
tb.SensorDBMixin.__init__(self, name, **kwargs)
tb_utils.remove_class_init_kwargs(tb.SensorDBMixin, kwargs)
kwargs["generic_asset"] = generic_asset
if generic_asset is not None:
kwargs["generic_asset"] = generic_asset
else:
kwargs["generic_asset_id"] = generic_asset_id
db.Model.__init__(self, **kwargs)

@property
Expand Down