diff --git a/packages/binding-modbus/src/modbus-client.ts b/packages/binding-modbus/src/modbus-client.ts index 8074d2107..b2c30e084 100644 --- a/packages/binding-modbus/src/modbus-client.ts +++ b/packages/binding-modbus/src/modbus-client.ts @@ -150,7 +150,7 @@ export default class ModbusClient implements ProtocolClient { const parsed = new URL(form.href); const port = parsed.port ? parseInt(parsed.port, 10) : DEFAULT_PORT; let body; - if (content) { + if (content != null) { body = await content.toBuffer(); } const formValidated = this.validateAndFillDefaultForm(form, body?.byteLength); @@ -160,7 +160,7 @@ export default class ModbusClient implements ProtocolClient { const host = parsed.hostname; const hostAndPort = host + ":" + port; - if (body) { + if (body != null) { this.validateBufferLength(formValidated, body); } diff --git a/packages/binding-mqtt/src/mqtt-broker-server.ts b/packages/binding-mqtt/src/mqtt-broker-server.ts index bd5862c14..b6a176071 100644 --- a/packages/binding-mqtt/src/mqtt-broker-server.ts +++ b/packages/binding-mqtt/src/mqtt-broker-server.ts @@ -146,7 +146,7 @@ export default class MqttBrokerServer implements ProtocolServer { const topic = encodeURIComponent(name) + "/properties/" + encodeURIComponent(propertyName); const property = thing.properties[propertyName]; - const writeOnly = property.writeOnly ?? false; + const writeOnly: boolean = property.writeOnly ?? false; if (!writeOnly) { const href = this.brokerURI + "/" + topic; const form = new TD.Form(href, ContentSerdes.DEFAULT); @@ -167,7 +167,7 @@ export default class MqttBrokerServer implements ProtocolServer { }; thing.handleObserveProperty(propertyName, observeListener, { formIndex: property.forms.length - 1 }); } - const readOnly = property.readOnly ?? false; + const readOnly: boolean = property.readOnly ?? false; if (!readOnly) { const href = this.brokerURI + "/" + topic + "/writeproperty"; this.broker.subscribe(topic + "/writeproperty"); @@ -236,7 +236,7 @@ export default class MqttBrokerServer implements ProtocolServer { // connecting to the actions debug(`MqttBrokerServer at ${this.brokerURI} received message for '${receivedTopic}'`); const thing = this.things.get(segments[this.THING_NAME_SEGMENT_INDEX]); - if (thing) { + if (thing != null) { if (segments[this.INTERACTION_TYPE_SEGMENT_INDEX] === "actions") { const action = thing.actions[segments[this.INTERACTION_NAME_SEGMENT_INDEX]]; if (action != null) { @@ -251,7 +251,7 @@ export default class MqttBrokerServer implements ProtocolServer { ) { // connecting to the writeable properties const thing = this.things.get(segments[this.THING_NAME_SEGMENT_INDEX]); - if (thing) { + if (thing != null) { if (segments[this.INTERACTION_TYPE_SEGMENT_INDEX] === "properties") { const property = thing.properties[segments[this.INTERACTION_NAME_SEGMENT_INDEX]]; if (property != null) { @@ -364,7 +364,7 @@ export default class MqttBrokerServer implements ProtocolServer { } } - if (removedThing) { + if (removedThing != null) { info(`MqttBrokerServer succesfully destroyed '${removedThing.title}'`); } else { info(`MqttBrokerServer failed to destroy thing with thingId '${thingId}'`); diff --git a/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts b/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts index e3d2fbbb0..70b7aad8d 100644 --- a/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts +++ b/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts @@ -76,7 +76,7 @@ describe("MQTT client implementation", () => { if (!eventReceived) { eventReceived = true; } else { - if (!x.data) { + if (x.data == null) { done(new Error("No data received")); return; } @@ -138,7 +138,7 @@ describe("MQTT client implementation", () => { if (!eventReceived) { eventReceived = true; } else { - if (!x.data) { + if (x.data == null) { done(new Error("No data received")); return; } diff --git a/packages/binding-opcua/src/opcua-protocol-client.ts b/packages/binding-opcua/src/opcua-protocol-client.ts index 80d794a83..2df14aa2a 100644 --- a/packages/binding-opcua/src/opcua-protocol-client.ts +++ b/packages/binding-opcua/src/opcua-protocol-client.ts @@ -151,7 +151,8 @@ export class OPCUAProtocolClient implements ProtocolClient { private async _withConnection(form: OPCUAForm, next: (connection: OPCUAConnection) => Promise): Promise { const endpoint = form.href; - if (!endpoint || !endpoint.match(/^opc.tcp:\/\//)) { + const matchesScheme: boolean = endpoint?.match(/^opc.tcp:\/\//) != null; + if (!matchesScheme) { debug(`invalid opcua:endpoint ${endpoint} specified`); throw new Error("Invalid OPCUA endpoint " + endpoint); } diff --git a/packages/binding-websockets/src/ws-server.ts b/packages/binding-websockets/src/ws-server.ts index 9672ab739..a2b85d3a7 100644 --- a/packages/binding-websockets/src/ws-server.ts +++ b/packages/binding-websockets/src/ws-server.ts @@ -178,8 +178,8 @@ export default class WebSocketServer implements ProtocolServer { const form = new TD.Form(href, ContentSerdes.DEFAULT); const ops = []; - const writeOnly = property.writeOnly ?? false; - const readOnly = property.readOnly ?? false; + const writeOnly: boolean = property.writeOnly ?? false; + const readOnly: boolean = property.readOnly ?? false; if (!writeOnly) { ops.push("readproperty", "observeproperty", "unobserveproperty"); @@ -209,7 +209,8 @@ export default class WebSocketServer implements ProtocolServer { } }; - if (property.writeOnly ?? false) { + const writeOnly: boolean = property.writeOnly ?? false; + if (writeOnly) { for (let formIndex = 0; formIndex < thing.properties[propertyName].forms.length; formIndex++) { thing .handleObserveProperty(propertyName, observeListener, { formIndex })