homebridge-smartthings-ac
Version:
Control your Samsung SmartThings AC using Homebridge.
53 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceAdapter = void 0;
class DeviceAdapter {
constructor(device, log, client) {
this.device = device;
this.log = log;
this.client = client;
}
async getStatus() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const mainComponent = await this.getMainComponent();
return {
mode: (_b = (_a = mainComponent === null || mainComponent === void 0 ? void 0 : mainComponent['airConditionerMode']) === null || _a === void 0 ? void 0 : _a['airConditionerMode']) === null || _b === void 0 ? void 0 : _b['value'],
targetTemperature: (_d = (_c = mainComponent === null || mainComponent === void 0 ? void 0 : mainComponent['thermostatCoolingSetpoint']) === null || _c === void 0 ? void 0 : _c['coolingSetpoint']) === null || _d === void 0 ? void 0 : _d['value'],
currentTemperature: (_f = (_e = mainComponent === null || mainComponent === void 0 ? void 0 : mainComponent['temperatureMeasurement']) === null || _e === void 0 ? void 0 : _e['temperature']) === null || _f === void 0 ? void 0 : _f['value'],
currentHumidity: (_h = (_g = mainComponent === null || mainComponent === void 0 ? void 0 : mainComponent['relativeHumidityMeasurement']) === null || _g === void 0 ? void 0 : _g['humidity']) === null || _h === void 0 ? void 0 : _h['value'],
active: ((_k = (_j = mainComponent === null || mainComponent === void 0 ? void 0 : mainComponent['switch']) === null || _j === void 0 ? void 0 : _j['switch']) === null || _k === void 0 ? void 0 : _k['value']) === 'on',
};
}
async getMainComponent() {
const status = await this.getDeviceStatus();
if (!status.components) {
throw Error('Cannot get device status');
}
return status.components['main'];
}
getDeviceStatus() {
if (!this.device.deviceId) {
throw new Error('Device id must be set.');
}
this.log.debug('Get status for device', this.device.deviceId);
return this.client.devices.getStatus(this.device.deviceId);
}
async executeMainCommand(command, capability, commandArguments) {
if (!this.device.deviceId) {
throw Error('Device ID must be set');
}
this.log.debug('Executing command', capability, command);
const status = await this.client.devices.executeCommand(this.device.deviceId, {
component: 'main',
command: command,
capability: capability,
arguments: commandArguments,
});
this.log.debug('Command executed with status', status.status);
if (status.status !== 'success') {
throw Error('Command failed with status ' + status.status);
}
}
}
exports.DeviceAdapter = DeviceAdapter;
//# sourceMappingURL=deviceAdapter.js.map