fix!: Device and state properties are now optional (#170)

Updated DeviceBase, BrandInfo, and DeviceState interfaces to make most properties optional, improving flexibility for partial objects and better handling of missing data.
This commit is contained in:
Pascal Bourque
2025-11-01 09:33:31 -04:00
committed by GitHub
parent 7b332b1416
commit d861a50136
3 changed files with 53 additions and 50 deletions

View File

@@ -65,9 +65,10 @@ async function main() {
client.emitter.on('statusChanged', (status) => {
try {
const device = devices.DevicesObj[status.deviceId];
const watts = status.current !== undefined ? status.current * device.Voltage : undefined;
const watts =
status.current !== undefined && device.Voltage !== undefined ? status.current * device.Voltage : undefined;
rootLogger.info(
`[${status.deviceId}] '${device.Name}' status changed: ${status.temperature}°C, ${status.humidity}%, ${watts ?? 'na'}W`
`[${status.deviceId}] '${device.Name ?? 'Unknown'}' status changed: ${status.temperature}°C, ${status.humidity}%, ${watts ?? 'na'}W`
);
} catch (error) {
rootLogger.error(error, `Error processing status update for device '${status.deviceId}'`);
@@ -77,7 +78,9 @@ async function main() {
client.emitter.on('setPointChanged', (change) => {
try {
const device = devices.DevicesObj[change.deviceId];
rootLogger.info(`'${device.Name}' setpoint changed from ${change.previousSetPoint} to ${change.newSetPoint}`);
rootLogger.info(
`'${device.Name ?? 'Unknown'}' setpoint changed from ${change.previousSetPoint} to ${change.newSetPoint}`
);
} catch (error) {
rootLogger.error(error, `Error processing setpoint update for device '${change.deviceId}'`);
}
@@ -86,7 +89,7 @@ async function main() {
client.emitter.on('stateChanged', (change) => {
try {
const device = devices.DevicesObj[change.deviceId];
rootLogger.info(change, `'${device.Name}' state changed.`);
rootLogger.info(change, `'${device.Name ?? 'Unknown'}' state changed.`);
} catch (error) {
rootLogger.error(error, `Error processing state update for device '${change.deviceId}'`);
}
@@ -96,7 +99,7 @@ async function main() {
await Promise.all(
Object.entries(devices.DevicesObj).map(async ([deviceId, device]) => {
const serial = await client.getDeviceSerialNumber(deviceId);
rootLogger.info(`Serial number for device '${deviceId}' (${device.Name}): ${serial}`);
rootLogger.info(`Serial number for device '${deviceId}' (${device.Name ?? 'Unknown'}): ${serial}`);
await client.startRealtimeUpdates(deviceId);
})