Skip to content

Commit d48cbcc

Browse files
committed
substitute location attribute by list of locations
1 parent 90d2c01 commit d48cbcc

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

frost_sta_client/model/historical_location.py

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

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

@@ -55,15 +55,23 @@ def time(self, value):
5555
self._time = utils.check_datetime(value, 'time')
5656

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

61-
@location.setter
62-
def location(self, value):
63-
if value is None or isinstance(value, location.Location):
64-
self._location = value
61+
@locations.setter
62+
def locations(self, values):
63+
if values is None:
64+
self._locations = None
6565
return
66-
raise ValueError("location should be of type Location!")
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 not isinstance(values, entity_list.EntityList) or \
71+
any((not isinstance(loc, location.Location)) for loc in values.entities):
72+
raise ValueError('locations should be a list of locations')
73+
self._locations = values
74+
6775

6876
@property
6977
def thing(self):
@@ -112,9 +120,12 @@ def __setstate__(self, state):
112120
if state.get("Thing", None) is not None:
113121
self.thing = frost_sta_client.model.thing.Thing()
114122
self.thing.__setstate__(state["Thing"])
115-
if state.get("Location", None) is not None:
116-
self.thing = frost_sta_client.model.location.Location()
117-
self.thing.__setstate__(state["Location"])
123+
if state.get("Locations", None) is not None and isinstance(state["Locations"], list):
124+
entity_class = entity_type.EntityTypes['Location']['class']
125+
self.locations = utils.transform_json_to_entity_list(state['Locations'], entity_class)
126+
self.locations.next_link = state.get("Locations@iot.nextLink", None)
127+
self.locations.count = state.get("Locations@iot.count", None)
128+
118129

119130
def get_dao(self, service):
120131
return HistoricalLocationDao(service)

0 commit comments

Comments
 (0)