FraunhoferIOSB / FROST-Python-Client

Python Client Library for FROST.
GNU Lesser General Public License v3.0
8 stars 8 forks source link

Error: Entity to JSON encoding with location=None #30

Open securedimensions opened 5 months ago

securedimensions commented 5 months ago

Is this a bug?

When creating a Thing with locations, the location property of the Location entity is not rendered into JSON.

Reproducing the error

1) clone the github 2) create the example as per this Github

from geojson import Point

import frost_sta_client as fsc

url = "http://localhost:8080/FROST-Server/v1.1"
service = fsc.SensorThingsService(url)
point = Point((-115.81, 37.24))
location = fsc.Location(name="here", description="and there", location=point, encoding_type='application/geo+json')

thing = fsc.Thing(name='new thing',
                  description='I am a thing with a location',
                  properties={'withLocation': True, 'owner': 'IOSB'})
thing.locations = [location]
service.create(thing)

3) The error In line json_dict = frost_sta_client.utils.transform_entity_to_json_dict(entity) (line 103 in base.py) renders the location entity grafik into JSON with location=None grafik

4) FROST-Server returns error Property location must be non-NULL grafik

uwzm commented 3 hours ago

Hello Andreas!

Thank you for your feedback.

In order to reproduce the problem we appended the line

print(fsc.utils.transform_entity_to_json_dict(thing))

to your example code and got the output

{'@iot.id': 32, 'Locations': [{'description': 'and there', 'encodingType': 'application/geo+json', 'location': {'coordinates': [-115.81, 37.24], 'type': 'Point'}, 'name': 'here'}], 'description': 'I am a thing with a location', 'name': 'new thing', 'properties': {'owner': 'IOSB', 'withLocation': True}}

Here, the point coordinates are included. Is this the situation you are referring to?

In case you query the server for the newly created thing, please keep in mind to include the expand command:

for th in service.things().query().filter("name eq 'new thing'").expand("Locations").list(): print("JSON: {}".format(fsc.utils.transform_entity_to_json_dict(th)))

If you have got any further questions, feel free to ask.