Skip to content

Commit

Permalink
feat(accessories): streamline push naming
Browse files Browse the repository at this point in the history
  • Loading branch information
johannrichard committed Nov 12, 2020
1 parent 35ef031 commit 9614ad6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/dingzAccessory.ts
Expand Up @@ -486,7 +486,7 @@ export class DingzDaAccessory extends EventEmitter {
this.services.push(this.addButtonService('dingz Button 4', '4'));

this.platform.eb.on(
DingzEvent.BTN_PRESS,
DingzEvent.ACTION,
(mac, action: ButtonAction, button: ButtonId | '5') => {
if (mac === this.device.mac && button) {
this.platform.log.debug(
Expand Down
2 changes: 1 addition & 1 deletion src/myStromButtonAccessory.ts
Expand Up @@ -124,7 +124,7 @@ export class MyStromButtonAccessory {
.getCharacteristic(this.platform.Characteristic.ChargingState)
.on(CharacteristicEventTypes.GET, this.getChargingState.bind(this));

this.platform.eb.on(DingzEvent.BTN_PRESS, (mac, action, battery) => {
this.platform.eb.on(DingzEvent.ACTION, (mac, action, battery) => {
if (mac === this.device.mac) {
this.buttonState = action ?? ButtonAction.SINGLE_PRESS;
this.batteryLevel = battery;
Expand Down
6 changes: 3 additions & 3 deletions src/platform.ts
Expand Up @@ -896,7 +896,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
request.connection.remoteAddress,
);
this.eb.emit(
DingzEvent.BTN_PRESS,
DingzEvent.ACTION,
mac,
action as ButtonAction,
button as ButtonId,
Expand All @@ -905,15 +905,15 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
if (action) {
this.log.warn('-> Simple Button action');
this.eb.emit(
DingzEvent.BTN_PRESS,
DingzEvent.ACTION,
mac,
action as ButtonAction,
battery as number,
);
} else {
this.log.warn('-> Button Heartbeat');
this.eb.emit(
DingzEvent.BTN_PRESS,
DingzEvent.ACTION,
mac,
action as ButtonAction,
battery,
Expand Down
10 changes: 5 additions & 5 deletions src/util/dingzEventBus.ts
Expand Up @@ -6,17 +6,17 @@ import { ButtonId } from './dingzTypes';
// EVENT TYPES
export const enum DingzEvent {
UPDATE_INFO = 'updateDingzInfo',
BTN_PRESS = 'buttonPress',
ACTION = 'deviceAction',
STATE_UPDATE = 'stateUpdate',
}

export declare interface DingzEventBus {
on(
event: DingzEvent.BTN_PRESS,
event: DingzEvent.ACTION,
listener: (mac: string, action: ButtonAction, battery: number) => void,
): this;
on(
event: DingzEvent.BTN_PRESS,
event: DingzEvent.ACTION,
listener: (mac: string, action: ButtonAction, button: ButtonId) => void,
): this;
on(
Expand All @@ -26,13 +26,13 @@ export declare interface DingzEventBus {
on(event: DingzEvent.STATE_UPDATE, listener: () => void): this;

emit(
event: DingzEvent.BTN_PRESS,
event: DingzEvent.ACTION,
mac: string,
action: ButtonAction,
battery: number,
): boolean;
emit(
event: DingzEvent.BTN_PRESS,
event: DingzEvent.ACTION,
mac: string,
action: ButtonAction,
button: ButtonId,
Expand Down

0 comments on commit 9614ad6

Please sign in to comment.