mirror of
https://github.com/bourquep/mysa2mqtt.git
synced 2025-11-02 12:49:40 +00:00
feat: Expose device serial number and origin (#7)
This commit is contained in:
19
src/main.ts
19
src/main.ts
@@ -64,8 +64,24 @@ async function main() {
|
||||
await client.login(options.mysaUsername, options.mysaPassword);
|
||||
}
|
||||
|
||||
rootLogger.debug('Fetching devices and firmwares...');
|
||||
const [devices, firmwares] = await Promise.all([client.getDevices(), client.getDeviceFirmwares()]);
|
||||
|
||||
rootLogger.debug('Fetching serial numbers...');
|
||||
const serialNumbers = new Map<string, string>();
|
||||
for (const [deviceId] of Object.entries(devices.DevicesObj)) {
|
||||
try {
|
||||
const serial = await client.getDeviceSerialNumber(deviceId);
|
||||
if (serial) {
|
||||
serialNumbers.set(deviceId, serial);
|
||||
}
|
||||
} catch (error) {
|
||||
rootLogger.error(`Failed to retrieve serial number for device ${deviceId}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
rootLogger.debug('Initializing MQTT entities...');
|
||||
|
||||
const mqttSettings: MqttSettings = {
|
||||
host: options.mqttHost,
|
||||
port: options.mqttPort,
|
||||
@@ -82,7 +98,8 @@ async function main() {
|
||||
device,
|
||||
mqttSettings,
|
||||
new PinoLogger(rootLogger.child({ module: 'thermostat', deviceId: device.Id })),
|
||||
firmwares.Firmware[device.Id]
|
||||
firmwares.Firmware[device.Id],
|
||||
serialNumbers.get(device.Id)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user