iobroker.iot 5.0.2 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -174,7 +174,9 @@ class DeviceManager {
174
174
  // detectedControls = detectedControls.filter(c => ['light', 'dimmer'].includes(c.type));
175
175
  const createdGroups = [];
176
176
  const usedFriendlyNames = [];
177
+ let iteration = 0;
177
178
  while (detectedControls.length) {
179
+ iteration++;
178
180
  // take the next control
179
181
  const control = detectedControls[0];
180
182
  let processedControls = [];
@@ -261,12 +263,10 @@ class DeviceManager {
261
263
  // neither room nor smart name
262
264
  this.log.debug(`Control of type [${control.type}] has neither room no smart name. Skipped.`);
263
265
  }
264
- // if (!processedControls.length) {
265
- // processedControls = [control];
266
- // }
267
- // remove processed controls
268
- // const objectIds = processedControls.map(item => item.object?.id);
269
- // detectedControls = detectedControls.filter(item => item.object && !objectIds.includes(item.object.id));
266
+ if (iteration > 1000) {
267
+ this.log.error(`too many iterations while collecting devices. Stopping to avoid endless loop: ${JSON.stringify(detectedControls)}`);
268
+ break;
269
+ }
270
270
  }
271
271
  // done
272
272
  this.log.debug(`finished collecting devices. there is/are ${this.devices.length} device(s) in total`);
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceManager.js","sourceRoot":"","sources":["../../../src/lib/AlexaSmartHomeV3/DeviceManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,uDAAyC;AACzC,oEAA4C;AAC5C,0DAAkC;AAElC,8DAAsC;AACtC,gFAAwD;AACxD,0EAAkD;AAClD,kEAA0C;AAC1C,wEAAgD;AAChD,+GAAuF;AACvF,+GAAuF;AAEvF,mFAA2D;AAC3D,6EAAqD;AACrD,iFAAyD;AACzD,6CAAyC;AAGzC,MAAM,SAAS,GAA+B;IAC1C,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAA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;4BAC3E,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;gCAC9B,MAAM,IAAI,CAAC,uBAAuB,CAC9B,MAAM,CAAC,EAAE,EACT,GAAG,EAAE;oCACD,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;oCACrC,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gCACxC,CAAC,EACD,uBAAa,CAAC,mBAAmB,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CACpF,CAAC;4BACN,CAAC;wBACL,CAAC;6BAAM,CAAC;4BACJ,IAAI,CAAC,GAAG,CAAC,KAAK,CACV,mCAAmC,EAAE,4BAA4B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAClG,CAAC;wBACN,CAAC;oBACL,CAAC;gBACL,CAAC;gBAED,kEAAkE;gBAClE,MAAM;YACV,CAAC;QACL,CAAC;QAED,2BAA2B;QAC3B,IAAI,QAAQ,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,EAAE,+BAA+B,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;CACJ;AApfD,gCAofC","sourcesContent":["import Device from './Device';\nimport * as Utils from './Helpers/Utils';\nimport Directives from './Alexa/Directives';\nimport Controls from './Controls';\nimport type Control from './Controls/Control';\nimport Logger from './Helpers/Logger';\nimport AdapterProvider from './Helpers/AdapterProvider';\nimport AlexaResponse from './Alexa/AlexaResponse';\nimport IotProxy from './Helpers/IotProxy';\nimport RateLimiter from './Helpers/RateLimiter';\nimport OverallDailyRateLimitExceeded from './Exceptions/OverallDailyRateLimitExceeded';\nimport HourlyDeviceRateLimitExceeded from './Exceptions/HourlyDeviceRateLimitExceeded';\nimport type { AlexaV3EndpointID, AlexaV3Request, IotExternalPatternControl } from './types';\nimport ChangeReport from './Alexa/Directives/ChangeReport';\nimport Discovery from './Alexa/Directives/Discovery';\nimport ReportState from './Alexa/Directives/ReportState';\nimport { randomUUID } from 'node:crypto';\nimport type { Types } from '@iobroker/type-detector';\n\nconst GroupWord: { [lang: string]: string } = {\n en: 'Group',\n de: 'Gruppe',\n it: 'Gruppo',\n fr: 'Groupe',\n ru: 'Группа',\n es: 'Grupo',\n pl: 'Grupa',\n nl: 'Groep',\n};\nconst DeviceWord: { [lang: string]: string } = {\n en: 'Device',\n de: 'Gerät',\n it: 'Dispositivo',\n fr: 'Appareil',\n ru: 'Устройство',\n es: 'Dispositivo',\n pl: 'Urządzenie',\n nl: 'Dispositivo',\n};\n\nexport default class DeviceManager {\n private lang: ioBroker.Languages = 'en';\n private devices: Device[] = [];\n private subscribed: string[] = [];\n private log: Logger;\n private eventsPausedTill = 0; // timestamp\n\n private collecting = false;\n private recollect = false;\n\n /** Creates a Device Manager */\n constructor() {\n this.log = new Logger(this);\n }\n\n async informAboutStatesChange(): Promise<void> {\n await AdapterProvider.get().setStateAsync('smart.updates3', true, true);\n }\n\n get language(): ioBroker.Languages {\n return this.lang;\n }\n\n set language(value: ioBroker.Languages) {\n this.lang = value;\n }\n\n matchDirective(event: AlexaV3Request): ChangeReport | Discovery | ReportState | null {\n if (ChangeReport.matches(event)) {\n return new ChangeReport();\n }\n if (Discovery.matches(event)) {\n return new Discovery();\n }\n if (ReportState.matches(event)) {\n return new ReportState();\n }\n\n return null;\n }\n\n get endpoints(): Device[] {\n return this.devices;\n }\n\n endpointById(id: AlexaV3EndpointID): Device | undefined {\n return this.devices.find(device => device.id === id);\n }\n\n addDevice(device: Device): void {\n this.devices.push(device);\n }\n\n toDevice(options: {\n detectedControls: IotExternalPatternControl[];\n friendlyName: string;\n autoDetected: boolean;\n roomName?: string;\n funcName?: string;\n toggle?: boolean;\n possibleTypes: Types[];\n typeWasDetected: boolean;\n }): Device | undefined {\n const controls: Control[] = [];\n\n this.log.debug(`merging controls to a device with name ${options.friendlyName}`);\n\n options.detectedControls.forEach(item => {\n this.log.silly(`processing control: ${JSON.stringify(item)}`);\n const control = Controls.factory(item);\n\n if (control) {\n this.log.debug(`\"${item.type}\" added to \"${options.friendlyName}\"`);\n controls.push(control);\n } else {\n this.log.debug(`control of type \"${item.type}\" not supported yet. Skipped.`);\n }\n });\n\n if (!controls.length) {\n // the controls are not supported yet...\n return;\n }\n\n // create and add a new device to the collected devices\n this.addDevice(\n new Device({\n id: options.friendlyName,\n friendlyName: options.friendlyName,\n controls,\n autoDetected: options.autoDetected,\n roomName: options.roomName,\n funcName: options.funcName,\n toggle: options.toggle,\n possibleTypes: options.possibleTypes,\n typeWasDetected: options.typeWasDetected,\n }),\n );\n }\n\n getName(name: ioBroker.StringOrTranslated | undefined): string {\n if (!name) {\n return '';\n }\n if (typeof name === 'object') {\n return name[this.lang] || name.en || '';\n }\n return name;\n }\n\n async collectEndpoints(): Promise<void> {\n if (this.collecting) {\n this.log.debug(`collecting devices already in progress. Skipping...`);\n this.recollect = true;\n return;\n }\n this.collecting = true;\n this.log.debug(`(re)collecting devices...`);\n try {\n // const discoveryNeeded = this.devices.length > 0;\n\n this.devices = [];\n const defaultToggle = AdapterProvider.get().config.defaultToggle || false;\n\n // collect all iobroker controls in terms of iobroker type detector (https://github.com/ioBroker/ioBroker.type-detector)\n const detectedControls = await Utils.controls(AdapterProvider.get(), this.lang);\n\n this.log.debug(`type detector found ${detectedControls.length} controls`);\n\n // Normally, every control is a smart device. But due to the iobroker concept of 'rooms and functions'\n // multiple controls might be merged to a single device.\n\n // as long as not all controls mapped to a device...\n\n // detectedControls = detectedControls.filter(c => ['light', 'dimmer'].includes(c.type));\n const createdGroups: string[] = [];\n const usedFriendlyNames: string[] = [];\n\n while (detectedControls.length) {\n // take the next control\n const control = detectedControls[0];\n let processedControls: IotExternalPatternControl[] = [];\n\n if (control.room?.common?.name) {\n if (control.functionality?.common?.name) {\n // controls in the same room with the same functionality\n processedControls = detectedControls.filter(\n item =>\n control.room &&\n item.room?.id === control.room.id &&\n control.functionality &&\n item.functionality?.id === control.functionality.id,\n );\n let friendlyName = Utils.friendlyNameByRoomAndFunctionName(control, this.lang);\n // If a friendly name is already used, append Gruppe, Group, Gruppo, Groupe, etc.\n if (usedFriendlyNames.includes(friendlyName)) {\n let index = 0;\n let newFriendlyName = '';\n do {\n newFriendlyName = `${friendlyName} ${GroupWord[this.lang] || GroupWord.en}${index ? ` ${index}` : ''}`;\n index++;\n } while (usedFriendlyNames.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\n usedFriendlyNames.push(friendlyName);\n\n this.toDevice({\n detectedControls: processedControls,\n friendlyName,\n autoDetected: true,\n roomName: this.getName(control.room?.common?.name),\n funcName: this.getName(control.functionality?.common?.name),\n toggle: processedControls[0].object?.toggle ?? defaultToggle,\n possibleTypes: processedControls[0].object?.possibleTypes || [],\n typeWasDetected: processedControls[0].object?.typeWasDetected || false,\n });\n } else {\n this.log.debug(\n `Control of type [${control.type}] assigned to room [${this.getName(control.room.common.name)}] has no function. Skipped.`,\n );\n }\n // delete it from detected controls to avoid endless loop\n detectedControls.splice(0, 1);\n } else if (control.groupNames?.length) {\n // no room, but smart name (not only one)\n control.groupNames.forEach(groupName => {\n if (!createdGroups.includes(groupName)) {\n createdGroups.push(groupName);\n processedControls = detectedControls.filter(item => item.groupNames?.includes(groupName));\n let friendlyName = this.getName(groupName);\n // If a friendly name is already used, append Device\n if (usedFriendlyNames.includes(friendlyName)) {\n let index = 0;\n let newFriendlyName = '';\n do {\n newFriendlyName = `${friendlyName} ${DeviceWord[this.lang] || DeviceWord.en}${index ? ` ${index}` : ''}`;\n index++;\n } while (usedFriendlyNames.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\n usedFriendlyNames.push(friendlyName);\n\n this.toDevice({\n detectedControls: JSON.parse(JSON.stringify(processedControls)),\n friendlyName,\n autoDetected: false,\n toggle: processedControls[0].object?.toggle ?? defaultToggle,\n possibleTypes: processedControls[0].object?.possibleTypes || [],\n typeWasDetected: processedControls[0].object?.typeWasDetected || false,\n });\n\n // Remove groupName from all controls to avoid processing it again\n for (let c = detectedControls.length - 1; c >= 0; c--) {\n if (detectedControls[c].groupNames) {\n const pos = detectedControls[c].groupNames?.indexOf(groupName);\n if (pos !== -1) {\n detectedControls[c].groupNames.splice(pos, 1);\n }\n if (!detectedControls[c].groupNames.length) {\n detectedControls.splice(c, 1);\n }\n }\n }\n }\n });\n } else {\n // delete it from detected controls to avoid endless loop\n detectedControls.splice(0, 1);\n // neither room nor smart name\n this.log.debug(`Control of type [${control.type}] has neither room no smart name. Skipped.`);\n }\n\n // if (!processedControls.length) {\n // processedControls = [control];\n // }\n\n // remove processed controls\n // const objectIds = processedControls.map(item => item.object?.id);\n // detectedControls = detectedControls.filter(item => item.object && !objectIds.includes(item.object.id));\n }\n\n // done\n this.log.debug(`finished collecting devices. there is/are ${this.devices.length} device(s) in total`);\n for (const device of this.devices) {\n this.log.debug(`${device.toString()}`);\n }\n\n // a new discovery process is needed in case we had already devices and device collection was\n // triggered again by, e.g., a change in room/function enums\n // if (discoveryNeeded) {\n // this.log.info(`Please delete all managed by ioBroker devices in your Alexa app and then start discovery`);\n // }\n\n // collect all relevant states to subscribe to updates\n const stateIds = new Set(\n this.devices\n .flatMap(d => d.controls)\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .map(item => item.getId)\n .filter(id => id),\n );\n this.log.debug(`registering for updates of total ${stateIds.size} states`);\n const newSubscribed = Array.from(stateIds);\n const subscribe: string[] = [];\n for (const id of newSubscribed) {\n this.log.silly(`subscribing to updates of ${id}`);\n if (!this.subscribed.includes(id)) {\n this.subscribed.push(id);\n if (!subscribe.includes(id)) {\n subscribe.push(id);\n }\n }\n }\n\n this.subscribed.sort();\n\n // wait till all promises are settled\n if (subscribe.length) {\n await AdapterProvider.subscribe(subscribe);\n }\n\n // unsubscribe from unused states\n const unsubscribe: string[] = [];\n for (let i = this.subscribed.length - 1; i >= 0; i--) {\n const id = this.subscribed[i];\n if (!newSubscribed.includes(id)) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n this.subscribed.splice(i, 1);\n if (!unsubscribe.includes(id)) {\n unsubscribe.push(id);\n }\n }\n }\n if (unsubscribe.length) {\n await AdapterProvider.unsubscribe(unsubscribe);\n }\n } catch (e) {\n this.log.error(`failed to collect devices: ${e}`);\n if (e.stack) {\n this.log.error(e.stack);\n }\n }\n\n this.collecting = false;\n\n // if during the collection a new collection was triggered, start collecting again\n if (this.recollect) {\n this.recollect = false;\n setTimeout(() => this.collectEndpoints(), 1000);\n }\n }\n\n async destroy(): Promise<void> {\n const promises = [];\n for (const id of this.subscribed) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n promises.push(AdapterProvider.subscribe(id));\n }\n await Promise.allSettled(promises);\n\n this.subscribed = [];\n }\n\n publishStateChange(stateChange: AlexaResponse): void {\n if (this.eventsPausedTill < Date.now()) {\n this.log.silly(`publishing ${JSON.stringify(stateChange)}`);\n IotProxy.publishStateChange(stateChange);\n }\n }\n\n pauseEvents(): void {\n this.eventsPausedTill = Date.now() + 30 * 60 * 1000; // 30 minutes\n }\n\n async executeWithinRateLimits(\n endpointId: AlexaV3EndpointID,\n awaitable: () => Promise<AlexaResponse>,\n errorResponse: AlexaResponse,\n ): Promise<AlexaResponse> {\n try {\n await RateLimiter.incrementAndGet(endpointId);\n return await awaitable();\n } catch (error) {\n if (error instanceof OverallDailyRateLimitExceeded || error instanceof HourlyDeviceRateLimitExceeded) {\n this.log.warn(error.message);\n } else {\n this.log.error(error.message);\n }\n\n return errorResponse;\n }\n }\n\n async handleAlexaEvent(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`incoming Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n if (!event?.directive?.header) {\n throw new Error('Alexa event header is missing');\n }\n\n let response: AlexaResponse;\n const directive = this.matchDirective(event);\n if (directive) {\n response = await directive.handle(event, this);\n } else {\n const endpointId = event?.directive?.endpoint?.endpointId;\n const device = endpointId ? this.endpointById(endpointId) : undefined;\n\n if (device) {\n if (device.supports(event)) {\n response = await this.executeWithinRateLimits(\n endpointId!,\n async () => {\n response = await device.handle(event);\n if (!AlexaResponse.isErrorResponse(response)) {\n // report state change via voice interaction\n const propertyName = response.context?.properties[0].name;\n const responseEvent = ChangeReport.get(\n device.id,\n propertyName || '',\n false,\n event.directive.header.messageId,\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n // get device state (not just one control)\n const deviceState = await device.reportState();\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n // fire state change report to Alexa\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n this.publishStateChange(stateChange);\n }\n await this.informAboutStatesChange();\n } else {\n this.log.debug(\n `ignoring state change event for ${endpointId} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n return response;\n },\n AlexaResponse.throttlingException(event.directive.header.messageId).get(),\n );\n } else {\n response = AlexaResponse.directiveNotSupportedByDevice(\n device.friendlyName,\n event.directive.header.namespace,\n event.directive.header.messageId,\n event.directive.header.payloadVersion,\n ).get();\n }\n } else {\n response = AlexaResponse.endpointUnreachable(event.directive.header.messageId).get();\n }\n }\n\n this.log.silly(`response: ${JSON.stringify(response)}`);\n return response;\n }\n\n async handleStateUpdate(id: string, state: ioBroker.State | null | undefined): Promise<void> {\n // ignore updates not confirmed by a corresponding device\n if (!state?.ack) {\n this.log.silly(`ignoring state change event for ${id} due to state.ack == ${state?.ack}`);\n return;\n }\n if (id.startsWith(`${AdapterProvider.get().namespace}.`)) {\n // nop, this is just to inform Alexa app about changes\n return;\n }\n\n let notFound = true;\n\n for (const device of this.devices) {\n const property = device.controls\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .find(item => item.getId === id);\n\n if (property) {\n notFound = false;\n if (property.currentValue === state.val) {\n this.log.debug(`ignoring state change event for ${id} due to the same value [${state.val}]`);\n } else {\n property.currentValue = state.val;\n\n const responseEvent = Directives.ChangeReport.get(\n device.id,\n property.propertyName,\n true,\n randomUUID(),\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n\n // get device state (not just one control)\n const deviceState = await device.reportState();\n\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n await this.informAboutStatesChange();\n // fire state change report to Alexa\n\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n await this.executeWithinRateLimits(\n device.id,\n () => {\n this.publishStateChange(stateChange);\n return Promise.resolve(stateChange);\n },\n AlexaResponse.throttlingException(responseEvent.directive.header.messageId).get(),\n );\n }\n } else {\n this.log.debug(\n `ignoring state change event for ${id} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n\n // should be the only device having the id => stop processing here\n break;\n }\n }\n\n // this should never happen\n if (notFound) {\n this.log.debug(`state id ${id} doesn't belong to any device`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"DeviceManager.js","sourceRoot":"","sources":["../../../src/lib/AlexaSmartHomeV3/DeviceManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,uDAAyC;AACzC,oEAA4C;AAC5C,0DAAkC;AAElC,8DAAsC;AACtC,gFAAwD;AACxD,0EAAkD;AAClD,kEAA0C;AAC1C,wEAAgD;AAChD,+GAAuF;AACvF,+GAAuF;AAEvF,mFAA2D;AAC3D,6EAAqD;AACrD,iFAAyD;AACzD,6CAAyC;AAGzC,MAAM,SAAS,GAA+B;IAC1C,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,OAAO;IAC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,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;4BACrC,oCAAoC;4BAEpC,2EAA2E;4BAC3E,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;gCAC9B,MAAM,IAAI,CAAC,uBAAuB,CAC9B,MAAM,CAAC,EAAE,EACT,GAAG,EAAE;oCACD,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;oCACrC,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gCACxC,CAAC,EACD,uBAAa,CAAC,mBAAmB,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CACpF,CAAC;4BACN,CAAC;wBACL,CAAC;6BAAM,CAAC;4BACJ,IAAI,CAAC,GAAG,CAAC,KAAK,CACV,mCAAmC,EAAE,4BAA4B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAClG,CAAC;wBACN,CAAC;oBACL,CAAC;gBACL,CAAC;gBAED,kEAAkE;gBAClE,MAAM;YACV,CAAC;QACL,CAAC;QAED,2BAA2B;QAC3B,IAAI,QAAQ,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,EAAE,+BAA+B,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;CACJ;AArfD,gCAqfC","sourcesContent":["import Device from './Device';\nimport * as Utils from './Helpers/Utils';\nimport Directives from './Alexa/Directives';\nimport Controls from './Controls';\nimport type Control from './Controls/Control';\nimport Logger from './Helpers/Logger';\nimport AdapterProvider from './Helpers/AdapterProvider';\nimport AlexaResponse from './Alexa/AlexaResponse';\nimport IotProxy from './Helpers/IotProxy';\nimport RateLimiter from './Helpers/RateLimiter';\nimport OverallDailyRateLimitExceeded from './Exceptions/OverallDailyRateLimitExceeded';\nimport HourlyDeviceRateLimitExceeded from './Exceptions/HourlyDeviceRateLimitExceeded';\nimport type { AlexaV3EndpointID, AlexaV3Request, IotExternalPatternControl } from './types';\nimport ChangeReport from './Alexa/Directives/ChangeReport';\nimport Discovery from './Alexa/Directives/Discovery';\nimport ReportState from './Alexa/Directives/ReportState';\nimport { randomUUID } from 'node:crypto';\nimport type { Types } from '@iobroker/type-detector';\n\nconst GroupWord: { [lang: string]: string } = {\n en: 'Group',\n de: 'Gruppe',\n it: 'Gruppo',\n fr: 'Groupe',\n ru: 'Группа',\n es: 'Grupo',\n pl: 'Grupa',\n nl: 'Groep',\n};\nconst DeviceWord: { [lang: string]: string } = {\n en: 'Device',\n de: 'Gerät',\n it: 'Dispositivo',\n fr: 'Appareil',\n ru: 'Устройство',\n es: 'Dispositivo',\n pl: 'Urządzenie',\n nl: 'Dispositivo',\n};\n\nexport default class DeviceManager {\n private lang: ioBroker.Languages = 'en';\n private devices: Device[] = [];\n private subscribed: string[] = [];\n private log: Logger;\n private eventsPausedTill = 0; // timestamp\n\n private collecting = false;\n private recollect = false;\n\n /** Creates a Device Manager */\n constructor() {\n this.log = new Logger(this);\n }\n\n async informAboutStatesChange(): Promise<void> {\n await AdapterProvider.get().setStateAsync('smart.updates3', true, true);\n }\n\n get language(): ioBroker.Languages {\n return this.lang;\n }\n\n set language(value: ioBroker.Languages) {\n this.lang = value;\n }\n\n matchDirective(event: AlexaV3Request): ChangeReport | Discovery | ReportState | null {\n if (ChangeReport.matches(event)) {\n return new ChangeReport();\n }\n if (Discovery.matches(event)) {\n return new Discovery();\n }\n if (ReportState.matches(event)) {\n return new ReportState();\n }\n\n return null;\n }\n\n get endpoints(): Device[] {\n return this.devices;\n }\n\n endpointById(id: AlexaV3EndpointID): Device | undefined {\n return this.devices.find(device => device.id === id);\n }\n\n addDevice(device: Device): void {\n this.devices.push(device);\n }\n\n toDevice(options: {\n detectedControls: IotExternalPatternControl[];\n friendlyName: string;\n autoDetected: boolean;\n roomName?: string;\n funcName?: string;\n toggle?: boolean;\n possibleTypes: Types[];\n typeWasDetected: boolean;\n }): Device | undefined {\n const controls: Control[] = [];\n\n this.log.debug(`merging controls to a device with name ${options.friendlyName}`);\n\n options.detectedControls.forEach(item => {\n this.log.silly(`processing control: ${JSON.stringify(item)}`);\n const control = Controls.factory(item);\n\n if (control) {\n this.log.debug(`\"${item.type}\" added to \"${options.friendlyName}\"`);\n controls.push(control);\n } else {\n this.log.debug(`control of type \"${item.type}\" not supported yet. Skipped.`);\n }\n });\n\n if (!controls.length) {\n // the controls are not supported yet...\n return;\n }\n\n // create and add a new device to the collected devices\n this.addDevice(\n new Device({\n id: options.friendlyName,\n friendlyName: options.friendlyName,\n controls,\n autoDetected: options.autoDetected,\n roomName: options.roomName,\n funcName: options.funcName,\n toggle: options.toggle,\n possibleTypes: options.possibleTypes,\n typeWasDetected: options.typeWasDetected,\n }),\n );\n }\n\n getName(name: ioBroker.StringOrTranslated | undefined): string {\n if (!name) {\n return '';\n }\n if (typeof name === 'object') {\n return name[this.lang] || name.en || '';\n }\n return name;\n }\n\n async collectEndpoints(): Promise<void> {\n if (this.collecting) {\n this.log.debug(`collecting devices already in progress. Skipping...`);\n this.recollect = true;\n return;\n }\n this.collecting = true;\n this.log.debug(`(re)collecting devices...`);\n try {\n // const discoveryNeeded = this.devices.length > 0;\n\n this.devices = [];\n const defaultToggle = AdapterProvider.get().config.defaultToggle || false;\n\n // collect all iobroker controls in terms of iobroker type detector (https://github.com/ioBroker/ioBroker.type-detector)\n const detectedControls = await Utils.controls(AdapterProvider.get(), this.lang);\n\n this.log.debug(`type detector found ${detectedControls.length} controls`);\n\n // Normally, every control is a smart device. But due to the iobroker concept of 'rooms and functions'\n // multiple controls might be merged to a single device.\n\n // as long as not all controls mapped to a device...\n\n // detectedControls = detectedControls.filter(c => ['light', 'dimmer'].includes(c.type));\n const createdGroups: string[] = [];\n const usedFriendlyNames: string[] = [];\n let iteration = 0;\n\n while (detectedControls.length) {\n iteration++;\n // take the next control\n const control = detectedControls[0];\n let processedControls: IotExternalPatternControl[] = [];\n\n if (control.room?.common?.name) {\n if (control.functionality?.common?.name) {\n // controls in the same room with the same functionality\n processedControls = detectedControls.filter(\n item =>\n control.room &&\n item.room?.id === control.room.id &&\n control.functionality &&\n item.functionality?.id === control.functionality.id,\n );\n let friendlyName = Utils.friendlyNameByRoomAndFunctionName(control, this.lang);\n // If a friendly name is already used, append Gruppe, Group, Gruppo, Groupe, etc.\n if (usedFriendlyNames.includes(friendlyName)) {\n let index = 0;\n let newFriendlyName = '';\n do {\n newFriendlyName = `${friendlyName} ${GroupWord[this.lang] || GroupWord.en}${index ? ` ${index}` : ''}`;\n index++;\n } while (usedFriendlyNames.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\n usedFriendlyNames.push(friendlyName);\n\n this.toDevice({\n detectedControls: processedControls,\n friendlyName,\n autoDetected: true,\n roomName: this.getName(control.room?.common?.name),\n funcName: this.getName(control.functionality?.common?.name),\n toggle: processedControls[0].object?.toggle ?? defaultToggle,\n possibleTypes: processedControls[0].object?.possibleTypes || [],\n typeWasDetected: processedControls[0].object?.typeWasDetected || false,\n });\n } else {\n this.log.debug(\n `Control of type [${control.type}] assigned to room [${this.getName(control.room.common.name)}] has no function. Skipped.`,\n );\n }\n // delete it from detected controls to avoid endless loop\n detectedControls.splice(0, 1);\n } else if (control.groupNames?.length) {\n // no room, but smart name (not only one)\n control.groupNames.forEach(groupName => {\n if (!createdGroups.includes(groupName)) {\n createdGroups.push(groupName);\n processedControls = detectedControls.filter(item => item.groupNames?.includes(groupName));\n let friendlyName = this.getName(groupName);\n // If a friendly name is already used, append Device\n if (usedFriendlyNames.includes(friendlyName)) {\n let index = 0;\n let newFriendlyName = '';\n do {\n newFriendlyName = `${friendlyName} ${DeviceWord[this.lang] || DeviceWord.en}${index ? ` ${index}` : ''}`;\n index++;\n } while (usedFriendlyNames.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\n usedFriendlyNames.push(friendlyName);\n\n this.toDevice({\n detectedControls: JSON.parse(JSON.stringify(processedControls)),\n friendlyName,\n autoDetected: false,\n toggle: processedControls[0].object?.toggle ?? defaultToggle,\n possibleTypes: processedControls[0].object?.possibleTypes || [],\n typeWasDetected: processedControls[0].object?.typeWasDetected || false,\n });\n\n // Remove groupName from all controls to avoid processing it again\n for (let c = detectedControls.length - 1; c >= 0; c--) {\n if (detectedControls[c].groupNames) {\n const pos = detectedControls[c].groupNames?.indexOf(groupName);\n if (pos !== -1) {\n detectedControls[c].groupNames.splice(pos, 1);\n }\n if (!detectedControls[c].groupNames.length) {\n detectedControls.splice(c, 1);\n }\n }\n }\n }\n });\n } else {\n // delete it from detected controls to avoid endless loop\n detectedControls.splice(0, 1);\n // neither room nor smart name\n this.log.debug(`Control of type [${control.type}] has neither room no smart name. Skipped.`);\n }\n\n if (iteration > 1000) {\n this.log.error(\n `too many iterations while collecting devices. Stopping to avoid endless loop: ${JSON.stringify(detectedControls)}`,\n );\n break;\n }\n }\n\n // done\n this.log.debug(`finished collecting devices. there is/are ${this.devices.length} device(s) in total`);\n for (const device of this.devices) {\n this.log.debug(`${device.toString()}`);\n }\n\n // a new discovery process is needed in case we had already devices and device collection was\n // triggered again by, e.g., a change in room/function enums\n // if (discoveryNeeded) {\n // this.log.info(`Please delete all managed by ioBroker devices in your Alexa app and then start discovery`);\n // }\n\n // collect all relevant states to subscribe to updates\n const stateIds = new Set(\n this.devices\n .flatMap(d => d.controls)\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .map(item => item.getId)\n .filter(id => id),\n );\n this.log.debug(`registering for updates of total ${stateIds.size} states`);\n const newSubscribed = Array.from(stateIds);\n const subscribe: string[] = [];\n for (const id of newSubscribed) {\n this.log.silly(`subscribing to updates of ${id}`);\n if (!this.subscribed.includes(id)) {\n this.subscribed.push(id);\n if (!subscribe.includes(id)) {\n subscribe.push(id);\n }\n }\n }\n\n this.subscribed.sort();\n\n // wait till all promises are settled\n if (subscribe.length) {\n await AdapterProvider.subscribe(subscribe);\n }\n\n // unsubscribe from unused states\n const unsubscribe: string[] = [];\n for (let i = this.subscribed.length - 1; i >= 0; i--) {\n const id = this.subscribed[i];\n if (!newSubscribed.includes(id)) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n this.subscribed.splice(i, 1);\n if (!unsubscribe.includes(id)) {\n unsubscribe.push(id);\n }\n }\n }\n if (unsubscribe.length) {\n await AdapterProvider.unsubscribe(unsubscribe);\n }\n } catch (e) {\n this.log.error(`failed to collect devices: ${e}`);\n if (e.stack) {\n this.log.error(e.stack);\n }\n }\n\n this.collecting = false;\n\n // if during the collection a new collection was triggered, start collecting again\n if (this.recollect) {\n this.recollect = false;\n setTimeout(() => this.collectEndpoints(), 1000);\n }\n }\n\n async destroy(): Promise<void> {\n const promises = [];\n for (const id of this.subscribed) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n promises.push(AdapterProvider.subscribe(id));\n }\n await Promise.allSettled(promises);\n\n this.subscribed = [];\n }\n\n publishStateChange(stateChange: AlexaResponse): void {\n if (this.eventsPausedTill < Date.now()) {\n this.log.silly(`publishing ${JSON.stringify(stateChange)}`);\n IotProxy.publishStateChange(stateChange);\n }\n }\n\n pauseEvents(): void {\n this.eventsPausedTill = Date.now() + 30 * 60 * 1000; // 30 minutes\n }\n\n async executeWithinRateLimits(\n endpointId: AlexaV3EndpointID,\n awaitable: () => Promise<AlexaResponse>,\n errorResponse: AlexaResponse,\n ): Promise<AlexaResponse> {\n try {\n await RateLimiter.incrementAndGet(endpointId);\n return await awaitable();\n } catch (error) {\n if (error instanceof OverallDailyRateLimitExceeded || error instanceof HourlyDeviceRateLimitExceeded) {\n this.log.warn(error.message);\n } else {\n this.log.error(error.message);\n }\n\n return errorResponse;\n }\n }\n\n async handleAlexaEvent(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`incoming Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n if (!event?.directive?.header) {\n throw new Error('Alexa event header is missing');\n }\n\n let response: AlexaResponse;\n const directive = this.matchDirective(event);\n if (directive) {\n response = await directive.handle(event, this);\n } else {\n const endpointId = event?.directive?.endpoint?.endpointId;\n const device = endpointId ? this.endpointById(endpointId) : undefined;\n\n if (device) {\n if (device.supports(event)) {\n response = await this.executeWithinRateLimits(\n endpointId!,\n async () => {\n response = await device.handle(event);\n if (!AlexaResponse.isErrorResponse(response)) {\n // report state change via voice interaction\n const propertyName = response.context?.properties[0].name;\n const responseEvent = ChangeReport.get(\n device.id,\n propertyName || '',\n false,\n event.directive.header.messageId,\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n // get device state (not just one control)\n const deviceState = await device.reportState();\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n // fire state change report to Alexa\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n this.publishStateChange(stateChange);\n }\n await this.informAboutStatesChange();\n } else {\n this.log.debug(\n `ignoring state change event for ${endpointId} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n return response;\n },\n AlexaResponse.throttlingException(event.directive.header.messageId).get(),\n );\n } else {\n response = AlexaResponse.directiveNotSupportedByDevice(\n device.friendlyName,\n event.directive.header.namespace,\n event.directive.header.messageId,\n event.directive.header.payloadVersion,\n ).get();\n }\n } else {\n response = AlexaResponse.endpointUnreachable(event.directive.header.messageId).get();\n }\n }\n\n this.log.silly(`response: ${JSON.stringify(response)}`);\n return response;\n }\n\n async handleStateUpdate(id: string, state: ioBroker.State | null | undefined): Promise<void> {\n // ignore updates not confirmed by a corresponding device\n if (!state?.ack) {\n this.log.silly(`ignoring state change event for ${id} due to state.ack == ${state?.ack}`);\n return;\n }\n if (id.startsWith(`${AdapterProvider.get().namespace}.`)) {\n // nop, this is just to inform Alexa app about changes\n return;\n }\n\n let notFound = true;\n\n for (const device of this.devices) {\n const property = device.controls\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .find(item => item.getId === id);\n\n if (property) {\n notFound = false;\n if (property.currentValue === state.val) {\n this.log.debug(`ignoring state change event for ${id} due to the same value [${state.val}]`);\n } else {\n property.currentValue = state.val;\n\n const responseEvent = Directives.ChangeReport.get(\n device.id,\n property.propertyName,\n true,\n randomUUID(),\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n\n // get device state (not just one control)\n const deviceState = await device.reportState();\n\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n await this.informAboutStatesChange();\n // fire state change report to Alexa\n\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n await this.executeWithinRateLimits(\n device.id,\n () => {\n this.publishStateChange(stateChange);\n return Promise.resolve(stateChange);\n },\n AlexaResponse.throttlingException(responseEvent.directive.header.messageId).get(),\n );\n }\n } else {\n this.log.debug(\n `ignoring state change event for ${id} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n\n // should be the only device having the id => stop processing here\n break;\n }\n }\n\n // this should never happen\n if (notFound) {\n this.log.debug(`state id ${id} doesn't belong to any device`);\n }\n }\n}\n"]}
@@ -49,7 +49,9 @@ exports.isValidSmartName = isValidSmartName;
49
49
  exports.defaultIfNullOrEmpty = defaultIfNullOrEmpty;
50
50
  exports.controls = controls;
51
51
  exports.normalize_0_100 = normalize_0_100;
52
+ exports.normalize_0_1 = normalize_0_1;
52
53
  exports.denormalize_0_100 = denormalize_0_100;
54
+ exports.denormalize_0_1 = denormalize_0_1;
53
55
  exports.distinctByPropertyName = distinctByPropertyName;
54
56
  exports.className = className;
55
57
  exports.ensureValueInRange_0_100 = ensureValueInRange_0_100;
@@ -323,8 +325,10 @@ async function controls(adapter, lang) {
323
325
  const list = [];
324
326
  // fetch all objects (states, channels and devices in terms of iobroker)
325
327
  const devicesObject = await allObjects(adapter);
328
+ adapter.log.debug(`[ALEXA3] Starting control detection with ${Object.keys(devicesObject).length} objects...`);
326
329
  // fetch all defined rooms and functions (enumerations)
327
330
  const [functionalities, rooms] = await functionalitiesAndRooms(adapter);
331
+ adapter.log.debug(`[ALEXA3] Found ${functionalities.length} functionalities and ${rooms.length} rooms...`);
328
332
  // every member of a function enumeration is added to the list of ids to inspect
329
333
  functionalities.forEach(functionEnumItem => {
330
334
  functionEnumItem?.common?.members?.forEach(id => {
@@ -394,6 +398,7 @@ async function controls(adapter, lang) {
394
398
  });
395
399
  // all ids, i.e. ids of all iobroker states/channels/devices
396
400
  const keys = Object.keys(devicesObject).sort();
401
+ adapter.log.debug(`[ALEXA3] collected ${keys.length} states from categories...`);
397
402
  const idsWithSmartName = [];
398
403
  // if a state has got a smart name directly assigned and neither itself nor its channel is in the list, add its id to the inspection list
399
404
  // and process it first
@@ -407,6 +412,7 @@ async function controls(adapter, lang) {
407
412
  idsWithSmartName.push(id);
408
413
  }
409
414
  });
415
+ adapter.log.debug(`[ALEXA3] collected ${keys.length} smart names...`);
410
416
  // collect first all smart names and remove them from the auto-groups
411
417
  const detectedControls = [];
412
418
  const detector = new type_detector_1.default();
@@ -659,6 +665,7 @@ async function controls(adapter, lang) {
659
665
  }
660
666
  options.ignoreEnums = false;
661
667
  options.detectAllPossibleDevices = false;
668
+ adapter.log.debug(`[ALEXA3] collected ${detectedControls.length} controls`);
662
669
  // go other the list of IDs to inspect and collect the detected controls
663
670
  list.forEach(id => {
664
671
  options.id = id;
@@ -735,6 +742,7 @@ async function controls(adapter, lang) {
735
742
  }
736
743
  });
737
744
  });
745
+ adapter.log.debug(`[ALEXA3] sorted ${detectedControls.length} controls`);
738
746
  return detectedControls;
739
747
  }
740
748
  /**
@@ -752,6 +760,17 @@ function normalize_0_100(value, min, max, noRound) {
752
760
  }
753
761
  return min >= max || value < min || value > max ? undefined : Math.round(((value - min) / (max - min)) * 100);
754
762
  }
763
+ /**
764
+ * Normalizes any provided value with observed min and max to the range 0..1
765
+ *
766
+ * @param value value to be normalized
767
+ * @param min min observed (possible) value
768
+ * @param max max observed (possible) value
769
+ * @returns Normalized value in the range 0..100 or undefined on invalid input
770
+ */
771
+ function normalize_0_1(value, min, max) {
772
+ return min >= max || value < min || value > max ? undefined : (value - min) / (max - min);
773
+ }
755
774
  /**
756
775
  * Denormalizes any provided value from range 0..100 to the min..max range
757
776
  *
@@ -769,6 +788,21 @@ function denormalize_0_100(normalized, min, max, noRound) {
769
788
  ? undefined
770
789
  : Math.round((normalized / 100) * (max - min) + min);
771
790
  }
791
+ /**
792
+ * Denormalizes any provided value from range 0..1 to the min..max range
793
+ *
794
+ * @param normalized normalized value
795
+ * @param min min observed (possible) value
796
+ * @param max max observed (possible) value
797
+ * @param noRound do not round the result
798
+ * @returns Denormalized value in the range min-max
799
+ */
800
+ function denormalize_0_1(normalized, min, max, noRound) {
801
+ if (noRound) {
802
+ return min >= max || normalized < 0 || normalized > 1 ? undefined : normalized * (max - min) + min;
803
+ }
804
+ return min >= max || normalized < 0 || normalized > 1 ? undefined : Math.round(normalized * (max - min) + min);
805
+ }
772
806
  /**
773
807
  * Returns distinct objects in a list based on values of the provided property name
774
808
  *