Skip to content

Commit 69b82ed

Browse files
committed
Check if station is valid
1 parent b47f397 commit 69b82ed

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ async def main():
1616
data = Luftdaten(155, loop, session)
1717
await data.get_data()
1818

19+
if not data.valid_sensor:
20+
print("Station is not available:", data.sensor_id)
21+
return
22+
1923
if data.values and data.meta:
2024
# Print the sensor values
2125
print("Sensor values:", data.values)
2226

2327
# Print the coordinates fo the sensor
2428
print("Location:", data.meta['latitude'], data.meta['longitude'])
25-
else:
26-
print("Station is not available:", data.sensor_id)
2729

2830

2931
loop = asyncio.get_event_loop()

luftdaten/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ async def get_data(self):
6868
self.meta['latitude'] = float(sensor_data['location']['latitude'])
6969
except (TypeError, IndexError):
7070
raise exceptions.LuftdatenError()
71+
72+
@property
73+
def valid_sensor(self):
74+
"""Return True if the sensor ID is valid."""
75+
return True if self.values else False

0 commit comments

Comments
 (0)