mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 09:41:07 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98003665b8 | ||
|
|
7afec1a7a9 | ||
|
|
e6631b0fd8 | ||
|
|
efaf3310d2 | ||
|
|
a62b538c42 | ||
|
|
2023e8b321 | ||
|
|
808e8f1037 | ||
|
|
f201c7944a | ||
|
|
f6c6127dab | ||
|
|
73cec9a90e | ||
|
|
39fc9048df | ||
|
|
45d69453df | ||
|
|
6dc6da2dde | ||
|
|
0cf7a1756c | ||
|
|
51b8f64dab | ||
|
|
14ee1d30eb | ||
|
|
4680ca2f85 | ||
|
|
3f020d5dc3 | ||
|
|
e93741525c | ||
|
|
9b945869aa | ||
|
|
becafbfacc | ||
|
|
c29e750f9c | ||
|
|
e3c93453ed |
@@ -51,6 +51,12 @@ Then, run the example:
|
|||||||
npm run 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
|
## Using
|
||||||
|
|
||||||
The Mysa SDK provides a simple interface to interact with Mysa smart thermostats.
|
The Mysa SDK provides a simple interface to interact with Mysa smart thermostats.
|
||||||
|
|||||||
@@ -57,35 +57,41 @@ async function main() {
|
|||||||
|
|
||||||
const devices = await client.getDevices();
|
const devices = await client.getDevices();
|
||||||
|
|
||||||
client.emitter.on('statusChanged', (status) => {
|
if (process.env.MYSA_OUTPUT_RAW_DATA === 'true') {
|
||||||
try {
|
client.emitter.on('rawRealtimeMessageReceived', (data) => {
|
||||||
const device = devices.DevicesObj[status.deviceId];
|
rootLogger.info(data, 'Raw message received');
|
||||||
const watts = status.current !== undefined ? status.current * device.Voltage : undefined;
|
});
|
||||||
rootLogger.info(
|
} else {
|
||||||
`'${device.Name}' status changed: ${status.temperature}°C, ${status.humidity}%, ${watts ?? 'na'}W`
|
client.emitter.on('statusChanged', (status) => {
|
||||||
);
|
try {
|
||||||
} catch (error) {
|
const device = devices.DevicesObj[status.deviceId];
|
||||||
rootLogger.error(`Error processing status update for device '${status.deviceId}':`, error);
|
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) => {
|
client.emitter.on('setPointChanged', (change) => {
|
||||||
try {
|
try {
|
||||||
const device = devices.DevicesObj[change.deviceId];
|
const device = devices.DevicesObj[change.deviceId];
|
||||||
rootLogger.info(`'${device.Name}' setpoint changed from ${change.previousSetPoint} to ${change.newSetPoint}`);
|
rootLogger.info(`'${device.Name}' setpoint changed from ${change.previousSetPoint} to ${change.newSetPoint}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error);
|
rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.emitter.on('stateChanged', (change) => {
|
client.emitter.on('stateChanged', (change) => {
|
||||||
try {
|
try {
|
||||||
const device = devices.DevicesObj[change.deviceId];
|
const device = devices.DevicesObj[change.deviceId];
|
||||||
rootLogger.info(change, `'${device.Name}' state changed.`);
|
rootLogger.info(change, `'${device.Name}' state changed.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error);
|
rootLogger.error(`Error processing setpoint update for device '${change.deviceId}':`, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const device of Object.entries(devices.DevicesObj)) {
|
for (const device of Object.entries(devices.DevicesObj)) {
|
||||||
const serial = await client.getDeviceSerialNumber(device[0]);
|
const serial = await client.getDeviceSerialNumber(device[0]);
|
||||||
|
|||||||
2584
package-lock.json
generated
2584
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
40
package.json
40
package.json
@@ -40,40 +40,44 @@
|
|||||||
"browser": false,
|
"browser": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"example": "tsx --watch ./example/main.ts",
|
"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",
|
"lint": "eslint --max-warnings 0 src/**/*.ts",
|
||||||
"style-lint": "prettier -c .",
|
"style-lint": "prettier -c .",
|
||||||
"build": "tsup",
|
"build": "tsup",
|
||||||
"build:docs": "typedoc"
|
"build:docs": "typedoc"
|
||||||
},
|
},
|
||||||
|
"overrides": {
|
||||||
|
"brace-expansion": "^2.0.2"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-iot": "3.825.0",
|
"@aws-sdk/client-iot": "3.835.0",
|
||||||
"@aws-sdk/credential-providers": "3.825.0",
|
"@aws-sdk/credential-providers": "3.876.0",
|
||||||
"amazon-cognito-identity-js": "6.3.15",
|
"amazon-cognito-identity-js": "6.3.15",
|
||||||
"aws-iot-device-sdk-v2": "1.21.5",
|
"aws-iot-device-sdk-v2": "1.22.0",
|
||||||
"dayjs": "1.11.13",
|
"dayjs": "1.11.13",
|
||||||
"lodash": "4.17.21"
|
"lodash": "4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "9.28.0",
|
"@eslint/js": "9.34.0",
|
||||||
"@semantic-release/npm": "12.0.1",
|
"@semantic-release/npm": "12.0.2",
|
||||||
"@types/lodash": "4.17.17",
|
"@types/lodash": "4.17.20",
|
||||||
"@types/node": "22.15.30",
|
"@types/node": "24.3.0",
|
||||||
"conventional-changelog-conventionalcommits": "9.0.0",
|
"conventional-changelog-conventionalcommits": "9.0.0",
|
||||||
"dotenv": "16.5.0",
|
"dotenv": "17.2.1",
|
||||||
"eslint": "9.28.0",
|
"eslint": "9.34.0",
|
||||||
"eslint-plugin-jsdoc": "50.7.1",
|
"eslint-plugin-jsdoc": "54.1.1",
|
||||||
"eslint-plugin-tsdoc": "0.4.0",
|
"eslint-plugin-tsdoc": "0.4.0",
|
||||||
"pino": "9.7.0",
|
"pino": "9.7.0",
|
||||||
"pino-pretty": "13.0.0",
|
"pino-pretty": "13.0.0",
|
||||||
"prettier": "3.5.3",
|
"prettier": "3.6.2",
|
||||||
"prettier-plugin-jsdoc": "1.3.2",
|
"prettier-plugin-jsdoc": "1.3.3",
|
||||||
"prettier-plugin-organize-imports": "4.1.0",
|
"prettier-plugin-organize-imports": "4.2.0",
|
||||||
"semantic-release": "24.2.5",
|
"semantic-release": "24.2.7",
|
||||||
"tsup": "8.5.0",
|
"tsup": "8.5.0",
|
||||||
"tsx": "4.19.4",
|
"tsx": "4.20.3",
|
||||||
"typedoc": "0.28.5",
|
"typedoc": "0.28.11",
|
||||||
"typedoc-material-theme": "1.4.0",
|
"typedoc-material-theme": "1.4.0",
|
||||||
"typescript": "5.8.3",
|
"typescript": "5.9.2",
|
||||||
"typescript-eslint": "8.33.1"
|
"typescript-eslint": "8.41.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export function parseMqttPayload(payload: ArrayBuffer): OutPayload {
|
|||||||
* @param payload - The typed payload object to serialize
|
* @param payload - The typed payload object to serialize
|
||||||
* @returns The serialized payload as ArrayBuffer ready for MQTT transmission
|
* @returns The serialized payload as ArrayBuffer ready for MQTT transmission
|
||||||
*/
|
*/
|
||||||
export function serializeMqttPayload<T extends InPayload>(payload: T): ArrayBuffer {
|
export function serializeMqttPayload<T extends InPayload>(payload: T): Uint8Array<ArrayBuffer> {
|
||||||
const jsonString = JSON.stringify(payload);
|
const jsonString = JSON.stringify(payload);
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
return encoder.encode(jsonString);
|
return encoder.encode(jsonString);
|
||||||
|
|||||||
Reference in New Issue
Block a user