Socket
Socket
Sign inDemoInstall

@switchbot/homebridge-switchbot

Package Overview
Dependencies
Maintainers
2
Versions
853
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@switchbot/homebridge-switchbot - npm Package Compare versions

Comparing version 0.1.2-beta.18 to 0.1.2-beta.19

6

dist/devices/bots.d.ts

@@ -36,3 +36,5 @@ /// <reference types="node" />

*/
parseStatus(): void;
parseStatus(): Promise<void>;
private BLEparseStatus;
private openAPIparseStatus;
/**

@@ -52,2 +54,4 @@ * Asks the SwitchBot API for the latest device information

pushChanges(): Promise<void>;
private BLEpushChanges;
private openAPIpushChanges;
/**

@@ -54,0 +58,0 @@ * Updates the status for each of the HomeKit Characteristics

198

dist/devices/bots.js

@@ -94,20 +94,26 @@ "use strict";

*/
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
this.platform.debug('Bots BLE Device RefreshStatus');
await this.BLEparseStatus();
}
else {
if (!this.platform.config.options?.bot?.switch) {
this.OutletInUse = true;
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} OutletInUse: ${this.OutletInUse} On: ${this.SwitchOn}`);
await this.openAPIparseStatus();
}
}
async BLEparseStatus() {
this.platform.debug('Bots BLE Device RefreshStatus');
}
async openAPIparseStatus() {
if (!this.platform.config.options?.bot?.switch) {
this.OutletInUse = true;
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId)) {
this.SwitchOn = false;
}
else {
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.SwitchOn}`);
this.platform.debug(`Bot ${this.accessory.displayName} OutletInUse: ${this.OutletInUse} On: ${this.SwitchOn}`);
}
else {
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.SwitchOn}`);
}

@@ -171,2 +177,4 @@ }

});
this.parseStatus();
this.updateHomeKitCharacteristics();
}, this.platform.config.options.refreshRate * 60000);

@@ -205,83 +213,89 @@ }

if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
this.platform.device('Bot BLE Device pushChanges');
// Target state has been changed.
this.platform.log.info('Target state of Bot setting: ' + (this.TargetState ? 'ON' : 'OFF'));
this.switchbot
.discover({ duration: this.ScanDuration, model: 'H', quick: true, id: (this.device.bleMac) })
.then((device_list) => {
this.platform.log.info('Scan done.');
let targetDevice = null;
for (const device of device_list) {
// log.info(device.modelName, device.address);
if (device.address === this.device.bleMac) {
targetDevice = device;
break;
}
}
if (!targetDevice) {
this.platform.log.info('No device was found during scan.');
return new Promise((resolve, reject) => {
reject(new Error('No device was found during scan.'));
});
}
else {
this.platform.log.info(targetDevice.modelName + ' (' + targetDevice.address + ') was found.');
// Set event handers
targetDevice.onconnect = () => {
// log.info('Connected.');
};
targetDevice.ondisconnect = () => {
// log.info('Disconnected.');
};
this.platform.log.info('Bot is running...');
return this.setTargetDeviceState(targetDevice, this.TargetState);
}
})
.then(() => {
this.platform.log.info('Done.');
this.SwitchOn = this.TargetState;
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state has been set to: ' + (this.SwitchOn ? 'ON' : 'OFF'));
})
.catch((error) => {
this.platform.log.error(error);
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state failed to be set to: ' + (this.TargetState ? 'ON' : 'OFF'));
});
await this.BLEpushChanges();
}
else {
const payload = {
commandType: 'command',
parameter: 'default',
};
if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId) && this.SwitchOn) {
payload.command = 'turnOn';
this.SwitchOn = true;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
await this.openAPIpushChanges();
}
this.refreshStatus();
}
async BLEpushChanges() {
this.platform.device('Bot BLE Device pushChanges');
// Target state has been changed.
this.platform.log.info('Target state of Bot setting: ' + (this.TargetState ? 'ON' : 'OFF'));
this.switchbot
.discover({ duration: this.ScanDuration, model: 'H', quick: true, id: (this.device.bleMac) })
.then((device_list) => {
this.platform.log.info('Scan done.');
let targetDevice = null;
for (const device of device_list) {
// log.info(device.modelName, device.address);
if (device.address === this.device.bleMac) {
targetDevice = device;
break;
}
}
else if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId) && !this.SwitchOn) {
payload.command = 'turnOff';
this.SwitchOn = false;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
if (!targetDevice) {
this.platform.log.info('No device was found during scan.');
return new Promise((resolve, reject) => {
reject(new Error('No device was found during scan.'));
});
}
else if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId)) {
payload.command = 'press';
this.platform.debug('Press Mode');
this.SwitchOn = false;
}
else {
throw new Error('Bot Device Paramters not set for this Bot.');
this.platform.log.info(targetDevice.modelName + ' (' + targetDevice.address + ') was found.');
// Set event handers
targetDevice.onconnect = () => {
// log.info('Connected.');
};
targetDevice.ondisconnect = () => {
// log.info('Disconnected.');
};
this.platform.log.info('Bot is running...');
return this.setTargetDeviceState(targetDevice, this.TargetState);
}
this.platform.log.info('Sending request for', this.accessory.displayName, 'to SwitchBot API. command:', payload.command, 'parameter:', payload.parameter, 'commandType:', payload.commandType);
this.platform.debug(`Bot ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
// Make the API request
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Bot ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
})
.then(() => {
this.platform.log.info('Done.');
this.SwitchOn = this.TargetState;
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state has been set to: ' + (this.SwitchOn ? 'ON' : 'OFF'));
})
.catch((error) => {
this.platform.log.error(error);
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state failed to be set to: ' + (this.TargetState ? 'ON' : 'OFF'));
});
}
async openAPIpushChanges() {
const payload = {
commandType: 'command',
parameter: 'default',
};
if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId) && this.SwitchOn) {
payload.command = 'turnOn';
this.SwitchOn = true;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
}
this.refreshStatus();
else if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId) && !this.SwitchOn) {
payload.command = 'turnOff';
this.SwitchOn = false;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
}
else if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId)) {
payload.command = 'press';
this.platform.debug('Press Mode');
this.SwitchOn = false;
}
else {
throw new Error('Bot Device Paramters not set for this Bot.');
}
this.platform.log.info('Sending request for', this.accessory.displayName, 'to SwitchBot API. command:', payload.command, 'parameter:', payload.parameter, 'commandType:', payload.commandType);
this.platform.debug(`Bot ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
// Make the API request
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Bot ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
}

@@ -292,6 +306,12 @@ /**

updateHomeKitCharacteristics() {
if (this.SwitchOn !== undefined) {
if (this.SwitchOn === undefined) {
this.platform.debug(`On: ${this.SwitchOn}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.On, this.SwitchOn);
}
if (!this.platform.config.options?.bot?.switch && this.OutletInUse !== undefined) {
if (this.OutletInUse === undefined || this.platform.config.options?.bot?.switch) {
this.platform.debug(`On: ${this.OutletInUse}, Switch: ${this.platform.config.options?.bot?.switch}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);

@@ -298,0 +318,0 @@ }

@@ -158,9 +158,18 @@ "use strict";

updateHomeKitCharacteristics() {
if (this.On !== undefined) {
if (this.On === undefined) {
this.platform.debug(`On: ${this.On}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
}
if (this.Brightness !== undefined) {
if (this.Brightness === undefined) {
this.platform.debug(`Brightness: ${this.Brightness}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
}
if (this.ColorTemperature !== undefined) {
if (this.ColorTemperature === undefined) {
this.platform.debug(`ColorTemperature: ${this.ColorTemperature}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.ColorTemperature);

@@ -167,0 +176,0 @@ }

@@ -33,3 +33,5 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

*/
parseStatus(): void;
parseStatus(): Promise<void>;
private BLEparseStatus;
private openAPIparseStatus;
/**

@@ -36,0 +38,0 @@ * Asks the SwitchBot API for the latest device information

@@ -19,2 +19,3 @@ "use strict";

this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
// BLE Connection
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {

@@ -68,25 +69,30 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

*/
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}
await this.BLEparseStatus();
}
else {
await this.openAPIparseStatus();
}
}
async BLEparseStatus() {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}
, ContactSensorState: ${this.ContactSensorState}, MotionDetected: ${this.MotionDetected}`);
}
async openAPIparseStatus() {
if (this.deviceStatus.body.openState === 'open') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.platform.log.info(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
else if (this.deviceStatus.body.openState === 'close') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
else {
// Conact Sensor
if (this.deviceStatus.body.openState === 'open') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.platform.log.info(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
else if (this.deviceStatus.body.openState === 'close') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
else {
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}
, ContactSensorState: ${this.ContactSensorState}, MotionDetected: ${this.MotionDetected}`);
}
}

@@ -183,3 +189,3 @@ /**

if (this.MotionDetected === undefined) {
this.platform.debug(`ContactSensorState: ${this.ContactSensorState}`);
this.platform.debug(`MotionDetected: ${this.MotionDetected}`);
}

@@ -186,0 +192,0 @@ else {

@@ -43,3 +43,5 @@ /// <reference types="node" />

constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: device);
parseStatus(): void;
parseStatus(): Promise<void>;
private BLEparseStatus;
private openAPIparseStatus;
refreshStatus(): Promise<void>;

@@ -49,2 +51,4 @@ private BLErefreshStatus;

pushChanges(): Promise<void>;
private BLEpushChanges;
private OpenAPIpushChanges;
updateHomeKitCharacteristics(): void;

@@ -51,0 +55,0 @@ apiError(e: any): void;

@@ -18,2 +18,3 @@ "use strict";

this.ScanDuration = this.platform.config.options.refreshRate;
// BLE Connection
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {

@@ -123,38 +124,43 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

}
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
this.platform.device('Curtains BLE Device parseStatus');
await this.BLEparseStatus();
}
else {
// CurrentPosition
this.setMinMax();
this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition;
this.setMinMax();
this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition - Device is Currently: ${this.CurrentPosition}`);
if (this.setNewTarget) {
this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
await this.openAPIparseStatus();
}
}
async BLEparseStatus() {
this.platform.device('Curtains BLE Device parseStatus');
}
async openAPIparseStatus() {
this.setMinMax();
this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition;
this.setMinMax();
this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition - Device is Currently: ${this.CurrentPosition}`);
if (this.setNewTarget) {
this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
}
if (this.deviceStatus.body.moving) {
if (this.TargetPosition > this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} closing`);
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
}
if (this.deviceStatus.body.moving) {
if (this.TargetPosition > this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} closing`);
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
}
else if (this.TargetPosition < this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} opening`);
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
}
else {
this.platform.debug(`Curtain ${this.CurrentPosition} - standby`);
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
else if (this.TargetPosition < this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} opening`);
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
}
else {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} standby`);
if (!this.setNewTarget) {
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
this.TargetPosition = this.CurrentPosition;
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
this.platform.debug(`Curtain ${this.CurrentPosition} - standby`);
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
}
else {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} standby`);
if (!this.setNewTarget) {
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
this.TargetPosition = this.CurrentPosition;
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
}
// Brightness

@@ -252,22 +258,28 @@ switch (this.deviceStatus.body.brightness) {

if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
this.platform.device('Curtains BLE Device pushChanges');
await this.BLEpushChanges();
}
else {
if (this.TargetPosition !== this.CurrentPosition) {
this.platform.debug(`Pushing ${this.TargetPosition}`);
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
const payload = {
commandType: 'command',
command: 'setPosition',
parameter: `0,ff,${adjustedTargetPosition}`,
};
this.platform.log.info('Sending request for', this.accessory.displayName, 'to SwitchBot API. command:', payload.command, 'parameter:', payload.parameter, 'commandType:', payload.commandType);
this.platform.debug(`Curtain ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
// Make the API request
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Curtain ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
}
await this.OpenAPIpushChanges();
}
}
BLEpushChanges() {
this.platform.device('Curtains BLE Device pushChanges');
}
async OpenAPIpushChanges() {
if (this.TargetPosition !== this.CurrentPosition) {
this.platform.debug(`Pushing ${this.TargetPosition}`);
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
const payload = {
commandType: 'command',
command: 'setPosition',
parameter: `0,ff,${adjustedTargetPosition}`,
};
this.platform.log.info('Sending request for', this.accessory.displayName, 'to SwitchBot API. command:', payload.command, 'parameter:', payload.parameter, 'commandType:', payload.commandType);
this.platform.debug(`Curtain ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
// Make the API request
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Curtain ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
}
}
updateHomeKitCharacteristics() {

@@ -281,12 +293,24 @@ this.platform.debug(`Curtain ${this.accessory.displayName} updateHomeKitCharacteristics - ${JSON.stringify({

this.setMinMax();
if (this.CurrentPosition !== undefined) {
if (this.CurrentPosition === undefined) {
this.platform.debug(`CurrentPosition: ${this.CurrentPosition}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.CurrentPosition);
}
if (this.PositionState !== undefined) {
if (this.PositionState === undefined) {
this.platform.debug(`PositionState: ${this.PositionState}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
}
if (this.TargetPosition !== undefined) {
if (this.TargetPosition === undefined) {
this.platform.debug(`TargetPosition: ${this.TargetPosition}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.TargetPosition);
}
if (this.CurrentAmbientLightLevel !== undefined) {
if (this.CurrentAmbientLightLevel === undefined) {
this.platform.debug(`CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
}
else {
this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);

@@ -299,3 +323,3 @@ }

this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
this.service.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
}

@@ -302,0 +326,0 @@ statusCode(push) {

@@ -41,3 +41,5 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

*/
parseStatus(): void;
parseStatus(): Promise<void>;
private BLEparseStatus;
private openAPIparseStatus;
/**

@@ -44,0 +46,0 @@ * Asks the SwitchBot API for the latest device information

@@ -23,2 +23,3 @@ "use strict";

this.CurrentTemperature = 0;
// BLE Connection
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {

@@ -121,4 +122,11 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

*/
parseStatus() {
// Set Room Sensor State
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
await this.BLEparseStatus();
}
else {
await this.openAPIparseStatus();
}
}
async BLEparseStatus() {
if (this.deviceStatus.body) {

@@ -136,2 +144,18 @@ this.BatteryLevel = 100;

}
this.platform.debug(`${this.accessory.displayName}
, BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
}
async openAPIparseStatus() {
if (this.deviceStatus.body) {
this.BatteryLevel = 100;
}
else {
this.BatteryLevel = 10;
}
if (this.BatteryLevel < 15) {
this.StatusLowBattery = 1;
}
else {
this.StatusLowBattery = 0;
}
// Current Relative Humidity

@@ -253,6 +277,12 @@ if (!this.platform.config.options?.meter?.hide_humidity) {

updateHomeKitCharacteristics() {
if (this.StatusLowBattery !== undefined) {
if (this.StatusLowBattery === undefined) {
this.platform.debug(`ContactSensorState: ${this.StatusLowBattery}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
}
if (this.BatteryLevel !== undefined) {
if (this.BatteryLevel === undefined) {
this.platform.debug(`ContactSensorState: ${this.BatteryLevel}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);

@@ -259,0 +289,0 @@ }

@@ -31,3 +31,5 @@ import { PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

*/
parseStatus(): void;
parseStatus(): Promise<void>;
private BLEparseStatus;
private openAPIparseStatus;
/**

@@ -34,0 +36,0 @@ * Asks the SwitchBot API for the latest device information

@@ -67,13 +67,18 @@ "use strict";

*/
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId)) {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
await this.BLEparseStatus();
}
else {
// Set Room Sensor State
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
await this.openAPIparseStatus();
}
}
async BLEparseStatus() {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
}
async openAPIparseStatus() {
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
}
/**

@@ -162,3 +167,6 @@ * Asks the SwitchBot API for the latest device information

updateHomeKitCharacteristics() {
if (this.MotionDetected !== undefined) {
if (this.MotionDetected === undefined) {
this.platform.debug(`MotionDetected: ${this.MotionDetected}`);
}
else {
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);

@@ -165,0 +173,0 @@ }

{
"displayName": "Homebridge SwitchBot",
"name": "@switchbot/homebridge-switchbot",
"version": "0.1.2-beta.18",
"version": "0.1.2-beta.19",
"description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",

@@ -6,0 +6,0 @@ "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",

@@ -135,18 +135,26 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

*/
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
this.platform.debug('Bots BLE Device RefreshStatus');
await this.BLEparseStatus();
} else {
if (!this.platform.config.options?.bot?.switch) {
this.OutletInUse = true;
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId!)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} OutletInUse: ${this.OutletInUse} On: ${this.SwitchOn}`);
} else {
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId!)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.SwitchOn}`);
await this.openAPIparseStatus();
}
}
private async BLEparseStatus() {
this.platform.debug('Bots BLE Device RefreshStatus');
}
private async openAPIparseStatus() {
if (!this.platform.config.options?.bot?.switch) {
this.OutletInUse = true;
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId!)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} OutletInUse: ${this.OutletInUse} On: ${this.SwitchOn}`);
} else {
if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId!)) {
this.SwitchOn = false;
}
this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.SwitchOn}`);
}

@@ -211,2 +219,4 @@ }

});
this.parseStatus();
this.updateHomeKitCharacteristics();
}, this.platform.config.options!.refreshRate! * 60000);

@@ -246,90 +256,98 @@ }

if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
this.platform.device('Bot BLE Device pushChanges');
// Target state has been changed.
this.platform.log.info('Target state of Bot setting: ' + (this.TargetState ? 'ON' : 'OFF'));
this.switchbot
.discover({ duration: this.ScanDuration, model: 'H', quick: true, id: (this.device.bleMac!) })
.then((device_list: any) => {
this.platform.log.info('Scan done.');
let targetDevice: any = null;
for (const device of device_list) {
// log.info(device.modelName, device.address);
if (device.address === this.device.bleMac) {
targetDevice = device;
break;
}
}
if (!targetDevice) {
this.platform.log.info('No device was found during scan.');
return new Promise((resolve, reject) => {
reject(new Error('No device was found during scan.'));
});
} else {
this.platform.log.info(targetDevice.modelName + ' (' + targetDevice.address + ') was found.');
// Set event handers
targetDevice.onconnect = () => {
// log.info('Connected.');
};
targetDevice.ondisconnect = () => {
// log.info('Disconnected.');
};
this.platform.log.info('Bot is running...');
return this.setTargetDeviceState(targetDevice, this.TargetState);
}
})
.then(() => {
this.platform.log.info('Done.');
this.SwitchOn = this.TargetState;
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state has been set to: ' + (this.SwitchOn ? 'ON' : 'OFF'));
})
.catch((error: any) => {
this.platform.log.error(error);
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state failed to be set to: ' + (this.TargetState ? 'ON' : 'OFF'));
});
await this.BLEpushChanges();
} else {
const payload = {
commandType: 'command',
parameter: 'default',
} as any;
await this.openAPIpushChanges();
}
this.refreshStatus();
}
if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId!) && this.SwitchOn) {
payload.command = 'turnOn';
this.SwitchOn = true;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
} else if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId!) && !this.SwitchOn) {
payload.command = 'turnOff';
this.SwitchOn = false;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
} else if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId!)) {
payload.command = 'press';
this.platform.debug('Press Mode');
this.SwitchOn = false;
} else {
throw new Error('Bot Device Paramters not set for this Bot.');
}
private async BLEpushChanges() {
this.platform.device('Bot BLE Device pushChanges');
// Target state has been changed.
this.platform.log.info('Target state of Bot setting: ' + (this.TargetState ? 'ON' : 'OFF'));
this.switchbot
.discover({ duration: this.ScanDuration, model: 'H', quick: true, id: (this.device.bleMac!) })
.then((device_list: any) => {
this.platform.log.info('Scan done.');
let targetDevice: any = null;
for (const device of device_list) {
// log.info(device.modelName, device.address);
if (device.address === this.device.bleMac) {
targetDevice = device;
break;
}
}
if (!targetDevice) {
this.platform.log.info('No device was found during scan.');
return new Promise((resolve, reject) => {
reject(new Error('No device was found during scan.'));
});
} else {
this.platform.log.info(targetDevice.modelName + ' (' + targetDevice.address + ') was found.');
// Set event handers
targetDevice.onconnect = () => {
// log.info('Connected.');
};
targetDevice.ondisconnect = () => {
// log.info('Disconnected.');
};
this.platform.log.info('Bot is running...');
return this.setTargetDeviceState(targetDevice, this.TargetState);
}
})
.then(() => {
this.platform.log.info('Done.');
this.SwitchOn = this.TargetState;
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state has been set to: ' + (this.SwitchOn ? 'ON' : 'OFF'));
})
.catch((error: any) => {
this.platform.log.error(error);
this.RunTimer = setTimeout(() => {
this.service?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.SwitchOn);
}, 500);
this.platform.log.info('Bot state failed to be set to: ' + (this.TargetState ? 'ON' : 'OFF'));
});
}
this.platform.log.info(
'Sending request for',
this.accessory.displayName,
'to SwitchBot API. command:',
payload.command,
'parameter:',
payload.parameter,
'commandType:',
payload.commandType,
);
this.platform.debug(`Bot ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
private async openAPIpushChanges() {
const payload = {
commandType: 'command',
parameter: 'default',
} as any;
// Make the API request
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Bot ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId!) && this.SwitchOn) {
payload.command = 'turnOn';
this.SwitchOn = true;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
} else if (this.platform.config.options?.bot?.device_switch?.includes(this.device.deviceId!) && !this.SwitchOn) {
payload.command = 'turnOff';
this.SwitchOn = false;
this.platform.debug(`Switch Mode, Turning ${this.SwitchOn}`);
} else if (this.platform.config.options?.bot?.device_press?.includes(this.device.deviceId!)) {
payload.command = 'press';
this.platform.debug('Press Mode');
this.SwitchOn = false;
} else {
throw new Error('Bot Device Paramters not set for this Bot.');
}
this.refreshStatus();
this.platform.log.info(
'Sending request for',
this.accessory.displayName,
'to SwitchBot API. command:',
payload.command,
'parameter:',
payload.parameter,
'commandType:',
payload.commandType,
);
this.platform.debug(`Bot ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
// Make the API request
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Bot ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
}

@@ -341,6 +359,10 @@

updateHomeKitCharacteristics() {
if (this.SwitchOn !== undefined) {
if (this.SwitchOn === undefined) {
this.platform.debug(`On: ${this.SwitchOn}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.On, this.SwitchOn);
}
if (!this.platform.config.options?.bot?.switch && this.OutletInUse !== undefined) {
if (this.OutletInUse === undefined || this.platform.config.options?.bot?.switch) {
this.platform.debug(`On: ${this.OutletInUse}, Switch: ${this.platform.config.options?.bot?.switch}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);

@@ -347,0 +369,0 @@ }

@@ -220,9 +220,15 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

updateHomeKitCharacteristics() {
if (this.On !== undefined) {
if (this.On === undefined) {
this.platform.debug(`On: ${this.On}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
}
if (this.Brightness !== undefined) {
if (this.Brightness === undefined) {
this.platform.debug(`Brightness: ${this.Brightness}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
}
if (this.ColorTemperature !== undefined) {
if (this.ColorTemperature === undefined) {
this.platform.debug(`ColorTemperature: ${this.ColorTemperature}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.ColorTemperature);

@@ -229,0 +235,0 @@ }

@@ -49,2 +49,4 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
// BLE Connection
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {

@@ -59,2 +61,3 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

}
// this is subject we use to track when we need to POST changes to the SwitchBot API

@@ -108,22 +111,29 @@ this.doContactUpdate = new Subject();

*/
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}
await this.BLEparseStatus();
} else {
await this.openAPIparseStatus();
}
}
private async BLEparseStatus() {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}
, ContactSensorState: ${this.ContactSensorState}, MotionDetected: ${this.MotionDetected}`);
}
private async openAPIparseStatus() {
if (this.deviceStatus.body.openState === 'open') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.platform.log.info(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
} else if (this.deviceStatus.body.openState === 'close') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
} else {
// Conact Sensor
if (this.deviceStatus.body.openState === 'open') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.platform.log.info(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
} else if (this.deviceStatus.body.openState === 'close') {
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
} else {
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}
this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`);
}
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}
, ContactSensorState: ${this.ContactSensorState}, MotionDetected: ${this.MotionDetected}`);
}
}

@@ -223,3 +233,3 @@

if (this.MotionDetected === undefined) {
this.platform.debug(`ContactSensorState: ${this.ContactSensorState}`);
this.platform.debug(`MotionDetected: ${this.MotionDetected}`);
} else {

@@ -226,0 +236,0 @@ this.motionService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);

@@ -67,2 +67,4 @@ /* eslint-disable @typescript-eslint/no-var-requires */

this.ScanDuration = this.platform.config.options!.refreshRate!;
// BLE Connection
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {

@@ -191,35 +193,43 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
this.platform.device('Curtains BLE Device parseStatus');
await this.BLEparseStatus();
} else {
// CurrentPosition
this.setMinMax();
this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
this.setMinMax();
this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition - Device is Currently: ${this.CurrentPosition}`);
if (this.setNewTarget) {
this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
}
await this.openAPIparseStatus();
}
}
if (this.deviceStatus.body.moving) {
if (this.TargetPosition > this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} closing`);
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
} else if (this.TargetPosition < this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} opening`);
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
} else {
this.platform.debug(`Curtain ${this.CurrentPosition} - standby`);
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
private async BLEparseStatus() {
this.platform.device('Curtains BLE Device parseStatus');
}
private async openAPIparseStatus() {
this.setMinMax();
this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!;
this.setMinMax();
this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition - Device is Currently: ${this.CurrentPosition}`);
if (this.setNewTarget) {
this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
}
if (this.deviceStatus.body.moving) {
if (this.TargetPosition > this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} closing`);
this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
} else if (this.TargetPosition < this.CurrentPosition) {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} opening`);
this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
} else {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} standby`);
if (!this.setNewTarget) {
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
this.TargetPosition = this.CurrentPosition;
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
this.platform.debug(`Curtain ${this.CurrentPosition} - standby`);
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
} else {
this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} standby`);
if (!this.setNewTarget) {
/*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
this.TargetPosition = this.CurrentPosition;
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
}
}
// Brightness

@@ -321,30 +331,38 @@ switch (this.deviceStatus.body.brightness) {

if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
this.platform.device('Curtains BLE Device pushChanges');
await this.BLEpushChanges();
} else {
if (this.TargetPosition !== this.CurrentPosition) {
this.platform.debug(`Pushing ${this.TargetPosition}`);
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
const payload = {
commandType: 'command',
command: 'setPosition',
parameter: `0,ff,${adjustedTargetPosition}`,
} as any;
await this.OpenAPIpushChanges();
}
}
this.platform.log.info(
'Sending request for',
this.accessory.displayName,
'to SwitchBot API. command:',
payload.command,
'parameter:',
payload.parameter,
'commandType:',
payload.commandType,
);
this.platform.debug(`Curtain ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
private BLEpushChanges() {
this.platform.device('Curtains BLE Device pushChanges');
}
// Make the API request
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Curtain ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
}
private async OpenAPIpushChanges() {
if (this.TargetPosition !== this.CurrentPosition) {
this.platform.debug(`Pushing ${this.TargetPosition}`);
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
const payload = {
commandType: 'command',
command: 'setPosition',
parameter: `0,ff,${adjustedTargetPosition}`,
} as any;
this.platform.log.info(
'Sending request for',
this.accessory.displayName,
'to SwitchBot API. command:',
payload.command,
'parameter:',
payload.parameter,
'commandType:',
payload.commandType,
);
this.platform.debug(`Curtain ${this.accessory.displayName} pushChanges - ${JSON.stringify(payload)}`);
// Make the API request
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
this.platform.debug(`Curtain ${this.accessory.displayName} Changes pushed - ${push.data}`);
this.statusCode(push);
}

@@ -363,12 +381,20 @@ }

this.setMinMax();
if (this.CurrentPosition !== undefined) {
if (this.CurrentPosition === undefined) {
this.platform.debug(`CurrentPosition: ${this.CurrentPosition}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.CurrentPosition);
}
if (this.PositionState !== undefined) {
if (this.PositionState === undefined) {
this.platform.debug(`PositionState: ${this.PositionState}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
}
if (this.TargetPosition !== undefined) {
if (this.TargetPosition === undefined) {
this.platform.debug(`TargetPosition: ${this.TargetPosition}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.TargetPosition);
}
if (this.CurrentAmbientLightLevel !== undefined) {
if (this.CurrentAmbientLightLevel === undefined) {
this.platform.debug(`CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
} else {
this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);

@@ -382,3 +408,3 @@ }

this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
this.service.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
}

@@ -385,0 +411,0 @@

@@ -61,2 +61,4 @@ import { Service, PlatformAccessory, Units, CharacteristicValue, MacAddress } from 'homebridge';

this.CurrentTemperature = 0;
// BLE Connection
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {

@@ -170,4 +172,11 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

*/
parseStatus() {
// Set Room Sensor State
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
await this.BLEparseStatus();
} else {
await this.openAPIparseStatus();
}
}
private async BLEparseStatus() {
if (this.deviceStatus.body) {

@@ -183,2 +192,17 @@ this.BatteryLevel = 100;

}
this.platform.debug(`${this.accessory.displayName}
, BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
}
private async openAPIparseStatus() {
if (this.deviceStatus.body) {
this.BatteryLevel = 100;
} else {
this.BatteryLevel = 10;
}
if (this.BatteryLevel < 15) {
this.StatusLowBattery = 1;
} else {
this.StatusLowBattery = 0;
}
// Current Relative Humidity

@@ -300,6 +324,10 @@ if (!this.platform.config.options?.meter?.hide_humidity) {

updateHomeKitCharacteristics() {
if (this.StatusLowBattery !== undefined) {
if (this.StatusLowBattery === undefined) {
this.platform.debug(`ContactSensorState: ${this.StatusLowBattery}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
}
if (this.BatteryLevel !== undefined) {
if (this.BatteryLevel === undefined) {
this.platform.debug(`ContactSensorState: ${this.BatteryLevel}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);

@@ -306,0 +334,0 @@ }

@@ -107,13 +107,20 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';

*/
parseStatus() {
async parseStatus() {
if (this.platform.config.options?.ble?.includes(this.device.deviceId!)) {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
await this.BLEparseStatus();
} else {
// Set Room Sensor State
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
await this.openAPIparseStatus();
}
}
private async BLEparseStatus() {
this.MotionDetected = true;
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
}
private async openAPIparseStatus() {
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
this.platform.debug(`${this.accessory.displayName}, MotionDetected: ${this.MotionDetected}`);
}
/**

@@ -205,3 +212,5 @@ * Asks the SwitchBot API for the latest device information

updateHomeKitCharacteristics() {
if (this.MotionDetected !== undefined) {
if (this.MotionDetected === undefined) {
this.platform.debug(`MotionDetected: ${this.MotionDetected}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);

@@ -208,0 +217,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc