homebridge-aeg-robot
Version:
AEG RX9 / Electrolux Pure i9 robot vacuum plugin for Homebridge
52 lines • 2.02 kB
JavaScript
// Homebridge plugin for AEG RX 9 / Electrolux Pure i9 robot vacuum
// Copyright © 2022-2024 Alexander Thoukydides
import { AEGAuthoriseUserAgent } from './aegapi-ua-auth.js';
import { AEGAPITest } from './aegapi-test.js';
import { AEGAPIRX9 } from './aegapi-rx9.js';
import { checkers } from './ti/aegapi-types.js';
import { PrefixLogger } from './logger.js';
// Access to the Electrolux Group API
export class AEGAPI {
log;
config;
// User agent used for all requests
ua;
// Create a new API
constructor(log, config) {
this.log = log;
this.config = config;
this.ua = new AEGAuthoriseUserAgent(log, config);
// Run API tests if enabled
if (config.debug.includes('Run API Tests')) {
const unsafe = config.debug.includes('Run Unsafe API Tests');
new AEGAPITest(log, this, unsafe);
}
}
// Get user appliances
async getAppliances() {
const appliances = await this.ua.getJSON(checkers.Appliances, '/api/v1/appliances');
if (!this.config.debug.includes('Log Appliance IDs')) {
appliances.forEach(({ applianceId, applianceName }) => {
PrefixLogger.addApplianceId(applianceId, applianceName);
});
}
return appliances;
}
// Get appliance info
async getApplianceInfo(applianceId) {
return this.ua.getJSON(checkers.ApplianceInfo, `/api/v1/appliances/${applianceId}/info`);
}
// Get appliance state
async getApplianceState(applianceId) {
return this.ua.getJSON(checkers.ApplianceState, `/api/v1/appliances/${applianceId}/state`);
}
// Send command to appliance
async sendCommand(applianceId, command, signal) {
await this.ua.put(`/api/v1/appliances/${applianceId}/command`, command, { signal });
}
// Create an API for an AEG RX9.1 or RX9.2 robot vacuum cleaner
rx9API(applianceId) {
return new AEGAPIRX9(this.ua, applianceId);
}
}
//# sourceMappingURL=aegapi.js.map