trace + backup propertie

This commit is contained in:
Kevin L'Hereec committed 2026-06-01 16:20:58 +02:00
1 parent b3b1edec17
commit ea73e91aa4
8 files changed
+164 -37

No files matched your search

+29
View File
@@ -1,5 +1,7 @@
import { createRequire } from 'node:module'
import type { DeviceSnapshot } from '../domain/device/device.js'
import type { Device } from '../domain/device/device.js'
import { DeviceParameter } from '../domain/device/device_parameter.js'
const require = createRequire(import.meta.url)
const tr181Catalog: Array<{ path: string; writable: boolean; deviceClass: string }> =
@@ -7,6 +9,9 @@ const tr181Catalog: Array<{ path: string; writable: boolean; deviceClass: string
// Index chargé une fois au démarrage — O(1) lookup
const catalogIndex = new Map(tr181Catalog.map((e) => [e.path, e.writable]))
const catalogWritableIndex = new Set(
tr181Catalog.filter((e) => e.writable).map((e) => e.path)
)
/** Remplace les segments numériques par {i} pour matcher les entrées du catalogue */
export function normalizePath(path: string): string {
@@ -46,3 +51,27 @@ export function resolveWritability(snapshot: DeviceSnapshot, paramPath: string):
if (gpnStatus === 'unsupported') return { writable: true, source: 'default' }
return { writable: null, source: 'unknown' }
}
/**
* Reclassify device properties as parameters using the TR-181 catalog.
* Properties that are writable per the catalog are moved to parameters.
* Should be called after updateFromValues when gpnStatus is 'unsupported'.
*/
export function reclassifyDeviceFromCatalog(device: Device): number {
const properties = device.getProperties()
let reclassified = 0
for (const prop of properties) {
const normalized = normalizePath(prop.name)
if (catalogWritableIndex.has(normalized)) {
const snap = prop.toSnapshot()
device.setParameter(
new DeviceParameter(snap.name, snap.value, snap.type, snap.createdAt, snap.updatedAt, snap.notification, snap.accessList)
)
;(device as any)._properties.delete(prop.name)
reclassified++
}
}
return reclassified
}