Skip to content

Commit 06702ab

Browse files
committed
update set state methods
1 parent 5492020 commit 06702ab

4 files changed

Lines changed: 18 additions & 31 deletions

File tree

frost_sta_client/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = 'frost_sta_client'
2-
__version__ = '1.1.28'
2+
__version__ = '1.1.29'
33
__license__ = 'LGPL3'
44
__author__ = 'Katharina Emde'
55
__copyright__ = 'Fraunhofer IOSB'

frost_sta_client/model/datastream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ def __setstate__(self, state):
334334
if state.get("Sensor", None) is not None:
335335
self.sensor = frost_sta_client.model.sensor.Sensor()
336336
self.sensor.__setstate__(state["Sensor"])
337-
if state.get("Observations", None) is not None and isinstance(state["Observations"], list):
337+
if state.get("Observations", None) is not None and type(state["Observations"] == str):
338338
entity_class = entity_type.EntityTypes['Observation']['class']
339-
self.observations = utils.transform_json_to_entity_list(state['Observations'], entity_class)
339+
self.observations = utils.transform_related_json_to_entity_list(state['Observations'], entity_class)
340340
self.observations.next_link = state.get("Observations@iot.nextLink", None)
341341
self.observations.count = state.get("Observations@iot.count", None)
342342

frost_sta_client/model/historical_location.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@
2929
class HistoricalLocation(entity.Entity):
3030

3131
def __init__(self,
32-
locations=None,
32+
location=None,
3333
time=None,
3434
thing=None,
3535
**kwargs):
3636
super().__init__(**kwargs)
37-
self.locations = locations
37+
self.location = location
3838
self.time = time
3939
self.thing = thing
4040

4141
def __new__(cls, *args, **kwargs):
4242
new_h_loc = super().__new__(cls)
43-
attributes = {'_id': None, '_locations': None, '_time': None, '_thing': None, '_self_link': None,
43+
attributes = {'_id': None, '_location': None, '_time': None, '_thing': None, '_self_link': None,
4444
'_service': None}
4545
for key, value in attributes.items():
4646
new_h_loc.__dict__[key] = value
@@ -55,23 +55,15 @@ def time(self, value):
5555
self._time = utils.check_datetime(value, 'time')
5656

5757
@property
58-
def locations(self):
59-
return self._locations
58+
def location(self):
59+
return self._location
6060

61-
@locations.setter
62-
def locations(self, values):
63-
if values is None:
64-
self._locations = None
61+
@location.setter
62+
def location(self, value):
63+
if value is None or isinstance(value, location.Location):
64+
self._location = value
6565
return
66-
if isinstance(values, list) and all(isinstance(loc, location.Location) for loc in values):
67-
entity_class = entity_type.EntityTypes['Location']['class']
68-
self._locations = entity_list.EntityList(entity_class=entity_class, entities=values)
69-
return
70-
if isinstance(values, entity_list.EntityList) and\
71-
all((isinstance(loc, location.Location)) for loc in values.entities):
72-
self._locations = values
73-
return
74-
raise ValueError('locations should be a list of locations!')
66+
raise ValueError("location should be of type Location!")
7567

7668
@property
7769
def thing(self):
@@ -84,11 +76,6 @@ def thing(self, value):
8476
return
8577
raise ValueError('thing should be of type Thing!')
8678

87-
def get_locations(self):
88-
result = self.service.locations()
89-
result.parent = self
90-
return result
91-
9279
def ensure_service_on_children(self, service):
9380
if self.locations is not None:
9481
self.locations.set_service(service)
@@ -127,11 +114,9 @@ def __setstate__(self, state):
127114
if state.get("Thing", None) is not None:
128115
self.thing = frost_sta_client.model.thing.Thing()
129116
self.thing.__setstate__(state["Thing"])
130-
if state.get("Locations", None) is not None and isinstance(state["Locations"], list):
131-
entity_class = entity_type.EntityTypes['Location']['class']
132-
self.locations = utils.transform_json_to_entity_list(state['Locations'], entity_class)
133-
self.locations.next_link = state.get('Locations@iot.nextLink', None)
134-
self.locations.count = state.get('Locations@iot.count', None)
117+
if state.get("Location", None) is not None:
118+
self.thing = frost_sta_client.model.location.Location()
119+
self.thing.__setstate__(state["Location"])
135120

136121
def get_dao(self, service):
137122
return HistoricalLocationDao(service)

frost_sta_client/model/thing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@ def __setstate__(self, state):
274274
entity_class = entity_type.EntityTypes['Location']['class']
275275
self.locations = utils.transform_json_to_entity_list(state['Locations'], entity_class)
276276
self.locations.next_link = state.get("Locations@iot.nextLink", None)
277+
self.locations.count = state.get("Locations@iot.count", None)
277278
if state.get("HistoricalLocations", None) is not None and isinstance(state["HistoricalLocations"], list):
278279
entity_class = entity_type.EntityTypes['HistoricalLocation']['class']
279280
self.historical_locations = utils.transform_json_to_entity_list(state['HistoricalLocations'], entity_class)
280281
self.historical_locations.next_link = state.get("HistoricalLocations@iot.nextLink", None)
282+
self.historical_locations.count = state.get("HistoricalLocations@iot.count", None)
281283
if state.get("Datastreams", None) is not None and isinstance(state["Datastreams"], list):
282284
entity_class = entity_type.EntityTypes['Datastream']['class']
283285
self.datastreams = utils.transform_json_to_entity_list(state['Datastreams'], entity_class)

0 commit comments

Comments
 (0)