add json_wb in snapshot

This commit is contained in:
Cayo Puigdefabregas 2023-01-23 19:44:36 +01:00
parent 45a787aa39
commit e7e595f2c2
4 changed files with 17 additions and 7 deletions

View file

@ -305,6 +305,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
devices = [] devices = []
self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
for filename, snapshot_json in self.snapshots: for filename, snapshot_json in self.snapshots:
self.json_wb = copy.copy(snapshot_json)
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
debug = snapshot_json.pop('debug', None) debug = snapshot_json.pop('debug', None)
self.version = snapshot_json.get('schema_api') self.version = snapshot_json.get('schema_api')

View file

@ -699,6 +699,12 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice):
return return
json_hw = {} json_hw = {}
json_wb = copy.copy(json_wb)
if json_wb.get('device', {}).get('system_uuid'):
system_uuid = str(json_wb['device']['system_uuid'])
json_wb['device']['system_uuid'] = system_uuid
for k, v in json_wb.items(): for k, v in json_wb.items():
if k == 'device': if k == 'device':
json_hw['device'] = copy.copy(v) json_hw['device'] = copy.copy(v)
@ -755,8 +761,10 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice):
return snapshots and 'update' or 'new_device' return snapshots and 'update' or 'new_device'
def register_passport_dlt(self): def register_passport_dlt(self):
import pdb; pdb.set_trace() import pdb
if 'trublo' not in app.blueprints.keys() or not self.hid:
pdb.set_trace()
if 'trublo' not in app.blueprints.keys() or not self.device.hid:
return return
if not session.get('token_dlt'): if not session.get('token_dlt'):

View file

@ -1,5 +1,6 @@
""" This is the view for Snapshots """ """ This is the view for Snapshots """
import copy
import json import json
import os import os
import shutil import shutil
@ -121,6 +122,7 @@ class SnapshotMixin:
snapshot.device.set_hid() snapshot.device.set_hid()
snapshot.device.binding.device.set_hid() snapshot.device.binding.device.set_hid()
snapshot.create_json_hw(self.json_wb)
snapshot.device.register_dlt() snapshot.device.register_dlt()
snapshot.register_passport_dlt() snapshot.register_passport_dlt()
@ -214,6 +216,7 @@ class SnapshotView(SnapshotMixin):
self.schema = schema self.schema = schema
self.resource_def = resource_def self.resource_def = resource_def
self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
self.json_wb = copy.copy(snapshot_json)
self.path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) self.path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
self.version = snapshot_json.get('version') self.version = snapshot_json.get('version')
self.uuid = snapshot_json.get('uuid') self.uuid = snapshot_json.get('uuid')

View file

@ -777,10 +777,6 @@ class Device(Thing):
).first() ).first()
def set_hid(self): def set_hid(self):
with suppress(TypeError):
self.hid = Naming.hid(
self.type, self.manufacturer, self.model, self.serial_number
)
if 'property_hid' in app.blueprints.keys(): if 'property_hid' in app.blueprints.keys():
try: try:
from modules.device.utils import set_hid from modules.device.utils import set_hid
@ -887,7 +883,9 @@ class Device(Thing):
return types.get(self.type, '') return types.get(self.type, '')
def register_dlt(self): def register_dlt(self):
import pdb; pdb.set_trace() import pdb
pdb.set_trace()
if 'trublo' not in app.blueprints.keys() or not self.hid: if 'trublo' not in app.blueprints.keys() or not self.hid:
return return