@@ -142,11 +142,11 @@ async def test_get_sensebox(self):
142142 assert sensebox .id == "621f53cdb527de001b06ad5e"
143143 assert len (sensebox .sensors ) == 11
144144
145- async def test_get_data_from_sensor (self ):
145+ async def test_get_sensor_measurements (self ):
146146 with aioresponses () as mocked_api :
147147 mocked_api .get (
148148 # pylint:disable=line-too-long
149- "https://api.opensensemap.org/boxes/621f53cdb527de001b06ad5e/data/621f53cdb527de001b06ad69?format=json&from-date=2023-12-15T08-00- 00.000000Z&to-date=2023-12-15T08-05- 00.000000Z" ,
149+ "https://api.opensensemap.org/boxes/621f53cdb527de001b06ad5e/data/621f53cdb527de001b06ad69?format=json&from-date=2023-12-15T08:00: 00.000000Z&to-date=2023-12-15T08:05: 00.000000Z" ,
150150 status = 200 ,
151151 payload = [
152152 {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:04:42.215Z" , "value" : "2.63" },
@@ -156,12 +156,98 @@ async def test_get_data_from_sensor(self):
156156 {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:00:36.615Z" , "value" : "2.68" },
157157 ],
158158 )
159-
160159 client = OpenSenseMapClient ()
161- measurements = await client .get_measurements (
160+ measurements = await client .get_sensor_measurements (
162161 "621f53cdb527de001b06ad5e" ,
163162 "621f53cdb527de001b06ad69" ,
164163 from_date = _berlin .localize (datetime (2023 , 12 , 15 , 9 , 0 , 0 , 0 )),
165164 to_date = _berlin .localize (datetime (2023 , 12 , 15 , 9 , 5 , 0 , 0 )),
166165 )
167166 assert len (measurements ) == 5
167+
168+ async def test_get_measurements_with_sensor_metadata (self ):
169+ with aioresponses () as mocked_api :
170+ mocked_api .get (
171+ "https://api.opensensemap.org/boxes/621f53cdb527de001b06ad5e" ,
172+ status = 200 ,
173+ payload = {
174+ "_id" : "621f53cdb527de001b06ad5e" ,
175+ "createdAt" : "2022-03-02T11:23:57.505Z" ,
176+ "updatedAt" : "2023-12-18T13:06:48.041Z" ,
177+ "name" : "CampusJahnallee" ,
178+ "currentLocation" : {
179+ "timestamp" : "2022-03-02T11:23:57.500Z" ,
180+ "coordinates" : [12.353332 , 51.340222 ],
181+ "type" : "Point" ,
182+ },
183+ "exposure" : "outdoor" ,
184+ "sensors" : [
185+ {
186+ "title" : "Temperatur" ,
187+ "unit" : "°C" ,
188+ "sensorType" : "HDC1080" ,
189+ "icon" : "osem-thermometer" ,
190+ "_id" : "621f53cdb527de001b06ad69" ,
191+ "lastMeasurement" : {"createdAt" : "2023-12-18T13:06:48.018Z" , "value" : "9.65" },
192+ },
193+ {
194+ "title" : "rel. Luftfeuchte" ,
195+ "unit" : "%" ,
196+ "sensorType" : "HDC1080" ,
197+ "icon" : "osem-humidity" ,
198+ "_id" : "621f53cdb527de001b06ad68" ,
199+ "lastMeasurement" : {"createdAt" : "2023-12-18T13:06:48.018Z" , "value" : "74.66" },
200+ },
201+ # other sensors omitted for brevity
202+ ],
203+ "model" : "homeV2EthernetFeinstaub" ,
204+ "lastMeasurementAt" : "2023-12-18T13:06:48.018Z" ,
205+ "description" : "SenseBox der GSD Sachunterricht unter besonderer Berücksichtigung von ..." ,
206+ "image" : "621f53cdb527de001b06ad5e_rrlwm9.jpg" ,
207+ "weblink" : "https://www.erzwiss.uni-leipzig.de/institut-fuer-paedagogik-und-didaktik-im-..." ,
208+ "loc" : [
209+ {
210+ "geometry" : {
211+ "timestamp" : "2022-03-02T11:23:57.500Z" ,
212+ "coordinates" : [12.353332 , 51.340222 ],
213+ "type" : "Point" ,
214+ },
215+ "type" : "Feature" ,
216+ }
217+ ],
218+ },
219+ )
220+ mocked_api .get (
221+ # pylint:disable=line-too-long
222+ "https://api.opensensemap.org/boxes/621f53cdb527de001b06ad5e/data/621f53cdb527de001b06ad69?format=json&from-date=2023-12-15T08:00:00.000000Z&to-date=2023-12-15T08:05:00.000000Z" ,
223+ status = 200 ,
224+ payload = [
225+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:04:42.215Z" , "value" : "2.63" },
226+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:03:40.855Z" , "value" : "2.61" },
227+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:02:39.403Z" , "value" : "2.61" },
228+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:01:37.957Z" , "value" : "2.63" },
229+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:00:36.615Z" , "value" : "2.68" },
230+ ],
231+ )
232+ mocked_api .get (
233+ # pylint:disable=line-too-long
234+ "https://api.opensensemap.org/boxes/621f53cdb527de001b06ad5e/data/621f53cdb527de001b06ad68?format=json&from-date=2023-12-15T08:00:00.000000Z&to-date=2023-12-15T08:05:00.000000Z" ,
235+ status = 200 ,
236+ payload = [
237+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:04:42.215Z" , "value" : "99.51" },
238+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:03:40.855Z" , "value" : "99.61" },
239+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:02:39.403Z" , "value" : "99.65" },
240+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:01:37.957Z" , "value" : "99.71" },
241+ {"location" : [12.353332 , 51.340222 ], "createdAt" : "2023-12-15T08:00:36.615Z" , "value" : "99.92" },
242+ ],
243+ )
244+ client = OpenSenseMapClient ()
245+ results = await client .get_measurements_with_sensor_metadata (
246+ "621f53cdb527de001b06ad5e" ,
247+ from_date = _berlin .localize (datetime (2023 , 12 , 15 , 9 , 0 , 0 , 0 )),
248+ to_date = _berlin .localize (datetime (2023 , 12 , 15 , 9 , 5 , 0 , 0 )),
249+ )
250+ assert len (results ) == 10
251+ # assert the correct sensors are associated with their respective data
252+ assert all (3 > float (x .value ) > 2 for x in results if x .unit == "°C" )
253+ assert all (100 > float (x .value ) > 99 for x in results if x .unit == "%" )
0 commit comments