Skip to content

Commit

Permalink
refactor(dingz): standardise variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
johannrichard committed Nov 28, 2020
1 parent 90d9b5b commit e00b8cf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/dingzAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,39 +719,42 @@ export class DingzAccessory extends DingzDaBaseAccessory {
id,
index,
}: {
name?: string;
name: string;
output?: DingzDimmerConfigValue;
id: 'D1' | 'D2' | 'D3' | 'D4';
index: DimmerId;
}) {
// Service doesn't yet exist, create new one
const newService =
const service =
this.accessory.getServiceById(this.platform.Service.Lightbulb, id) ??
this.accessory.addService(
this.platform.Service.Lightbulb,
name ?? `Dimmer ${id}`, // Name Dimmers according to WebUI, not API info
name, // Name Dimmers according to WebUI, not API info
id,
);

// Update name
service.getCharacteristic(this.platform.Characteristic.Name).setValue(name);

// register handlers for the On/Off Characteristic
newService
service
.getCharacteristic(this.platform.Characteristic.On)
.on(CharacteristicEventTypes.SET, this.setOn.bind(this, index)) // SET - bind to the `setOn` method below
.on(CharacteristicEventTypes.GET, this.getOn.bind(this, index)); // GET - bind to the `getOn` method below

// register handlers for the Brightness Characteristic but only if not dimmable
if (output && output !== 'non_dimmable') {
newService
service
.getCharacteristic(this.platform.Characteristic.Brightness)
.on(CharacteristicEventTypes.SET, this.setBrightness.bind(this, index)); // SET - bind to the 'setBrightness` method below
}

// Update State
this.eb.on(
AccessoryEvent.PUSH_STATE_UPDATE,
this.updateDimmerState.bind(this, index, output, newService),
this.updateDimmerState.bind(this, index, output, service),
);
return newService;
return service;
}

private updateDimmerState(
Expand Down

0 comments on commit e00b8cf

Please sign in to comment.