Skip to content

Commit

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

## What's Changed
* Fixed Bug: Cannot read properties of undefined (reading 'updateCharacteristic').

**Full Changelog**: v1.2.3...v1.2.4
  • Loading branch information
donavanbecker authored Nov 25, 2021
1 parent f6bbfe5 commit 66a0b3b
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 55 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

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

## What's Changed
* Fixed Bug: Cannot read properties of undefined (reading 'updateCharacteristic').

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.3...v1.2.4

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

## What's Changed
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.3",
"version": "1.2.4",
"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
16 changes: 8 additions & 8 deletions src/devices/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Bot {
if (device.bot?.deviceType === 'switch') {
// If outletService still pressent, then remove first
if (this.outletService) {
this.platform.device(`Bot: ${this.accessory.displayName} Removing Leftover outletService first`);
this.platform.device(`Bot: ${accessory.displayName} Removing Leftover outletService first`);
}
this.outletService = this.accessory.getService(this.platform.Service.Outlet);
accessory.removeService(this.outletService!);
Expand All @@ -84,13 +84,13 @@ export class Bot {
(this.switchService =
accessory.getService(this.platform.Service.Switch) ||
accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
this.platform.log.info(`Bot: ${this.accessory.displayName} Displaying as Switch`);
this.platform.log.info(`Bot: ${accessory.displayName} Displaying as Switch`);

this.switchService?.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
} else {
// If switchService still pressent, then remove first
if (this.switchService) {
this.platform.device(`Bot: ${this.accessory.displayName} Removing Leftover switchService first`);
this.platform.device(`Bot: ${accessory.displayName} Removing Leftover switchService first`);
}
this.switchService = this.accessory.getService(this.platform.Service.Switch);
accessory.removeService(this.switchService!);
Expand All @@ -99,7 +99,7 @@ export class Bot {
(this.outletService =
accessory.getService(this.platform.Service.Outlet) ||
accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
this.platform.log.info(`Bot: ${this.accessory.displayName} Displaying as Outlet`);
this.platform.log.info(`Bot: ${accessory.displayName} Displaying as Outlet`);

this.outletService?.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
}
Expand Down Expand Up @@ -444,9 +444,9 @@ export class Bot {
this.platform.debug(`Bot: ${this.accessory.displayName} On: ${this.On}`);
} else {
if (this.device.bot?.deviceType === 'switch') {
this.switchService!.updateCharacteristic(this.platform.Characteristic.On, this.On);
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
} else {
this.outletService!.updateCharacteristic(this.platform.Characteristic.On, this.On);
this.outletService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
}
this.platform.device(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
}
Expand All @@ -468,9 +468,9 @@ export class Bot {

public apiError(e: any) {
if (this.device.bot?.deviceType === 'switch') {
this.switchService!.updateCharacteristic(this.platform.Characteristic.On, e);
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
} else {
this.outletService!.updateCharacteristic(this.platform.Characteristic.On, e);
this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
}
if (this.device.ble) {
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
Expand Down
12 changes: 6 additions & 6 deletions src/devices/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class Contact {
// see https://developers.homebridge.io/#/service/MotionSensor

// Motion Sensor Service
if (this.device.contact?.hide_motionsensor) {
if (device.contact?.hide_motionsensor) {
this.platform.device(`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`);
this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
accessory.removeService(this.motionService!);
Expand All @@ -106,7 +106,7 @@ export class Contact {
}

// Light Sensor Service
if (this.device.contact?.hide_lightsensor) {
if (device.contact?.hide_lightsensor) {
this.platform.device(`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`);
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
accessory.removeService(this.lightSensorService!);
Expand Down Expand Up @@ -328,15 +328,15 @@ export class Contact {
if (this.MotionDetected === undefined) {
this.platform.debug(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
} else {
this.motionService!.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
this.platform.device(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
}
}
if (!this.device.contact?.hide_lightsensor) {
if (this.CurrentAmbientLightLevel === undefined) {
this.platform.debug(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
} else {
this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
this.platform.device(`Contact Sensor: ${this.accessory.displayName}`
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
}
Expand All @@ -360,10 +360,10 @@ export class Contact {
public apiError(e: any) {
this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
if (!this.device.contact?.hide_motionsensor) {
this.motionService!.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
}
if (!this.device.contact?.hide_lightsensor) {
this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
}
if (this.device.ble) {
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
Expand Down
10 changes: 5 additions & 5 deletions src/devices/curtains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class Curtain {
.onSet(this.TargetPositionSet.bind(this));

// Light Sensor Service
if (this.device.curtain?.hide_lightsensor) {
if (device.curtain?.hide_lightsensor) {
this.platform.device(`Curtain: ${accessory.displayName} Removing Light Sensor Service`);
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
accessory.removeService(this.lightSensorService!);
Expand Down Expand Up @@ -573,7 +573,7 @@ export class Curtain {
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
} else {
this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
this.platform.device(`Curtain: ${this.accessory.displayName}`
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
}
Expand All @@ -599,11 +599,11 @@ export class Curtain {
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, e);
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
if (!this.device.curtain?.hide_lightsensor) {
this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
}
if (this.device.ble) {
this.batteryService!.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
this.batteryService!.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/devices/humidifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export class Humidifier {
if (this.CurrentTemperature === undefined) {
this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
} else {
this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
this.platform.device(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
}
}
Expand All @@ -611,7 +611,7 @@ export class Humidifier {
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/devices/plugs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class Plug {

// Characteristic Values
On!: CharacteristicValue;
OutletInUse!: CharacteristicValue;

// OpenAPI Others
deviceStatus!: deviceStatusResponse;
Expand All @@ -32,7 +31,6 @@ export class Plug {
) {
// default placeholders
this.On = false;
this.OutletInUse = true;

// this is subject we use to track when we need to POST changes to the SwitchBot API
this.doPlugUpdate = new Subject();
Expand Down Expand Up @@ -68,8 +66,6 @@ export class Plug {
// create handlers for required characteristics
this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));

this.service.setCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse || true);

// Update Homekit
this.updateHomeKitCharacteristics();

Expand Down Expand Up @@ -173,17 +169,10 @@ export class Plug {
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
this.platform.device(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
}
if (this.OutletInUse === undefined) {
this.platform.debug(`Plug: ${this.accessory.displayName} OutletInUse: ${this.OutletInUse}`);
} else {
this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);
this.platform.device(`Plug: ${this.accessory.displayName} updateCharacteristic OutletInUse: ${this.OutletInUse}`);
}
}

public apiError(e: any) {
this.service.updateCharacteristic(this.platform.Characteristic.On, e);
this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, e);
}

private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
Expand Down
12 changes: 6 additions & 6 deletions src/irdevices/airconditioners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,39 +168,39 @@ export class AirConditioner {
if (this.Active === undefined) {
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
}
if (this.RotationSpeed === undefined) {
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
}
if (this.CurrentTemperature === undefined) {
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.CurrentTemperature);
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.CurrentTemperature);
this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
}
if (this.TargetHeaterCoolerState === undefined) {
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
+ ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
}
if (this.CurrentHeaterCoolerState === undefined) {
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
}
if (this.HeatingThresholdTemperature === undefined) {
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
+ ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
}
Expand Down
6 changes: 3 additions & 3 deletions src/irdevices/airpurifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ export class AirPurifier {
if (this.Active === undefined) {
this.platform.debug(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
this.platform.device(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
}
if (this.CurrentAirPurifierState === undefined) {
this.platform.debug(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
this.service?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
this.platform.device(`Air Purifier: ${this.accessory.displayName}`
+ ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
}
if (this.CurrentHeaterCoolerState === undefined) {
this.platform.debug(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
this.platform.device(`Air Purifier: ${this.accessory.displayName}`
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/cameras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Camera {
if (this.On === undefined) {
this.platform.debug(`Camera: ${this.accessory.displayName} On: ${this.On}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
this.platform.device(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/irdevices/fans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ export class Fan {
if (this.Active === undefined) {
this.platform.debug(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
}
if (this.SwingMode === undefined) {
this.platform.debug(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
}
if (this.RotationSpeed === undefined) {
this.platform.debug(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
} else {
this.service!.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
}
}
Expand Down
Loading

0 comments on commit 66a0b3b

Please sign in to comment.