Skip to content

Commit

Permalink
Correct removeDevice. (Koenkk#247)
Browse files Browse the repository at this point in the history
Correct match responses.
  • Loading branch information
kirovilya authored Oct 29, 2020
1 parent d0dc334 commit aa3882f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/adapter/zigate/adapter/zigateAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ class ZiGateAdapter extends Adapter {
}
};

public removeDevice(networkAddress: number, ieeeAddr: string): Promise<void> {
public async removeDevice(networkAddress: number, ieeeAddr: string): Promise<void> {
const payload = {
targetShortAddress: networkAddress,
targetAddress: ieeeAddr,
extendedAddress: ieeeAddr
};

// @TODO test
return this.driver.sendCommand(ZiGateCommandCode.RemoveDevice, payload)
.then(() => Promise.resolve()).catch(() => Promise.reject());
await this.driver.sendCommand(ZiGateCommandCode.RemoveDevice, payload);
return Promise.resolve();
};

/**
Expand Down Expand Up @@ -543,7 +543,8 @@ class ZiGateAdapter extends Adapter {
try {
const result = await this.driver.sendCommand(
ZiGateCommandCode.RawAPSDataRequest, payload,
undefined, extraParameters
undefined, extraParameters,
disableResponse=(disableResponse || zclFrame.Header.frameControl.disableDefaultResponse),
);

if (result !== null) {
Expand Down
6 changes: 3 additions & 3 deletions src/adapter/zigate/driver/commandType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const ZiGateCommand: { [key: string]: ZiGateCommandType } = {
},
[ZiGateCommandCode.RemoveDevice]: {
request: [
{name: 'targetShortAddress', parameterType: 'UINT16BE'}, // <target short address: uint64_t>
{name: 'targetAddress', parameterType: 'IEEEADDR'}, // <target address: uint64_t>
{name: 'extendedAddress', parameterType: 'IEEEADDR'}, // <extended address: uint64_t>
],
response: [
Expand Down Expand Up @@ -261,12 +261,12 @@ export const ZiGateCommand: { [key: string]: ZiGateCommandType } = {
{
receivedProperty: 'payload.sourceEndpoint',
matcher: equal,
expectedProperty: 'payload.sourceEndpoint'
expectedProperty: 'payload.destinationEndpoint'
},
{
receivedProperty: 'payload.destinationEndpoint',
matcher: equal,
expectedProperty: 'payload.destinationEndpoint'
expectedProperty: 'payload.sourceEndpoint'
},
{
receivedProperty: 'payload.profileID',
Expand Down
7 changes: 4 additions & 3 deletions src/adapter/zigate/driver/zigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export default class ZiGate extends EventEmitter {
code: ZiGateCommandCode,
payload?: ZiGateObjectPayload,
timeout?: number,
extraParameters?: object
extraParameters?: object,
disableResponse: boolean = false
): Promise<ZiGateObject> {

const waiters: Promise<ZiGateObject>[] = [];
Expand All @@ -98,9 +99,9 @@ export default class ZiGate extends EventEmitter {

const sendBuffer = frame.toBuffer();
debug.log('<-- send command ', sendBuffer);
debug.log(`DisableResponse: ${disableResponse}`);


if (Array.isArray(ziGateObject.command.response)) {
if (!disableResponse && Array.isArray(ziGateObject.command.response)) {
ziGateObject.command.response.forEach((rules) => {
waiters.push(
this.waitress.waitFor(
Expand Down

0 comments on commit aa3882f

Please sign in to comment.