Skip to content

Commit

Permalink
v1.2.2 (#113)
Browse files Browse the repository at this point in the history
## [Version 1.2.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.2) (2021-11-24)

## What's Changed
* Allow the `configDeviceName` to override `deviceName`.
* Added Logging when BLE Connection wasn't established.

**Full Changelog**: v1.2.1...v1.2.2
  • Loading branch information
donavanbecker authored Nov 25, 2021
1 parent 642b2aa commit cd0dce7
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 27 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)

## [Version 1.2.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.0) (2021-11-24)
## [Version 1.2.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.2) (2021-11-24)

## What's Changed
* Allow the `configDeviceName` to override `deviceName`.
* Added Logging when BLE Connection wasn't established.

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.1...v1.2.2

## [Version 1.2.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.1) (2021-11-24)

## What's Changed
* Fixed Bug: Curtains alternate between open/close state. [#85](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/85)
Expand Down
2 changes: 1 addition & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
}
],
"condition": {
"functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Meter' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].meter && !model.options.devices[arrayIndices].meter.hide_temperature);"
"functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Meter' && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].meter.hide_temperature);"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge SwitchBot",
"name": "@switchbot/homebridge-switchbot",
"version": "1.2.1",
"version": "1.2.2",
"description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
"author": "SwitchBot <[email protected]> (https://github.com/SwitchBot)",
"license": "ISC",
Expand Down
17 changes: 15 additions & 2 deletions src/devices/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Bot {
deviceStatus!: deviceStatusResponse;

// BLE Others
connected?: boolean;
switchbot!: switchbot;
serviceData!: serviceData;
mode!: serviceData['mode'];
Expand Down Expand Up @@ -237,14 +238,26 @@ export class Bot {
this.platform.device(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
this.platform.device(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
+ ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);

if (this.serviceData) {
this.connected = true;
this.platform.device(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
} else {
this.connected = false;
this.platform.device(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
}
};
// Wait 10 seconds
return switchbot.wait(10000);
}).then(() => {
// Stop to monitor
switchbot.stopScan();
this.parseStatus();
this.updateHomeKitCharacteristics();
if (this.connected) {
this.parseStatus();
this.updateHomeKitCharacteristics();
} else {
this.platform.log.error(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
}
}).catch(async (e: any) => {
this.platform.log.error(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
if (this.deviceDebug) {
Expand Down
17 changes: 15 additions & 2 deletions src/devices/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Contact {
deviceStatus!: deviceStatusResponse;

// BLE Others
connected?: boolean;
switchbot!: switchbot;
serviceData!: serviceData;
battery!: serviceData['battery'];
Expand Down Expand Up @@ -248,14 +249,26 @@ export class Contact {
this.platform.device(`Contact Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
this.platform.device(`Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: `
+ `${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);

if (this.serviceData) {
this.connected = true;
this.platform.device(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
} else {
this.connected = false;
this.platform.device(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
}
};
// Wait 10 seconds
return switchbot.wait(10000);
}).then(() => {
// Stop to monitor
switchbot.stopScan();
this.parseStatus();
this.updateHomeKitCharacteristics();
if (this.connected) {
this.parseStatus();
this.updateHomeKitCharacteristics();
} else {
this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
}
}).catch(async (e: any) => {
this.platform.log.error(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
if (this.deviceDebug) {
Expand Down
17 changes: 15 additions & 2 deletions src/devices/curtains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Curtain {
deviceStatus!: deviceStatusResponse;

// BLE Others
connected?: boolean;
switchbot!: switchbot;
serviceData!: serviceData;
calibration: serviceData['calibration'];
Expand Down Expand Up @@ -413,14 +414,26 @@ export class Curtain {
this.platform.device(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
this.platform.device(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, `
+ `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);

if (this.serviceData) {
this.connected = true;
this.platform.device(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
} else {
this.connected = false;
this.platform.device(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
}
};
// Wait 10 seconds
return switchbot.wait(10000);
}).then(() => {
// Stop to monitor
switchbot.stopScan();
this.parseStatus();
this.updateHomeKitCharacteristics();
if (this.connected) {
this.parseStatus();
this.updateHomeKitCharacteristics();
} else {
this.platform.log.error(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
}
}).catch(async (e: any) => {
this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
if (this.deviceDebug) {
Expand Down
17 changes: 15 additions & 2 deletions src/devices/humidifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Humidifier {
deviceStatus!: deviceStatusResponse;

// BLE Others
connected?: boolean;
serviceData!: serviceData;
onState!: serviceData['onState'];
autoMode!: serviceData['autoMode'];
Expand Down Expand Up @@ -315,14 +316,26 @@ export class Humidifier {
this.platform.device(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
this.platform.device(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
+ `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);

if (this.serviceData) {
this.connected = true;
this.platform.device(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
} else {
this.connected = false;
this.platform.device(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
}
};
// Wait 10 seconds
return switchbot.wait(10000);
}).then(() => {
// Stop to monitor
switchbot.stopScan();
this.parseStatus();
this.updateHomeKitCharacteristics();
if (this.connected) {
this.parseStatus();
this.updateHomeKitCharacteristics();
} else {
this.platform.log.error(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
}
}).catch(async (e: any) => {
this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
if (this.deviceDebug) {
Expand Down
31 changes: 19 additions & 12 deletions src/devices/meters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Meter {
deviceStatus!: deviceStatusResponse;

// BLE Others
connected?: boolean;
switchbot!: switchbot;
serviceData!: serviceData;
battery!: serviceData['battery'];
Expand Down Expand Up @@ -191,19 +192,13 @@ export class Meter {
// Current Temperature
if (!this.device.meter?.hide_temperature) {
if (this.device.meter?.unit === 1) {
this.CurrentTemperature = Number(this.temperature?.f);
this.CurrentTemperature = this.toFahrenheit(this.temperature!.c);
} else if (this.device.meter?.unit === 0) {
this.CurrentTemperature = Number(this.temperature?.c);
this.CurrentTemperature = this.toCelsius(this.temperature!.c);
} else {
if (this.fahrenheit) {
this.CurrentTemperature = Number(this.temperature?.f);
} else {
this.CurrentTemperature = Number(this.temperature?.c);
}
this.CurrentTemperature = Number(this.temperature?.c);
}

this.CurrentTemperature = Number();
this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c, fahrenheit: ${this.fahrenheit}`);
this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
}
}

Expand Down Expand Up @@ -278,14 +273,26 @@ export class Meter {
this.platform.device(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
+ `temperature: ${JSON.stringify(ad.serviceData.temperature)}, fahrenheit: ${ad.serviceData.fahrenheit}, `
+ `humidity: ${ad.serviceData.humidity}, battery: ${ad.serviceData.battery}`);

if (this.serviceData) {
this.connected = true;
this.platform.device(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
} else {
this.connected = false;
this.platform.device(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
}
};
// Wait 10 seconds
return switchbot.wait(10000);
}).then(() => {
// Stop to monitor
switchbot.stopScan();
this.parseStatus();
this.updateHomeKitCharacteristics();
if (this.connected) {
this.parseStatus();
this.updateHomeKitCharacteristics();
} else {
this.platform.log.error(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
}
}).catch(async (e: any) => {
this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
if (this.deviceDebug) {
Expand Down
17 changes: 15 additions & 2 deletions src/devices/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Motion {
deviceStatus!: deviceStatusResponse;

// BLE Others
connected?: boolean;
switchbot!: switchbot;
serviceData!: serviceData;
battery!: serviceData['battery'];
Expand Down Expand Up @@ -185,14 +186,26 @@ export class Motion {
this.platform.device(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
this.platform.device(`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: `
+ `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);

if (this.serviceData) {
this.connected = true;
this.platform.device(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
} else {
this.connected = false;
this.platform.device(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
}
};
// Wait 10 seconds
return switchbot.wait(10000);
}).then(() => {
// Stop to monitor
switchbot.stopScan();
this.parseStatus();
this.updateHomeKitCharacteristics();
if (this.connected) {
this.parseStatus();
this.updateHomeKitCharacteristics();
} else {
this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
}
}).catch(async (e: any) => {
this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
if (this.deviceDebug) {
Expand Down
6 changes: 6 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
const devices = deviceLists.map((v: any) => v);
for (const device of devices) {
if (device.deviceType) {
if (device.configDeviceName) {
device.deviceName = device.configDeviceName;
}
this.createDevice(device);
}
}
Expand All @@ -209,6 +212,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
this.debug(`SwitchBot Devices: ${JSON.stringify(devices)}`);
for (const device of devices) {
if (device.deviceType) {
if (device.configDeviceName) {
device.deviceName = device.configDeviceName;
}
this.createDevice(device);
}
}
Expand Down

0 comments on commit cd0dce7

Please sign in to comment.