1.3 KiB
1.3 KiB
Device Status LWT MAC Resolution Design
Goal
When a device publishes its MQTT last-will status on /MAC/publish/status, resolve the MAC address to the stored deviceNo before updating device status.
Design
- Keep
DeviceStatusHandlerresponsible for parsing status payloads and invoking status updates. - Reuse
DeviceIdentityResolverto translate the Topic identity into anAppDeviceand then itsdeviceNo. - The resolver first supports an existing
deviceNoTopic and falls back to a case-insensitivemac_addresslookup. This preserves compatibility while handling LWT Topics that contain a MAC address. - If no device matches the Topic identity, do not update any record; keep the existing warning log.
- Update the handler documentation to state that the Topic identity may be either a device number or a MAC address.
Verification
Add a focused unit test using the real DeviceIdentityResolver with a mocked AppDeviceMapper. The test publishes an offline status with a MAC identity and verifies that:
- The mapper looks up the MAC address.
MqttDeviceStatusService.markOfflinereceives the resolveddeviceNo.- No status update uses the MAC address as a device number.
Scope
This change only covers /MAC/publish/status. Other MQTT communication continues to use deviceNo according to the existing protocol.