Skip to content

Commit

Permalink
Device get data returns bool
Browse files Browse the repository at this point in the history
  • Loading branch information
oscgonfer committed Oct 23, 2024
1 parent d8ce996 commit 7f17d43
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions smartcitizen_connector/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,19 @@ async def get_data(self,

logger.info(f'Make sure we are up to date')
self.__load__()

if self.json.state == 'never_published':
logger.warning('Device has never published anything, skipping')
return False

logger.info(f'Requesting data from SC API')
logger.info(f'Device ID: {self.id}')
rollup = convert_freq_to_rollup(frequency)
logger.info(f'Using rollup: {rollup}')

if self.timezone is None:
logger.warning('Device does not have timezone set, skipping')
return self.data
return False

# Check start date and end date
# Converting to UTC by passing None
Expand All @@ -292,12 +297,12 @@ async def get_data(self,
if min_date is not None and self.json.last_reading_at is not None:
if min_date > self.json.last_reading_at:
logger.warning(f'Device {self.id} request would yield empty data (min_date). Returning')
return self.data
return False

if max_date is not None and self.json.created_at is not None:
if max_date < self.json.created_at:
logger.warning(f'Device {self.id} request would yield empty data (max_date). Returning')
return self.data
return False

if max_date is not None and self.json.last_reading_at is not None:
if max_date > self.json.last_reading_at:
Expand All @@ -308,7 +313,7 @@ async def get_data(self,

if not self.json.data.sensors:
logger.info(f'Device {self.id} is empty')
return self.data
return False
else: logger.info(f"Sensor IDs: {[f'{sensor.name}: {sensor.id}' for sensor in self.json.data.sensors]}")

df = DataFrame()
Expand Down Expand Up @@ -349,7 +354,7 @@ async def get_data(self,
pass

logger.info(f'Device {self.id} loaded successfully from API')
return self.data
return True

async def post_data(self, columns = 'sensors', rename = None, clean_na = 'drop', chunk_size = 500, dry_run = False, max_retries = 2, delay = None):
'''
Expand Down

0 comments on commit 7f17d43

Please sign in to comment.