From c0617609c16d5bee11c30b4ce9abd84b5352b1c6 Mon Sep 17 00:00:00 2001 From: Shaquu Date: Tue, 18 Jun 2024 23:32:54 +0200 Subject: [PATCH] cleanup ServiceUtils --- src/lib/utils/ServiceUtils.ts | 12 +++++------- src/lib/utils/ServiceUtils2.ts | 6 ++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/utils/ServiceUtils.ts b/src/lib/utils/ServiceUtils.ts index eeb2c42a..7558097b 100644 --- a/src/lib/utils/ServiceUtils.ts +++ b/src/lib/utils/ServiceUtils.ts @@ -228,7 +228,7 @@ module.exports = function (node: HAPServiceNodeType) { } const onInput = function (msg: Record) { - if (msg.hasOwnProperty('payload')) { + if (msg.payload) { // payload must be an object const type = typeof msg.payload @@ -241,7 +241,7 @@ module.exports = function (node: HAPServiceNodeType) { return } - const topic = node.config.topic ? node.config.topic : node.name + const topic = node.config.topic ?? node.name if (node.config.filter && msg.topic !== topic) { log.debug( "msg.topic doesn't match configured value and filter is enabled. Dropping message." @@ -250,15 +250,13 @@ module.exports = function (node: HAPServiceNodeType) { } let context: any = null - if (msg.payload.hasOwnProperty('Context')) { + if (msg.payload.Context) { context = msg.payload.Context delete msg.payload.Context } - node.topic_in = msg.topic ? msg.topic : '' + node.topic_in = msg.topic ?? '' - // iterate over characteristics to be written - // eslint-disable-next-line no-unused-vars Object.keys(msg.payload).map((key: string) => { if (node.supported.indexOf(key) < 0) { log.error( @@ -277,7 +275,7 @@ module.exports = function (node: HAPServiceNodeType) { ) if (context !== null) { - characteristic.setValue(value, () => {}, context) + characteristic.setValue(value, undefined, context) } else { characteristic.setValue(value) } diff --git a/src/lib/utils/ServiceUtils2.ts b/src/lib/utils/ServiceUtils2.ts index d31630df..26bf5c72 100644 --- a/src/lib/utils/ServiceUtils2.ts +++ b/src/lib/utils/ServiceUtils2.ts @@ -276,7 +276,7 @@ module.exports = function (node: HAPService2NodeType) { return } - const topic = node.config.topic ? node.config.topic : node.name + const topic = node.config.topic ?? node.name if (node.config.filter && msg.topic !== topic) { log.debug( "msg.topic doesn't match configured value and filter is enabled. Dropping message." @@ -292,8 +292,6 @@ module.exports = function (node: HAPService2NodeType) { node.topic_in = msg.topic ?? '' - // iterate over characteristics to be written - // eslint-disable-next-line no-unused-vars Object.keys(msg.payload).map((key: string) => { if (node.supported.indexOf(key) < 0) { if ( @@ -330,7 +328,7 @@ module.exports = function (node: HAPService2NodeType) { ) if (context !== null) { - characteristic.setValue(value, () => {}, context) + characteristic.setValue(value, undefined, context) } else { characteristic.setValue(value) }