Refactor: separate models.Device method for device JSON obj
This commit is contained in:
parent
e9ac3d291d
commit
29d49dfeb2
1 changed files with 16 additions and 6 deletions
22
models.py
22
models.py
|
@ -93,13 +93,23 @@ class Device:
|
||||||
'''Generate a JSON format request body'''
|
'''Generate a JSON format request body'''
|
||||||
|
|
||||||
obj = {
|
obj = {
|
||||||
'devices': [{
|
'devices': [
|
||||||
'mac': self.mac,
|
self._json_device_obj(),
|
||||||
'sensors': [],
|
]
|
||||||
}]
|
}
|
||||||
|
|
||||||
|
return json.dumps(obj)
|
||||||
|
|
||||||
|
def _json_device_obj(self) -> dict[str, Any]:
|
||||||
|
'''Create a device JSON object for json_req_data().
|
||||||
|
Moved to a separate function to allow performing tests
|
||||||
|
with multiple devices in a request at once.'''
|
||||||
|
|
||||||
|
dev = {
|
||||||
|
'mac': self.mac,
|
||||||
|
'sensors': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = obj['devices'][0]
|
|
||||||
if self.name is not None:
|
if self.name is not None:
|
||||||
dev['name'] = self.name
|
dev['name'] = self.name
|
||||||
if self.owner is not None:
|
if self.owner is not None:
|
||||||
|
@ -121,4 +131,4 @@ class Device:
|
||||||
sobj['name'] = s.name
|
sobj['name'] = s.name
|
||||||
sl.append(sobj)
|
sl.append(sobj)
|
||||||
|
|
||||||
return json.dumps(obj)
|
return dev
|
||||||
|
|
Loading…
Add table
Reference in a new issue