Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zigate adapter. Correct removeDevice and match responses #247

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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