feat: add typed data and views with scoped device power

This commit is contained in:
Codex
2026-10-25 14:35:24 +08:00
parent 5b99a7e9fc
commit ca60398dea
65 changed files with 4238 additions and 231 deletions
+16 -1
View File
@@ -25,6 +25,15 @@ class Inventory:
def display(self, item):
result = dict(item)
result['powerManaged'] = self.a.POWER.managed(item)
if self.a.get_object('devices',item['id']):
result.update(self.a.TYPES.instance(item))
if result['fbType']=='computer.power.v1':
state=self.a.POWER.power(item['id'])
result['dataInstance']['values'].update(RUN=None if state['run'] is None else bool(state['run']),
OP=state['op'],BUSY=bool(state['op']),RESULT=(state['last'] or {}).get('result',''))
result['dataInstance']['checkedAt']=state['checkedAt']
result['dataInstance']['quality']=state['state']
for prefix in ('owner', 'manager'):
ref = item.get(prefix+'Ref', '')
kind, _, key = ref.partition(':')
@@ -95,7 +104,7 @@ class Inventory:
if item['deviceType'] in ('摄像头', '摄像机', '录像机'):
raise a.Problem('视频设备请使用摄像机或录像机档案,以保留取流与通道配置')
item.update(id=key, familyId=family, siteId=a.clean_text(data.get('siteId', ''), 32),
**self.metadata(data, old, user))
**self.metadata(data, old, user), **a.TYPES.preserve(data, old, user))
a.save_object('devices', item)
a.audit('保存设备档案', item['name'])
return item
@@ -133,6 +142,12 @@ class Inventory:
child['uplinkId']=''
a.DB.execute('UPDATE '+other_table+' SET body=? WHERE id=?',(json.dumps(child),child['id']))
a.DB.execute('UPDATE household_displays SET revoked=1 WHERE device_id=?',(item['id'],))
# Views are household-owned presentations, not portable device data.
# Remove the old household's bindings atomically with the transfer.
if table == 'devices':
for view in a.objects('device_views'):
if view.get('familyId') == old_family and view.get('dataInstanceId',view.get('deviceId')) == item['id']:
a.DB.execute('DELETE FROM device_views WHERE id=?',(view['id'],))
a.audit('转移设备家庭',item['name']+':'+old_family+' → '+target['name'])
if channels: a.write_media_config()
return {'ok':True,'id':item['id'],'familyId':target['id']}