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

feat: in play mode, allow showing any sensor on the asset page #740

Merged
merged 10 commits into from Aug 1, 2023
1 change: 1 addition & 0 deletions documentation/host/modes.rst
Expand Up @@ -39,3 +39,4 @@ Small features
- [API] Posted UDI events are not enforced to be consecutive.
- [API] Names in ``GetConnectionResponse`` are the connections' unique database names rather than their display names (this feature is planned to be deprecated).
- [UI] The dashboard plot showing the latest power value is not enforced to lie in the past (in case of simulating future values).
- [UI] On the asset page, the ``sensors_to_show`` attribute can be used to show any sensor from any account, rather than only sensors from assets owned by the user's organization.
12 changes: 11 additions & 1 deletion flexmeasures/data/models/generic_assets.py
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Dict, Optional, Tuple, List, Union
import json

from flask import current_app
from flask_security import current_user
import pandas as pd
from sqlalchemy.engine import Row
Expand Down Expand Up @@ -453,13 +454,22 @@ def sensors_to_show(self) -> list["Sensor" | list["Sensor"]]: # noqa F821
if not self.has_attribute("sensors_to_show"):
return self.sensors[:2]

# Only allow showing sensors from assets owned by the user's organization,
# except in play mode, where any sensor may be shown
if current_app.get("FLEXMEASURES_MODE") != "play":
account = self.owner
else:
from flexmeasures.data.models.user import Account

account = Account.query.all()

from flexmeasures.data.services.sensors import get_sensors

sensor_ids_to_show = self.get_attribute("sensors_to_show")
sensor_map = {
sensor.id: sensor
for sensor in get_sensors(
account=self.owner,
account=account,
include_public_assets=True,
sensor_id_allowlist=flatten_unique(sensor_ids_to_show),
)
Expand Down