11 Commits

4 changed files with 308 additions and 329 deletions

View File

@@ -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.

View File

@@ -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]);

549
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -40,28 +40,32 @@
"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",
"build:docs": "typedoc"
},
"overrides": {
"brace-expansion": "^2.0.2"
},
"dependencies": {
"@aws-sdk/client-iot": "3.825.0",
"@aws-sdk/credential-providers": "3.825.0",
"@aws-sdk/client-iot": "3.830.0",
"@aws-sdk/credential-providers": "3.830.0",
"amazon-cognito-identity-js": "6.3.15",
"aws-iot-device-sdk-v2": "1.21.5",
"dayjs": "1.11.13",
"lodash": "4.17.21"
},
"devDependencies": {
"@eslint/js": "9.28.0",
"@eslint/js": "9.29.0",
"@semantic-release/npm": "12.0.1",
"@types/lodash": "4.17.17",
"@types/node": "22.15.30",
"@types/lodash": "4.17.18",
"@types/node": "24.0.3",
"conventional-changelog-conventionalcommits": "9.0.0",
"dotenv": "16.5.0",
"eslint": "9.28.0",
"eslint-plugin-jsdoc": "50.7.1",
"eslint": "9.29.0",
"eslint-plugin-jsdoc": "51.0.3",
"eslint-plugin-tsdoc": "0.4.0",
"pino": "9.7.0",
"pino-pretty": "13.0.0",
@@ -70,10 +74,10 @@
"prettier-plugin-organize-imports": "4.1.0",
"semantic-release": "24.2.5",
"tsup": "8.5.0",
"tsx": "4.19.4",
"tsx": "4.20.3",
"typedoc": "0.28.5",
"typedoc-material-theme": "1.4.0",
"typescript": "5.8.3",
"typescript-eslint": "8.33.1"
"typescript-eslint": "8.34.0"
}
}