Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions src/homekit-device/plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ export default class HomeKitDevicePlug extends HomekitDevice {
this.removeSwitchService();
} else if (this.category === Categories.OUTLET) {
primaryService = this.addOutletService();
this.removeBrightnessCharacteristic(primaryService);
this.removeLightbulbService();
this.removeSwitchService();
} else if (this.category === Categories.SWITCH) {
primaryService = this.addSwitchService();
this.removeBrightnessCharacteristic(primaryService);
this.removeLightbulbService();
this.removeOutletService();
} else {
Expand Down Expand Up @@ -138,21 +136,19 @@ export default class HomeKitDevicePlug extends HomekitDevice {

this.addOnCharacteristic(outletService);

if (this.category === Categories.OUTLET) {
const outletInUseCharacteristic = getOrAddCharacteristic(
outletService,
Characteristic.OutletInUse
);
const outletInUseCharacteristic = getOrAddCharacteristic(
outletService,
Characteristic.OutletInUse
);

outletInUseCharacteristic.onGet(() => {
this.getSysInfo().catch(this.logRejection.bind(this)); // this will eventually trigger update
return this.tplinkDevice.inUse; // immediately returned cached value
});
outletInUseCharacteristic.onGet(() => {
this.getSysInfo().catch(this.logRejection.bind(this)); // this will eventually trigger update
return this.tplinkDevice.inUse; // immediately returned cached value
});

this.tplinkDevice.on('in-use-update', (value) => {
this.updateValue(outletService, outletInUseCharacteristic, value);
});
}
this.tplinkDevice.on('in-use-update', (value) => {
this.updateValue(outletService, outletInUseCharacteristic, value);
});

return outletService;
}
Expand Down Expand Up @@ -218,7 +214,9 @@ export default class HomeKitDevicePlug extends HomekitDevice {
this.updateValue(service, onCharacteristic, value);
});

this.addBrightnessCharacteristic(service);
if (this.tplinkDevice.supportsDimmer) {
this.addBrightnessCharacteristic(service);
}

return service;
}
Expand Down Expand Up @@ -254,13 +252,6 @@ export default class HomeKitDevicePlug extends HomekitDevice {
return service;
}

private removeBrightnessCharacteristic(service: Service) {
this.removeCharacteristicIfExists(
service,
this.platform.Characteristic.Brightness
);
}

private addEnergyCharacteristics(service: Service): void {
const { Amperes, KilowattHours, VoltAmperes, Volts, Watts } =
this.platform.customCharacteristics;
Expand Down