@switchbot/homebridge-switchbot
Advanced tools
Comparing version
@@ -35,3 +35,2 @@ "use strict"; | ||
// Retrieve initial values and updateHomekit | ||
this.parseStatus(); | ||
// set accessory information | ||
@@ -89,3 +88,2 @@ accessory | ||
this.refreshStatus(); | ||
this.updateHomeKitCharacteristics(); | ||
// Start an update interval | ||
@@ -160,2 +158,10 @@ (0, rxjs_1.interval)(this.platform.config.options.refreshRate * 1000) | ||
} | ||
else { | ||
if (this.deviceStatus.body.power === 'on') { | ||
this.On = true; | ||
} | ||
else { | ||
this.On = false; | ||
} | ||
} | ||
this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.On}`); | ||
@@ -245,12 +251,14 @@ } | ||
try { | ||
this.deviceStatus = { | ||
statusCode: 100, | ||
body: { | ||
deviceId: this.device.deviceId, | ||
deviceType: this.device.deviceType, | ||
hubDeviceId: this.device.hubDeviceId, | ||
power: 'on', | ||
}, | ||
message: 'success', | ||
}; | ||
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data; | ||
this.platform.device(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`); | ||
/*this.deviceStatus = { | ||
statusCode: 100, | ||
body: { | ||
deviceId: this.device.deviceId!, | ||
deviceType: this.device.deviceType!, | ||
hubDeviceId: this.device.hubDeviceId, | ||
power: 'on', | ||
}, | ||
message: 'success', | ||
};*/ | ||
this.parseStatus(); | ||
@@ -287,3 +295,3 @@ this.updateHomeKitCharacteristics(); | ||
} | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -295,3 +303,4 @@ async BLEpushChanges() { | ||
this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`); | ||
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => { | ||
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }) | ||
.then((device_list) => { | ||
this.platform.log.info(`Bot: ${this.accessory.displayName}, On: ${this.On}`); | ||
@@ -298,0 +307,0 @@ return device_list[0].press({ id: this.device.bleMac }); |
@@ -429,3 +429,3 @@ "use strict"; | ||
} | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -432,0 +432,0 @@ async BLEpushChanges() { |
@@ -349,3 +349,3 @@ "use strict"; | ||
//} | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -352,0 +352,0 @@ async BLEpushChanges() { |
@@ -134,3 +134,3 @@ "use strict"; | ||
this.statusCode(push); | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -137,0 +137,0 @@ else { |
@@ -59,2 +59,4 @@ import { AxiosInstance } from 'axios'; | ||
connectionTypeExistingAccessory(device: device & devicesConfig, existingAccessory: PlatformAccessory): Promise<void>; | ||
connectionTypeNewIRAccessory(device: irdevice & devicesConfig, accessory: PlatformAccessory): Promise<void>; | ||
connectionTypeExistingIRAccessory(device: irdevice & devicesConfig, existingAccessory: PlatformAccessory): Promise<void>; | ||
unregisterPlatformAccessories(existingAccessory: PlatformAccessory): void; | ||
@@ -61,0 +63,0 @@ deviceListInfo(devices: deviceResponses): void; |
{ | ||
"displayName": "Homebridge SwitchBot", | ||
"name": "@switchbot/homebridge-switchbot", | ||
"version": "1.3.1-beta.2", | ||
"version": "1.3.1-beta.3", | ||
"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)", |
@@ -64,3 +64,2 @@ | ||
// Retrieve initial values and updateHomekit | ||
this.parseStatus(); | ||
@@ -127,3 +126,2 @@ // set accessory information | ||
this.refreshStatus(); | ||
this.updateHomeKitCharacteristics(); | ||
@@ -202,2 +200,8 @@ // Start an update interval | ||
this.On = false; | ||
} else { | ||
if (this.deviceStatus.body.power === 'on') { | ||
this.On = true; | ||
} else { | ||
this.On = false; | ||
} | ||
} | ||
@@ -290,3 +294,5 @@ this.platform.debug(`Bot ${this.accessory.displayName} On: ${this.On}`); | ||
try { | ||
this.deviceStatus = { | ||
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data; | ||
this.platform.device(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`); | ||
/*this.deviceStatus = { | ||
statusCode: 100, | ||
@@ -300,3 +306,3 @@ body: { | ||
message: 'success', | ||
}; | ||
};*/ | ||
this.parseStatus(); | ||
@@ -332,3 +338,3 @@ this.updateHomeKitCharacteristics(); | ||
} | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -341,23 +347,24 @@ | ||
this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`); | ||
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => { | ||
this.platform.log.info(`Bot: ${this.accessory.displayName}, On: ${this.On}`); | ||
return device_list[0].press({ id: this.device.bleMac }); | ||
}).then(() => { | ||
this.platform.device(`Bot: ${this.accessory.displayName} Done.`); | ||
}).catch(async (e: any) => { | ||
this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`); | ||
if (this.deviceDebug) { | ||
this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` | ||
+ ` Error Message: ${JSON.stringify(e.message)}`); | ||
} | ||
if (this.debugDebug) { | ||
this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` | ||
+ ` Error: ${JSON.stringify(e)}`); | ||
} | ||
if (this.platform.config.credentials?.openToken) { | ||
this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`); | ||
await this.openAPIpushChanges(); | ||
} | ||
this.apiError(e); | ||
}); | ||
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }) | ||
.then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => { | ||
this.platform.log.info(`Bot: ${this.accessory.displayName}, On: ${this.On}`); | ||
return device_list[0].press({ id: this.device.bleMac }); | ||
}).then(() => { | ||
this.platform.device(`Bot: ${this.accessory.displayName} Done.`); | ||
}).catch(async (e: any) => { | ||
this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`); | ||
if (this.deviceDebug) { | ||
this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` | ||
+ ` Error Message: ${JSON.stringify(e.message)}`); | ||
} | ||
if (this.debugDebug) { | ||
this.platform.log.error(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` | ||
+ ` Error: ${JSON.stringify(e)}`); | ||
} | ||
if (this.platform.config.credentials?.openToken) { | ||
this.platform.log.warn(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`); | ||
await this.openAPIpushChanges(); | ||
} | ||
this.apiError(e); | ||
}); | ||
} else if (this.device.bot?.mode === 'switch') { | ||
@@ -364,0 +371,0 @@ this.platform.device(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`); |
@@ -490,3 +490,3 @@ | ||
} | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -493,0 +493,0 @@ |
@@ -397,3 +397,3 @@ import { AxiosResponse } from 'axios'; | ||
//} | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} | ||
@@ -400,0 +400,0 @@ |
@@ -181,3 +181,3 @@ import { AxiosResponse } from 'axios'; | ||
this.statusCode(push); | ||
this.refreshStatus(); | ||
setTimeout(this.refreshStatus, 5000); | ||
} else { | ||
@@ -184,0 +184,0 @@ this.platform.device(`Indoor Cam: ${this.accessory.displayName} No pushChanges. Active: ${this.Active}`); |
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 too big to display
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 too big to display
1433912
0.75%17554
0.61%