mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 01:31:05 +00:00
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:
@@ -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);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user