Skip to content

Commit

Permalink
revert(commit): 73298a5
Browse files Browse the repository at this point in the history
Reverts change that closes #17: implement support for reachability"
  • Loading branch information
johannrichard committed Nov 21, 2020
1 parent f1fae16 commit c6207c8
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/dingzAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class DingzDaAccessory extends EventEmitter {
Temperature: 0 as number,
Motion: false as boolean,
Brightness: 0 as number,
Reachable: true as boolean,
};

private motionTimer?: NodeJS.Timer;
Expand Down Expand Up @@ -129,20 +128,11 @@ export class DingzDaAccessory extends EventEmitter {
}
});

// Initialize reachability service
const bridgingService: Service =
this.accessory.getService(this.platform.Service.BridgingState) ??
this.accessory.addService(this.platform.Service.BridgingState);

bridgingService
.getCharacteristic(this.platform.Characteristic.Reachable)
.on(CharacteristicEventTypes.GET, this.getReachability.bind(this));

this.services.push(bridgingService);
/****
* How to discover Accessories:
* - Check for UDP Packets and/or use manually configured accessories
*/

// Add Dimmers, Blinds etc.
this.platform.log.info(
'Adding output devices for ',
Expand All @@ -164,6 +154,7 @@ export class DingzDaAccessory extends EventEmitter {
// Now we have what we need and can create the services …
this.addOutputServices();
setInterval(() => {
// TODO: Set rechability if call times out too many times
// Set up an interval to fetch Dimmer states
this.updateDeviceState();
}, 10000);
Expand Down Expand Up @@ -300,13 +291,6 @@ export class DingzDaAccessory extends EventEmitter {
);
}

private getReachability(callback: CharacteristicGetCallback) {
const currentReachability = this.dingzStates.Reachable ? 1 : 0;

this.platform.log.debug('getReachablility:', currentReachability);
callback(null, currentReachability);
}

private updateTemperature(temperatureService: Service) {
const currentTemperature: number = this.dingzStates.Temperature;

Expand Down Expand Up @@ -700,15 +684,13 @@ export class DingzDaAccessory extends EventEmitter {
private updateDeviceState() {
this.getDeviceState().then((state) => {
if (typeof state !== 'undefined' && state?.config) {
this.dingzStates.Reachable = true;
// Outputs
this.dingzStates.Dimmers = state.dimmers;
this.dingzStates.LED = state.led;
// Sensors
this.dingzStates.Temperature = state.sensors.room_temperature;
this.dingzStates.Brightness = state.sensors.brightness;
} else {
this.dingzStates.Reachable = false;
this.platform.log.error('Can`t get device state');
}
this.platform.eb.emit(DingzEvent.STATE_UPDATE);
Expand Down Expand Up @@ -1120,7 +1102,6 @@ export class DingzDaAccessory extends EventEmitter {
this.getDeviceMotion()
.then((data) => {
if (data?.success) {
this.dingzStates.Reachable = true;
const isMotion: boolean = data.motion;
// Only update if motionService exists *and* if there's a change in motion'
if (this.motionService && this.dingzStates.Motion !== isMotion) {
Expand All @@ -1133,8 +1114,6 @@ export class DingzDaAccessory extends EventEmitter {
.updateValue(isMotion);
}
} else {
// Not reachable
this.dingzStates.Reachable = false;
throw new DeviceNotReachableError(
`Device can not be reached ->
${this.device.name}-> ${this.device.address}`,
Expand Down

0 comments on commit c6207c8

Please sign in to comment.