config: tolerate devices with no unitId

This commit is contained in:
Peter F. Patel-Schneider 2025-12-16 15:17:38 -05:00
parent 40dcaadec7
commit 42e0e391b5
1 changed files with 12 additions and 4 deletions

View File

@ -231,8 +231,16 @@ yaml.add_representer(NamedInt, named_int_representer)
# So new entries are not created for unseen off-line receiver-connected devices # So new entries are not created for unseen off-line receiver-connected devices
def persister(device): def persister(device):
def match(wpid, serial, modelId, unitId, c): def match(wpid, serial, modelId, unitId, c):
return (wpid and wpid == c.get(_KEY_WPID) and serial and serial == c.get(_KEY_SERIAL)) or ( return (
modelId and modelId == c.get(_KEY_MODEL_ID) and unitId and unitId == c.get(_KEY_UNIT_ID) (wpid and wpid == c.get(_KEY_WPID) and serial and serial == c.get(_KEY_SERIAL))
or (modelId and modelId == c.get(_KEY_MODEL_ID) and unitId and unitId == c.get(_KEY_UNIT_ID))
or (
c.get(_KEY_WPID) is None
and c.get(_KEY_SERIAL) is None
and c.get(_KEY_UNIT_ID) is None
and modelId
and modelId == c.get(_KEY_MODEL_ID)
)
) )
with configuration_lock: with configuration_lock:
@ -240,8 +248,8 @@ def persister(device):
_load() _load()
entry = None entry = None
# some devices report modelId and unitId as zero so use name and serial for them # some devices report modelId and unitId as zero so use name and serial for them
modelId = device.modelId if device.modelId != "000000000000" else device._name if device.modelId else None modelId = device.modelId if device.modelId != "000000000000" else device._name if device._name else None
unitId = device.unitId if device.modelId != "000000000000" else device._serial if device.unitId else None unitId = device.unitId if device.unitId != "00000000" else device._serial if device._serial else None
for c in _config: for c in _config:
if isinstance(c, _DeviceEntry) and match(device.wpid, device._serial, modelId, unitId, c): if isinstance(c, _DeviceEntry) and match(device.wpid, device._serial, modelId, unitId, c):
entry = c entry = c