diff --git a/README.md b/README.md index bcc9e28..919ca3b 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ Then, run the example: npm run example ``` +If you prefer to see the raw data published by your Mysa smart thermostats, run: + +```bash +npm run example:raw +``` + ## Using The Mysa SDK provides a simple interface to interact with Mysa smart thermostats. diff --git a/example/main.ts b/example/main.ts index cb21f91..be3b856 100644 --- a/example/main.ts +++ b/example/main.ts @@ -57,35 +57,41 @@ async function main() { const devices = await client.getDevices(); - client.emitter.on('statusChanged', (status) => { - try { - const device = devices.DevicesObj[status.deviceId]; - const watts = status.current !== undefined ? status.current * device.Voltage : undefined; - rootLogger.info( - `'${device.Name}' status changed: ${status.temperature}°C, ${status.humidity}%, ${watts ?? 'na'}W` - ); - } catch (error) { - rootLogger.error(`Error processing status update for device '${status.deviceId}':`, error); - } - }); + if (process.env.MYSA_OUTPUT_RAW_DATA === 'true') { + client.emitter.on('rawRealtimeMessageReceived', (data) => { + rootLogger.info(data, 'Raw message received'); + }); + } else { + client.emitter.on('statusChanged', (status) => { + try { + const device = devices.DevicesObj[status.deviceId]; + const watts = status.current !== undefined ? status.current * device.Voltage : undefined; + rootLogger.info( + `'${device.Name}' status changed: ${status.temperature}°C, ${status.humidity}%, ${watts ?? 'na'}W` + ); + } catch (error) { + rootLogger.error(`Error processing status update for device '${status.deviceId}':`, error); + } + }); - client.emitter.on('setPointChanged', (change) => { - try { - const device = devices.DevicesObj[change.deviceId]; - rootLogger.info(`'${device.Name}' setpoint changed from ${change.previousSetPoint} to ${change.newSetPoint}`); - } catch (error) { - rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error); - } - }); + client.emitter.on('setPointChanged', (change) => { + try { + const device = devices.DevicesObj[change.deviceId]; + rootLogger.info(`'${device.Name}' setpoint changed from ${change.previousSetPoint} to ${change.newSetPoint}`); + } catch (error) { + rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error); + } + }); - client.emitter.on('stateChanged', (change) => { - try { - const device = devices.DevicesObj[change.deviceId]; - rootLogger.info(change, `'${device.Name}' state changed.`); - } catch (error) { - rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error); - } - }); + client.emitter.on('stateChanged', (change) => { + try { + const device = devices.DevicesObj[change.deviceId]; + rootLogger.info(change, `'${device.Name}' state changed.`); + } catch (error) { + rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error); + } + }); + } for (const device of Object.entries(devices.DevicesObj)) { const serial = await client.getDeviceSerialNumber(device[0]); diff --git a/package.json b/package.json index 7c19307..03563e4 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "browser": false, "scripts": { "example": "tsx --watch ./example/main.ts", + "example:raw": "MYSA_OUTPUT_RAW_DATA=true tsx --watch ./example/main.ts", "lint": "eslint --max-warnings 0 src/**/*.ts", "style-lint": "prettier -c .", "build": "tsup",