feat: read device identity from OCF /oic/p and /oic/d

This commit is contained in:
Marc Billow committed 2026-06-30 16:32:37 -05:00
1 parent 246379acbc
commit f2c1d8391e
2 files changed
+70

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
"""Read device identity from standard OCF resources (/oic/p, /oic/d)."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Optional
import cbor2
@dataclass(frozen=True)
class DeviceIdentity:
manufacturer: str
model: str
name: str
serial: Optional[str]
def _get(sess, path) -> dict:
try:
code, pl = sess.get(path, timeout=10.0)
if code == 0x45 and pl:
body = cbor2.loads(pl)
return body if isinstance(body, dict) else {}
except Exception:
pass
return {}
def read_identity(sess, serial: Optional[str]) -> DeviceIdentity:
p = _get(sess, ['oic', 'p'])
d = _get(sess, ['oic', 'd'])
return DeviceIdentity(
manufacturer=p.get('mnmn') or 'Samsung',
model=p.get('mnmo') or '',
name=d.get('n') or '',
serial=serial,
)