diff --git a/config/pageSettings-example.json b/config/pageSettings-example.json index bb2e9b54d49e31aacd60781203a1e25cc2c466a5..d957d27e91bc6bb2245dbca3f78f531bff36bf23 100644 --- a/config/pageSettings-example.json +++ b/config/pageSettings-example.json @@ -18,7 +18,12 @@ "numberOfHoursToShow": 4, "decimals": 1, "lineColor": "rgba(254, 151, 0, 1)", - "fillColor": "rgba(254, 151, 0, 0.2)" + "fillColor": "rgba(254, 151, 0, 0.2)", + "showAxes": false, + "outdatedValueWarning": { + "enable": false, + "limitInSeconds": -1 + } }, "x": 0, "y": 0, diff --git a/src/logic/tile/tiles/SensorLineChartTile.html b/src/logic/tile/tiles/SensorLineChartTile.html index 4293a180b7421827e1a517730ab88b178c9105bb..eac8c468b65ee9b269ee43b720612c8f237baa78 100644 --- a/src/logic/tile/tiles/SensorLineChartTile.html +++ b/src/logic/tile/tiles/SensorLineChartTile.html @@ -95,10 +95,10 @@ <div class="value">{{ latest }}{{ unit }}</div> {% endif %} </div> - {% if timeAgo %} + {% if timeSinceLastValue %} <div class="warning"> <i class="material-icons icon-warning">warning</i> - <div class="warning-text">{{ timeAgo }}</div> + <div class="warning-text">{{ timeSinceLastValue }}</div> </div> {% endif %} <div class="header-right"> diff --git a/src/logic/tile/tiles/SensorLineChartTile.py b/src/logic/tile/tiles/SensorLineChartTile.py index 48e3005ac6e64682e0886a0fee97919c110bf23d..cef33154f260766689aef4a2831ed101c25ef278 100644 --- a/src/logic/tile/tiles/SensorLineChartTile.py +++ b/src/logic/tile/tiles/SensorLineChartTile.py @@ -32,7 +32,10 @@ class SensorLineChartTile(Tile): "lineColor": "rgba(254, 151, 0, 1)", "fillColor": "rgba(254, 151, 0, 0.2)", "showAxes": True, - "outdatedValueWarningLimitInSeconds": 300 # use -1 to disable warning + "outdatedValueWarning": { + "enable": False, + "limitInSeconds": 300 + } } UNIT_BY_SENSOR_TYPE = { @@ -176,13 +179,8 @@ class SensorLineChartTile(Tile): days = int(self._settings['numberOfHoursToShow'] / 24) title = f'{title} - {days} days' - now = datetime.now() - timeAgo = '' - outdatedValueWarningLimitInSeconds = self._settings['outdatedValueWarningLimitInSeconds'] - if outdatedValueWarningLimitInSeconds > 0: - timeDifference = now - data['latestTime'] - if timeDifference.total_seconds() > outdatedValueWarningLimitInSeconds: - timeAgo = format(timeDifference) + warningSettings = self._settings['outdatedValueWarning'] + timeSinceLastValue = self.__get_time_since_last_value(warningSettings, data) return Tile.render_template(os.path.dirname(__file__), __class__.__name__, x=data['x'], @@ -200,7 +198,24 @@ class SensorLineChartTile(Tile): ghostTraceX=data['ghostTraceX'], ghostTraceY=data['ghostTraceY'], showAxes=self._settings['showAxes'], - timeAgo=timeAgo) + timeSinceLastValue=timeSinceLastValue) + + def __get_time_since_last_value(self, warningSettings: Dict, data): + timeAgo = '' + + if not warningSettings['enable']: + return timeAgo + + now = datetime.now() + + limitInSeconds = warningSettings['limitInSeconds'] + + if limitInSeconds > 0: + timeDifference = now - data['latestTime'] + if timeDifference.total_seconds() > limitInSeconds: + timeAgo = format(timeDifference) + + return timeAgo def __format_date(self, dateTime: str): parsedDateTime = datetime.strptime(dateTime, self.DATE_FORMAT)