sleeptracker-tools
Version:
Simple tool to check SleepTracker device status
47 lines (46 loc) • 2.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const api_1 = require("./utils/api");
async function displayDeviceInfo(device) {
console.log(chalk_1.default.yellow('Bed ID: ') + device.deviceID);
console.log(chalk_1.default.yellow('Name: ') + device.name);
console.log(chalk_1.default.yellow('Model: ') + device.modelID);
console.log(chalk_1.default.yellow('Firmware: ') + device.processorVersionFirmware);
console.log(chalk_1.default.yellow('Status: ') + (device.active ? 'Active' : 'Inactive'));
// WiFi Information
console.log(chalk_1.default.yellow('WiFi Signal: ') + `${device.lastWiFiSignal}% (${device.wifiSignalGood ? 'Good' : 'Poor'})`);
// Power Base Information
if (device.powerBase) {
console.log(chalk_1.default.yellow('Power Base: ') + device.powerBase.modelDescription);
}
console.log(chalk_1.default.gray('----------------------------------------'));
}
async function main() {
var _a, _b;
try {
const client = await (0, api_1.createApiClient)();
const response = await client.post('/actrack-client/v2/fpcsiot/processor/getByType', {
...api_1.CLIENT_INFO,
id: 'TEST_ANDROID_cloudIoTDevicesGetByType',
types: [1, 2, 4, 6]
});
if (((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.deviceList) === null || _b === void 0 ? void 0 : _b.length) > 0) {
console.log(chalk_1.default.green('\nConnected beds:\n'));
for (const device of response.data.deviceList) {
await displayDeviceInfo(device);
}
}
else {
console.log(chalk_1.default.red('\nNo beds found'));
}
}
catch (error) {
console.error(chalk_1.default.red(`\nError: ${error instanceof Error ? error.message : 'Unknown error occurred'}`));
process.exit(1);
}
}
main();