Skip to content

Commit f218179

Browse files
committed
docs: sketch usage of custom data model
1 parent 7d6035d commit f218179

1 file changed

Lines changed: 52 additions & 9 deletions

File tree

README.md

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,59 @@ module is set to demjson3 per default. The backend can be modified by calling
134134

135135
### OData Code Generation
136136

137-
Optionally, you can generate Python source code for the OData data model exposed by a FROST-Server (if the OData plugin is enabled).
137+
Since version 2.0.0 this client supports general OData models hosted by FROST servers with active OData plugin.
138138

139-
- The generator tries ODATA_4.01 first, then ODATA_4.0 ($metadata).
140-
- If no OData endpoint is available, the generator falls back to the provided metadata.xml (default data model) and generates code from it.
141-
142-
Usage:
139+
For this purpose the client provides a command line interface for generating a python module containing the URL of the FROST server in use as well as source code for the Python classes corresponding to the data model contained in it. It is called like this:
143140
```bash
144-
frost-codegen --url http://localhost:8080/FROST-Server --out frost_sta_client/generated/odata --module datamodel
141+
frost-codegen --url http://localhost:8080/FROST-Server --out my_datamodel
142+
```
143+
The generator tries the OData 4.01 endpoint of the FROST server in use first and falls back to the OData 4.0 if the other one is not available.
144+
145+
In order to use the custom data model it needs to be imported in the source code. The corresponding service needs to be created with paramter `model` instead of `url`. In fact, the following two programs are equivalent:
146+
```
147+
import frost_sta_client as fsc
148+
import .my_datamodel as my_model
149+
150+
service = fsc.SensorThingsService(model=my_model)
151+
152+
my_entity = my_model.MyEntityClass(...)
153+
service.create(my_entity)
154+
```
155+
156+
For backward compatibility, a client for a FROST server containing the SensorThings data model can be used as in previous versions of this client. In fact, the following two programs are equivalent in this case:
157+
158+
Variant I:
159+
```
160+
import frost_sta_client as fsc
161+
from geojson import Point
162+
163+
url = "http://localhost:8080/FROST-Server"
164+
service = fsc.SensorThingsService(url)
165+
166+
point = Point((-115.81, 37.24))
167+
location = fsc.Location(name="here", description="and there", location=point, encoding_type='application/geo+json')
168+
thing = fsc.Thing(name='new thing',
169+
description='I am a thing with a location',
170+
properties={'withLocation': True, 'owner': 'IOSB'})
171+
thing.locations = [location]
172+
service.create(thing)
173+
```
174+
175+
Variant II:
176+
```
177+
import frost_sta_client as fsc
178+
import .my_datamodel as my_model
179+
from geojson import Point
180+
181+
service = fsc.SensorThingsService(model=my_model)
182+
183+
point = Point((-115.81, 37.24))
184+
location = my_model.Location(name="here", description="and there", location=point, encoding_type='application/geo+json')
185+
thing = my_model.Thing(name='new thing',
186+
description='I am a thing with a location',
187+
properties={'withLocation': True, 'owner': 'IOSB'})
188+
thing.locations = [location]
189+
service.create(thing)
145190
```
146191

147-
Notes:
148-
- The generated code is not used automatically; import and use it as needed.
149-
- This feature is backward-compatible. If you wish to replace the hand-written model with generated code, point --out to frost_sta_client/model and adapt imports accordingly.
192+
However, variant II also works for data models different from SensorThings.

0 commit comments

Comments
 (0)