From ead561401aefe21b5a3c95279b431aecd59f5086 Mon Sep 17 00:00:00 2001 From: oscgonfer Date: Tue, 30 Apr 2024 11:03:00 +0200 Subject: [PATCH] Params for SCDevice and postprocessing --- smartcitizen_connector/device/device.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/smartcitizen_connector/device/device.py b/smartcitizen_connector/device/device.py index f10b53b..0bb868d 100644 --- a/smartcitizen_connector/device/device.py +++ b/smartcitizen_connector/device/device.py @@ -91,8 +91,14 @@ def check_postprocessing(postprocessing): class SCDevice: - def __init__(self, id, check_postprocessing=True): - self.id = id + def __init__(self, id = None, params = None, check_postprocessing=True): + if id is not None: + self.id = id + elif params is not None: + self.id = params.id + else: + raise ValueError("Need at least id or params.id") + self.params = params self.url = f'{config.DEVICES_URL}{self.id}' self.page = f'{config.FRONTEND_URL}{self.id}' self.method = 'async' @@ -573,10 +579,13 @@ def postprocessing(self): @property def latest_postprocessing(self): - return self.json.postprocessing.latest_postprocessing + if self.json.postprocessing is not None: + return self.json.postprocessing.latest_postprocessing + else: + return None def update_latest_postprocessing(self, date): - if self.json.postprocessing.id is not None: + if self.json.postprocessing is not None: # Add latest postprocessing rounded up with # frequency so that we don't end up in # and endless loop processing only the latest data line