@@ -23,6 +23,7 @@ def __init__(self, sensor_id, loop, session):
2323 self ._loop = loop
2424 self ._session = session
2525 self .sensor_id = sensor_id
26+ self .data = None
2627 self .values = {
2728 'humidity' : None ,
2829 'P1' : None ,
@@ -42,19 +43,19 @@ async def get_data(self):
4243
4344 _LOGGER .debug (
4445 "Response from luftdaten.info: %s" , response .status )
45- data = await response .json ()
46- _LOGGER .debug (data )
46+ self . data = await response .json ()
47+ _LOGGER .debug (self . data )
4748 except (asyncio .TimeoutError , aiohttp .ClientError ):
4849 _LOGGER .error ("Can not load data from luftdaten.info" )
4950 raise exceptions .LuftdatenConnectionError ()
5051
51- if not data :
52+ if not self . data :
5253 self .values = self .meta = None
5354 return
5455
5556 try :
5657 sensor_data = sorted (
57- data , key = lambda timestamp : timestamp ['timestamp' ],
58+ self . data , key = lambda timestamp : timestamp ['timestamp' ],
5859 reverse = True )[0 ]
5960
6061 for entry in sensor_data ['sensordatavalues' ]:
@@ -69,18 +70,6 @@ async def get_data(self):
6970 except (TypeError , IndexError ):
7071 raise exceptions .LuftdatenError ()
7172
72- async def validate_sensor (self , sensor_id ):
73+ async def validate_sensor (self ):
7374 """Return True if the sensor ID is valid."""
74- try :
75- with async_timeout .timeout (5 , loop = self ._loop ):
76- response = await self ._session .get (
77- '{}/{}/' .format (self .url , sensor_id ))
78-
79- _LOGGER .debug (
80- "Response from luftdaten.info: %s" , response .status )
81- data = await response .json ()
82- except (asyncio .TimeoutError , aiohttp .ClientError ):
83- _LOGGER .error ("Can not load data from luftdaten.info" )
84- raise exceptions .LuftdatenConnectionError ()
85-
86- return True if data else False
75+ return True if self .data else False
0 commit comments