iobroker.iot 5.0.12 → 5.0.13
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.
- package/LICENSE +1 -1
- package/README.md +6 -6
- package/admin/assets/index-CJ_AWUR4.css +1 -0
- package/admin/assets/index-DCr4hGKK.js +705 -0
- package/admin/index_m.html +2 -2
- package/admin/rules/@mf-types/ActionVisu.d.ts +2 -0
- package/admin/rules/@mf-types/compiled-types/ActionVisu.d.ts +29 -0
- package/admin/rules/@mf-types.d.ts +3 -0
- package/admin/rules/@mf-types.zip +0 -0
- package/admin/rules/assets/ActionVisu-BN0Kjfo9.js +5 -0
- package/admin/rules/assets/ActionVisu__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.js-D5qEIjqV.js +1 -0
- package/admin/rules/assets/ActionVisu__loadShare__react__loadShare__.js-aa1tDx2C.js +1 -0
- package/admin/rules/assets/ActionVisu__loadShare__react__loadShare__.js_commonjs-proxy-DX6cx281.js +1 -0
- package/admin/rules/assets/ActionVisu__loadShare__react_mf_2_dom__loadShare__.js-uY2qDezJ.js +1 -0
- package/admin/rules/assets/ActionVisu__loadShare__react_mf_2_dom__loadShare__.js_commonjs-proxy-27bLZRGy.js +1 -0
- package/admin/rules/assets/bootstrap-QjsDSZNA.js +1 -0
- package/admin/rules/assets/hostInit-CoWylRge.js +1 -0
- package/admin/rules/assets/index-C1ZEp-2N.js +2 -0
- package/admin/rules/assets/index-Ccpql4vu.js +1 -0
- package/admin/rules/assets/{index-DAfe9TMn.js → index-DiSsXjpZ.js} +4 -20
- package/admin/rules/assets/index-FrXvyqvW.js +1187 -0
- package/admin/rules/assets/jsx-runtime-CnsYFZsa.js +1 -0
- package/admin/rules/assets/localSharedImportMap-8wECk2hR.js +1 -0
- package/admin/rules/assets/virtualExposes-b6CxLzZb.js +1 -0
- package/admin/rules/customRuleBlocks.js +7 -2
- package/admin/rules/mf-stats.json +1 -0
- package/build/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/EndpointHealth.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/EndpointHealth.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Control.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Controls/Control.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Device.js +3 -3
- package/build/lib/AlexaSmartHomeV3/Device.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js +2 -1
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -1
- package/build/lib/alisa.js +4 -4
- package/build/main.js +35 -64
- package/build/main.js.map +1 -1
- package/io-package.json +14 -14
- package/package.json +13 -14
- package/admin/assets/index-Bd3GtHgn.css +0 -1
- package/admin/assets/index-jI5Tax_m.js +0 -766
- package/admin/rules/assets/ActionVisu-BvWg4aqg.js +0 -5
- package/admin/rules/assets/ActionVisu__loadShare__react__loadShare__-5Bv9wGPU.js +0 -1
- package/admin/rules/assets/ActionVisu__loadShare__react_mf_2_dom__loadShare__-DUk47PjY.js +0 -9
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-BUkKpfUR.js +0 -1
- package/admin/rules/assets/_commonjsHelpers-Cpj98o6Y.js +0 -1
- package/admin/rules/assets/bootstrap-BPw119x4.js +0 -1
- package/admin/rules/assets/hostInit-Dxp6BaAc.js +0 -2
- package/admin/rules/assets/index-Do-nCdWy.js +0 -9
- package/admin/rules/assets/index-NkHakkqA.js +0 -2
- package/admin/rules/assets/index-iefDESue.js +0 -1152
- package/admin/rules/assets/index.cjs-DyuWoUPi.js +0 -8
- package/admin/rules/assets/virtualExposes-BQXgT6g9.js +0 -2
- package/build/lib/alexaSmartHomeV2.js +0 -2788
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Control.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Control.ts"],"names":[],"mappings":";;;;;AAEA,2EAAmD;AACnD,4CAAiH;AACjH,+DAAuC;AACvC,iFAAyD;AAEzD,gFAAwD;AACxD,wFAAgE;AAmChE;;;GAGG;AACH,MAAqB,OAAO;IACxB,MAAM,CAAC,SAAS,GAAgB;QAC5B,QAAQ;QACR,MAAM;QACN,YAAY;QACZ,QAAQ;QACR,OAAO;QACP,KAAK;QACL,MAAM;QACN,MAAM;QACN,IAAI;QACJ,WAAW;QACX,QAAQ;QACR,OAAO;QACP,KAAK;QACL,KAAK;QACL,MAAM;QACN,YAAY;QACZ,QAAQ;QACR,KAAK;QACL,aAAa;QACb,SAAS;QACT,OAAO;KACV,CAAC;IACc,GAAG,CAAS;IAClB,UAAU,CAAqB;IAC/B,SAAS,CAAqB;IACrB,OAAO,GAAyD,EAAE,CAAC;IAC5E,SAAS,CAAwB;IAE3C;;OAEG;IACH,YAAY,eAA0C;QAClD,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACnC,iBAAiB;QACjB,MAAM,kBAAkB,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,kBAAkB,EAAE,SAAS,CAAC;QAE/C,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;Q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AAgC,UAAiC;gBAC1E,OAAO,CACH,IAAA,yBAAiB,EAAC,UAAoB,EAAE,IAAI,CAAC,YAAsB,EAAE,IAAI,CAAC,YAAsB,CAAC;oBACjG,CAAC,CACJ,CAAC;YACN,CAAC;YACD,WAAW,EAAE,UAET,KAAsC;gBAEtC,OAAO,IAAA,uBAAe,EAAC,KAAe,EAAE,IAAI,CAAC,YAAsB,EAAE,IAAI,CAAC,YAAsB,CAAC,CAAC;YACtG,CAAC;YACD,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,CAAC;;AAzZL,0BA0ZC","sourcesContent":["import type { Types } from '@iobroker/type-detector';\n\nimport AlexaResponse from '../Alexa/AlexaResponse';\nimport { firstLower, className, denormalize_0_100, normalize_0_100, ensureValueInRange } from '../Helpers/Utils';\nimport Logger from '../Helpers/Logger';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport type { ControlStateInitObject, Base as PropertiesBase } from '../Alexa/Properties/Base';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport DetectionState from '../Alexa/Properties/DetectionState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ReportedState,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n SmartName,\n} from '../types';\nimport type { Base as CapabilitiesBase } from '../Alexa/Capabilities/Base';\n\nexport type StateName =\n | 'ACTUAL'\n | 'BLUE'\n | 'BRIGHTNESS'\n | 'DIMMER'\n | 'GREEN'\n | 'HUE'\n | 'MODE'\n | 'MUTE'\n | 'ON'\n | 'ON_ACTUAL'\n | 'ON_SET'\n | 'POWER'\n | 'RED'\n | 'RGB'\n | 'RGBW'\n | 'SATURATION'\n | 'SECOND'\n | 'SET'\n | 'TEMPERATURE'\n | 'UNREACH'\n | 'WHITE';\n\n/**\n * Represents the base functionality for a control in a smart device. A smart device has at least one control.\n * The specific functionality, natively supported capabilities, etc. are defined in derived classes.\n */\nexport default class Control {\n static stateKeys: StateName[] = [\n 'ACTUAL',\n 'BLUE',\n 'BRIGHTNESS',\n 'DIMMER',\n 'GREEN',\n 'HUE',\n 'MODE',\n 'MUTE',\n 'ON',\n 'ON_ACTUAL',\n 'ON_SET',\n 'POWER',\n 'RED',\n 'RGB',\n 'RGBW',\n 'SATURATION',\n 'SECOND',\n 'SET',\n 'TEMPERATURE',\n 'UNREACH',\n 'WHITE',\n ];\n public readonly log: Logger;\n protected _supported: CapabilitiesBase[];\n protected _enforced: CapabilitiesBase[];\n protected readonly _states: Record<string, IotExternalDetectorState | undefined> = {};\n protected smartName: SmartName | undefined;\n\n /**\n * @param detectedControl - The detected control in terms of iobroker type detector.\n */\n constructor(detectedControl: IotExternalPatternControl) {\n this.log = new Logger(this);\n this.log.silly(`created instance`);\n // find smartName\n const stateWithSmartName = detectedControl.states.find(s => s.smartName);\n this.smartName = stateWithSmartName?.smartName;\n\n this.initStates(detectedControl);\n this._supported = [];\n this._enforced = [];\n }\n\n get allCapabilities(): CapabilitiesBase[] {\n return this.supported.concat(this.enforced);\n }\n\n static get type(): Types {\n return firstLower(className(this.toString())) as Types;\n }\n /**\n * Getter for Alexa categories\n */\n get categories(): AlexaV3Category[] {\n return ['OTHER'];\n }\n\n get name(): string {\n return `${this.constructor.name}`;\n }\n /**\n * Getter for _supported\n */\n get supported(): CapabilitiesBase[] {\n return this._supported;\n }\n /**\n * Getter for _enforced\n */\n get enforced(): CapabilitiesBase[] {\n return this._enforced;\n }\n /**\n * This function returns whether the control natively supports the passed on Alexa directive.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control natively supports the directive, false - otherwise\n */\n supports(event: AlexaV3Request): boolean {\n return this.supported.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function returns whether the control though doesn't natively support the passed on Alexa directive, but able to handle it.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control can handle the directive, false - otherwise\n */\n canHandle(event: AlexaV3Request): boolean {\n return this.enforced.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value\n * as a reaction to an interaction with Alexa via voice, app, etc.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns Object containing the response to be sent to Alexa Service\n */\n async handle(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`handling Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n\n const properties = this.allCapabilities\n .flatMap(item => item.properties)\n .filter(property => property.matches(event));\n\n let response: AlexaResponse | null = null;\n\n for (const property of properties) {\n let alexaValue: AlexaV3DirectiveValue;\n try {\n const setter = this.valueSetter(event);\n alexaValue = await setter(event, property);\n } catch (error) {\n this.log.debug(`${error}`);\n this.log.error(`failed handling Alexa event`);\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(AlexaResponse.endpointUnreachable(event.directive.header.messageId).get());\n }\n\n // even though the handler successfully processed the Alexa event,\n // we return an error here for ENFORCED capabilities, to prevent\n // reporting multiple successes for the same capability and\n // running into a situation of returning a wrong value back to Alexa\n if (this.enforced.find(capability => capability.matches(event))) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(\n AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n ).get(),\n );\n }\n\n if (alexaValue !== undefined) {\n if (!response) {\n response = AlexaResponse.handled(\n event,\n property.propertyName,\n property.reportValue(alexaValue),\n property.instance,\n );\n } else {\n response.addContextProperty({\n namespace: event?.directive?.header?.namespace,\n name: property.propertyName,\n instance: property.instance,\n value: property.reportValue(alexaValue),\n });\n }\n }\n\n // though the processed directive required to change a single value, the response must contain values of all \"relevant\" properties\n // Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event\n }\n\n if (response) {\n this.log.silly(`${JSON.stringify(response.get())}`);\n return response.get();\n }\n\n const errorResponse = AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n );\n this.log.silly(`${JSON.stringify(errorResponse.get())}`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(errorResponse.get());\n }\n\n valueSetter(\n _event: AlexaV3Request,\n ): (event: AlexaV3Request, property: PropertiesBase) => Promise<AlexaV3DirectiveValue> {\n return this.setValue.bind(this);\n }\n\n async setValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract alexa value from event\n const alexaValue = property.alexaDirectiveValue(event);\n\n // convert alexa value to iobroker value\n let value: ioBroker.StateValue | undefined = property.value(alexaValue);\n\n // if set, the device could support toggle\n if (event.currentState) {\n // console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);\n const state = event.currentState.find(item => item.name === property.propertyName);\n if (state && value === true) {\n // it could support toggle.\n // get current value\n const current = property.value(state.value);\n if (current === true) {\n // turn off\n value = false;\n } else if (current !== false) {\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n if (currentValue === true) {\n // turn off\n value = false;\n }\n }\n }\n }\n\n // set iobroker state\n if (value !== undefined) {\n await this.setState(property, value);\n property.currentValue = value;\n // return value as expected by Alexa\n return property.alexaValue(value);\n }\n return undefined;\n }\n\n async adjustValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract Alexa delta value from event\n const delta = property.alexaDirectiveValue(event);\n // get current value\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n // convert the current value to Alexa value\n const valueToAdjust = property.alexaValue(currentValue);\n // adjust Alexa value\n const adjustedValue = ensureValueInRange(\n parseFloat((valueToAdjust as string) || '0') + parseFloat((delta as string) || '0'),\n property.valuesRangeMin as number,\n property.valuesRangeMax as number,\n );\n // convert adjusted value to iobroker value\n const value = property.value(adjustedValue);\n\n // set iobroker state\n await this.setState(property, value as ioBroker.StateValue);\n\n return adjustedValue;\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n if (property.currentValue === undefined) {\n const id = property.getId;\n if (!id && property.propertyName === 'connectivity') {\n // this is an exception\n property.currentValue = false;\n } else {\n if (!id) {\n throw new Error(`no ID defined for property \"${property.propertyName}\" of \"${this.name}\"`);\n }\n property.currentValue = await AdapterProvider.getState(id);\n }\n }\n\n if (property.currentValue === undefined) {\n throw new Error(`unable to retrieve ${property.getId}`);\n }\n\n return property.currentValue;\n }\n\n async reportState(): Promise<AlexaV3ReportedState[]> {\n const propertiesToReport: AlexaV3ReportedState[] = [];\n\n for (const capability of this.supported) {\n for (const property of capability.properties) {\n try {\n await this.getOrRetrieveCurrentValue(property);\n\n const toReport: AlexaV3ReportedState = {\n namespace: capability.namespace,\n instance: property.instance,\n name: property.propertyName,\n value: property.reportValue(property.alexaValue(property.currentValue)),\n };\n\n if (!toReport.instance) {\n delete toReport.instance;\n }\n\n propertiesToReport.push(toReport);\n } catch (error) {\n this.log.error(`failed reporting state for property \"${property.propertyName}\" of \"${this.name}\"`);\n if (error.stack) {\n this.log.debug(`${error.stack}`);\n }\n this.log.debug(`${error}`);\n }\n }\n }\n\n this.log.debug(`reporting state: ${JSON.stringify(propertiesToReport)}`);\n return propertiesToReport;\n }\n\n toString(): string {\n return `${this.constructor.name}`;\n }\n\n private initStates(ctrl: IotExternalPatternControl): void {\n for (const stateKey of Control.stateKeys) {\n this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);\n }\n }\n\n get states(): Record<string, IotExternalDetectorState | undefined> {\n return this._states;\n }\n\n get statesMap(): { [lowCaseName: string]: StateName } {\n const map: { [lowCaseName: string]: StateName } = {};\n for (const stateKey of Control.stateKeys) {\n map[stateKey.toLowerCase()] = stateKey;\n }\n return map;\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\n\n //-------------------------------------------------------\n // standard property init objects\n //\n\n protected blankInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n };\n }\n\n protected connectivityInitObject(alwaysReturn?: boolean): ControlStateInitObject | null {\n const map = this.statesMap;\n const state = this.states[map.unreach];\n if (state?.id.toLowerCase().includes('sticky_')) {\n state.id = state.id.replace(/\\.sticky_/i, '');\n }\n if (!state) {\n if (alwaysReturn) {\n return {\n getState: { id: '', smartName: '', common: {}, name: 'UNREACH' },\n setState: { id: '', smartName: '', common: {}, name: 'UNREACH' },\n };\n }\n return null;\n }\n return {\n setState: this.states[map.unreach],\n getState: this.states[map.unreach],\n };\n }\n\n protected powerStateInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual] || this.states[map.set]!,\n alexaSetter: function (alexaValue) {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n protected detectedStateInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (_alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n // should be never called\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? DetectionState.DETECTED : DetectionState.NOT_DETECTED;\n },\n };\n }\n\n protected percentageInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n // const range = configuredRangeOrDefault(this.states[map.set]);\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(alexaValue as number, this.valueRealMin as number, this.valueRealMax as number) ||\n 0\n );\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return normalize_0_100(value as number, this.valueRealMin as number, this.valueRealMax as number);\n },\n percentage: true,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Control.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Control.ts"],"names":[],"mappings":";;;;;AAEA,2EAAmD;AACnD,4CAAiH;AACjH,+DAAuC;AACvC,iFAAyD;AAEzD,gFAAwD;AACxD,wFAAgE;AAmChE;;;GAGG;AACH,MAAqB,OAAO;IACxB,MAAM,CAAC,SAAS,GAAgB;QAC5B,QAAQ;QACR,MAAM;QACN,YAAY;QACZ,QAAQ;QACR,OAAO;QACP,KAAK;QACL,MAAM;QACN,MAAM;QACN,IAAI;QACJ,WAAW;QACX,QAAQ;QACR,OAAO;QACP,KAAK;QACL,KAAK;QACL,MAAM;QACN,YAAY;QACZ,QAAQ;QACR,KAAK;QACL,aAAa;QACb,SAAS;QACT,OAAO;KACV,CAAC;IACc,GAAG,CAAS;IAClB,UAAU,CAAqB;IAC/B,SAAS,CAAqB;IACrB,OAAO,GAAyD,EAAE,CAAC;IAC5E,SAAS,CAAwB;IAE3C;;OAEG;IACH,YAAY,eAA0C;QAClD,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACnC,iBAAiB;QACjB,MAAM,kBAAkB,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,kBAAkB,EAAE,SAAS,CAAC;QAE/C,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,IA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,YAAsB,CAAC;oBACjG,CAAC,CACJ,CAAC;YACN,CAAC;YACD,WAAW,EAAE,UAET,KAAsC;gBAEtC,OAAO,IAAA,uBAAe,EAAC,KAAe,EAAE,IAAI,CAAC,YAAsB,EAAE,IAAI,CAAC,YAAsB,CAAC,CAAC;YACtG,CAAC;YACD,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,CAAC;;AAzZL,0BA0ZC","sourcesContent":["import type { Types } from '@iobroker/type-detector';\n\nimport AlexaResponse from '../Alexa/AlexaResponse';\nimport { firstLower, className, denormalize_0_100, normalize_0_100, ensureValueInRange } from '../Helpers/Utils';\nimport Logger from '../Helpers/Logger';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport type { ControlStateInitObject, Base as PropertiesBase } from '../Alexa/Properties/Base';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport DetectionState from '../Alexa/Properties/DetectionState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ReportedState,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n SmartName,\n} from '../types';\nimport type { Base as CapabilitiesBase } from '../Alexa/Capabilities/Base';\n\nexport type StateName =\n | 'ACTUAL'\n | 'BLUE'\n | 'BRIGHTNESS'\n | 'DIMMER'\n | 'GREEN'\n | 'HUE'\n | 'MODE'\n | 'MUTE'\n | 'ON'\n | 'ON_ACTUAL'\n | 'ON_SET'\n | 'POWER'\n | 'RED'\n | 'RGB'\n | 'RGBW'\n | 'SATURATION'\n | 'SECOND'\n | 'SET'\n | 'TEMPERATURE'\n | 'UNREACH'\n | 'WHITE';\n\n/**\n * Represents the base functionality for a control in a smart device. A smart device has at least one control.\n * The specific functionality, natively supported capabilities, etc. are defined in derived classes.\n */\nexport default class Control {\n static stateKeys: StateName[] = [\n 'ACTUAL',\n 'BLUE',\n 'BRIGHTNESS',\n 'DIMMER',\n 'GREEN',\n 'HUE',\n 'MODE',\n 'MUTE',\n 'ON',\n 'ON_ACTUAL',\n 'ON_SET',\n 'POWER',\n 'RED',\n 'RGB',\n 'RGBW',\n 'SATURATION',\n 'SECOND',\n 'SET',\n 'TEMPERATURE',\n 'UNREACH',\n 'WHITE',\n ];\n public readonly log: Logger;\n protected _supported: CapabilitiesBase[];\n protected _enforced: CapabilitiesBase[];\n protected readonly _states: Record<string, IotExternalDetectorState | undefined> = {};\n protected smartName: SmartName | undefined;\n\n /**\n * @param detectedControl - The detected control in terms of iobroker type detector.\n */\n constructor(detectedControl: IotExternalPatternControl) {\n this.log = new Logger(this);\n this.log.silly(`created instance`);\n // find smartName\n const stateWithSmartName = detectedControl.states.find(s => s.smartName);\n this.smartName = stateWithSmartName?.smartName;\n\n this.initStates(detectedControl);\n this._supported = [];\n this._enforced = [];\n }\n\n get allCapabilities(): CapabilitiesBase[] {\n return this.supported.concat(this.enforced);\n }\n\n static get type(): Types {\n return firstLower(className(this.toString())) as Types;\n }\n /**\n * Getter for Alexa categories\n */\n get categories(): AlexaV3Category[] {\n return ['OTHER'];\n }\n\n get name(): string {\n return `${this.constructor.name}`;\n }\n /**\n * Getter for _supported\n */\n get supported(): CapabilitiesBase[] {\n return this._supported;\n }\n /**\n * Getter for _enforced\n */\n get enforced(): CapabilitiesBase[] {\n return this._enforced;\n }\n /**\n * This function returns whether the control natively supports the passed on Alexa directive.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control natively supports the directive, false - otherwise\n */\n supports(event: AlexaV3Request): boolean {\n return this.supported.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function returns whether the control, though doesn't natively support the passed on Alexa directive, but able to handle it.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control can handle the directive, false - otherwise\n */\n canHandle(event: AlexaV3Request): boolean {\n return this.enforced.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value\n * as a reaction to an interaction with Alexa via voice, app, etc.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns Object containing the response to be sent to Alexa Service\n */\n async handle(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`handling Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n\n const properties = this.allCapabilities\n .flatMap(item => item.properties)\n .filter(property => property.matches(event));\n\n let response: AlexaResponse | null = null;\n\n for (const property of properties) {\n let alexaValue: AlexaV3DirectiveValue;\n try {\n const setter = this.valueSetter(event);\n alexaValue = await setter(event, property);\n } catch (error) {\n this.log.debug(`${error}`);\n this.log.error(`failed handling Alexa event`);\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(AlexaResponse.endpointUnreachable(event.directive.header.messageId).get());\n }\n\n // even though the handler successfully processed the Alexa event,\n // we return an error here for ENFORCED capabilities, to prevent\n // reporting multiple successes for the same capability and\n // running into a situation of returning a wrong value back to Alexa\n if (this.enforced.find(capability => capability.matches(event))) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(\n AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n ).get(),\n );\n }\n\n if (alexaValue !== undefined) {\n if (!response) {\n response = AlexaResponse.handled(\n event,\n property.propertyName,\n property.reportValue(alexaValue),\n property.instance,\n );\n } else {\n response.addContextProperty({\n namespace: event?.directive?.header?.namespace,\n name: property.propertyName,\n instance: property.instance,\n value: property.reportValue(alexaValue),\n });\n }\n }\n\n // though the processed directive required changing a single value, the response must contain values of all \"relevant\" properties\n // Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event\n }\n\n if (response) {\n this.log.silly(`${JSON.stringify(response.get())}`);\n return response.get();\n }\n\n const errorResponse = AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n );\n this.log.silly(`${JSON.stringify(errorResponse.get())}`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(errorResponse.get());\n }\n\n valueSetter(\n _event: AlexaV3Request,\n ): (event: AlexaV3Request, property: PropertiesBase) => Promise<AlexaV3DirectiveValue> {\n return this.setValue.bind(this);\n }\n\n async setValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract alexa value from event\n const alexaValue = property.alexaDirectiveValue(event);\n\n // convert alexa value to iobroker value\n let value: ioBroker.StateValue | undefined = property.value(alexaValue);\n\n // if set, the device could support toggle\n if (event.currentState) {\n // console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);\n const state = event.currentState.find(item => item.name === property.propertyName);\n if (state && value === true) {\n // it could support toggle.\n // get current value\n const current = property.value(state.value);\n if (current === true) {\n // turn off\n value = false;\n } else if (current !== false) {\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n if (currentValue === true) {\n // turn off\n value = false;\n }\n }\n }\n }\n\n // set iobroker state\n if (value !== undefined) {\n await this.setState(property, value);\n property.currentValue = value;\n // return value as expected by Alexa\n return property.alexaValue(value);\n }\n return undefined;\n }\n\n async adjustValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract Alexa delta value from event\n const delta = property.alexaDirectiveValue(event);\n // get current value\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n // convert the current value to Alexa value\n const valueToAdjust = property.alexaValue(currentValue);\n // adjust Alexa value\n const adjustedValue = ensureValueInRange(\n parseFloat((valueToAdjust as string) || '0') + parseFloat((delta as string) || '0'),\n property.valuesRangeMin as number,\n property.valuesRangeMax as number,\n );\n // convert adjusted value to iobroker value\n const value = property.value(adjustedValue);\n\n // set iobroker state\n await this.setState(property, value as ioBroker.StateValue);\n\n return adjustedValue;\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n if (property.currentValue === undefined) {\n const id = property.getId;\n if (!id && property.propertyName === 'connectivity') {\n // this is an exception\n property.currentValue = false;\n } else {\n if (!id) {\n throw new Error(`no ID defined for property \"${property.propertyName}\" of \"${this.name}\"`);\n }\n property.currentValue = await AdapterProvider.getState(id);\n }\n }\n\n if (property.currentValue === undefined) {\n throw new Error(`unable to retrieve ${property.getId}`);\n }\n\n return property.currentValue;\n }\n\n async reportState(): Promise<AlexaV3ReportedState[]> {\n const propertiesToReport: AlexaV3ReportedState[] = [];\n\n for (const capability of this.supported) {\n for (const property of capability.properties) {\n try {\n await this.getOrRetrieveCurrentValue(property);\n\n const toReport: AlexaV3ReportedState = {\n namespace: capability.namespace,\n instance: property.instance,\n name: property.propertyName,\n value: property.reportValue(property.alexaValue(property.currentValue)),\n };\n\n if (!toReport.instance) {\n delete toReport.instance;\n }\n\n propertiesToReport.push(toReport);\n } catch (error) {\n this.log.error(`failed reporting state for property \"${property.propertyName}\" of \"${this.name}\"`);\n if (error.stack) {\n this.log.debug(`${error.stack}`);\n }\n this.log.debug(`${error}`);\n }\n }\n }\n\n this.log.debug(`reporting state: ${JSON.stringify(propertiesToReport)}`);\n return propertiesToReport;\n }\n\n toString(): string {\n return `${this.constructor.name}`;\n }\n\n private initStates(ctrl: IotExternalPatternControl): void {\n for (const stateKey of Control.stateKeys) {\n this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);\n }\n }\n\n get states(): Record<string, IotExternalDetectorState | undefined> {\n return this._states;\n }\n\n get statesMap(): { [lowCaseName: string]: StateName } {\n const map: { [lowCaseName: string]: StateName } = {};\n for (const stateKey of Control.stateKeys) {\n map[stateKey.toLowerCase()] = stateKey;\n }\n return map;\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\n\n //-------------------------------------------------------\n // standard property init objects\n //\n\n protected blankInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n };\n }\n\n protected connectivityInitObject(alwaysReturn?: boolean): ControlStateInitObject | null {\n const map = this.statesMap;\n const state = this.states[map.unreach];\n if (state?.id.toLowerCase().includes('sticky_')) {\n state.id = state.id.replace(/\\.sticky_/i, '');\n }\n if (!state) {\n if (alwaysReturn) {\n return {\n getState: { id: '', smartName: '', common: {}, name: 'UNREACH' },\n setState: { id: '', smartName: '', common: {}, name: 'UNREACH' },\n };\n }\n return null;\n }\n return {\n setState: this.states[map.unreach],\n getState: this.states[map.unreach],\n };\n }\n\n protected powerStateInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual] || this.states[map.set]!,\n alexaSetter: function (alexaValue) {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n protected detectedStateInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (_alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n // should be never called\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? DetectionState.DETECTED : DetectionState.NOT_DETECTED;\n },\n };\n }\n\n protected percentageInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n // const range = configuredRangeOrDefault(this.states[map.set]);\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(alexaValue as number, this.valueRealMin as number, this.valueRealMax as number) ||\n 0\n );\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return normalize_0_100(value as number, this.valueRealMin as number, this.valueRealMax as number);\n },\n percentage: true,\n };\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
const Utils_1 = require("./Helpers/Utils");
|
|
8
8
|
const Logger_1 = __importDefault(require("./Helpers/Logger"));
|
|
9
9
|
/**
|
|
@@ -32,8 +32,8 @@ class Device {
|
|
|
32
32
|
this.typeWasDetected = opts.typeWasDetected;
|
|
33
33
|
this.possibleTypes = opts.possibleTypes;
|
|
34
34
|
this.log = new Logger_1.default(this);
|
|
35
|
-
this.id = (0, Utils_1.defaultIfNullOrEmpty)((0, Utils_1.endpointId)(opts.id), (0,
|
|
36
|
-
this.friendlyName = (0, Utils_1.defaultIfNullOrEmpty)(opts.friendlyName, (0,
|
|
35
|
+
this.id = (0, Utils_1.defaultIfNullOrEmpty)((0, Utils_1.endpointId)(opts.id), (0, node_crypto_1.randomUUID)());
|
|
36
|
+
this.friendlyName = (0, Utils_1.defaultIfNullOrEmpty)(opts.friendlyName, (0, node_crypto_1.randomUUID)());
|
|
37
37
|
this.controls = (0, Utils_1.defaultIfNullOrEmpty)(opts.controls, []);
|
|
38
38
|
this.autoDetected = !!opts.autoDetected;
|
|
39
39
|
this.roomName = opts.roomName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Device.js","sourceRoot":"","sources":["../../../src/lib/AlexaSmartHomeV3/Device.ts"],"names":[],"mappings":";;;;;AAAA
|
|
1
|
+
{"version":3,"file":"Device.js","sourceRoot":"","sources":["../../../src/lib/AlexaSmartHomeV3/Device.ts"],"names":[],"mappings":";;;;;AAAA,6CAAyC;AAGzC,2CAA2F;AAC3F,8DAAsC;AAMtC;;;;;;;;GAQG;AACH,MAAqB,MAAM;IAChB,GAAG,CAAS;IACZ,EAAE,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BAAsB,EAK1B,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,YAAY;QACZ,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtE,OAAO,IAAA,8BAAsB,EAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,iBAAiB;QACjB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,QAAQ;QACJ,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,MAAM,gBAAgB,GAAG;YACrB,IAAI,IAAI,GAAG,cAAc,CAAC;YAC1B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC1B,IAAI,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;YACnC,CAAC;YACD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAC/B,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;QACF,OAAO,GAAG,IAAI,CAAC,YAAY,GAAG,gBAAgB,EAAE,EAAE,CAAC;IACvD,CAAC;CACJ;AApGD,yBAoGC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport type { Types } from '@iobroker/type-detector';\n\nimport { endpointId, defaultIfNullOrEmpty, distinctByPropertyName } from './Helpers/Utils';\nimport Logger from './Helpers/Logger';\nimport type { AlexaV3Category, AlexaV3Namespace, AlexaV3ReportedState, AlexaV3Request } from './types';\nimport type Control from './Controls/Control';\nimport type { Base as CapabilitiesBase } from './Alexa/Capabilities/Base';\nimport type AlexaResponse from './Alexa/AlexaResponse';\n\n/**\n * This class hides the different iobroker controls representing physical devices from Alexa\n * and makes them appear as a single endpoint.\n * Due to differences in Alexa's and iobroker's endpoint/devices concepts, we have to merge some of the\n * by the type-detector detected controls to a single device, so that multiple controls are considered\n * to be the same endpoint from Alexa's perspective.\n * This leads to a situation where while Alexa believes controlling a single endpoint by sending a directive\n * to change the endpoint's state, in reality, the states of multiple controls, i.e. physical devices, are changed.\n */\nexport default class Device {\n public log: Logger;\n public id: string;\n public friendlyName: string;\n public controls: Control[];\n public autoDetected: boolean;\n public possibleTypes: Types[];\n public typeWasDetected: boolean;\n public roomName?: string;\n public funcName?: string;\n public toggle?: boolean;\n public description?: string;\n public lastReportedState?: any;\n\n constructor(opts: {\n id: string;\n friendlyName: string;\n controls: Control[];\n autoDetected?: boolean;\n roomName?: string;\n funcName?: string;\n toggle?: boolean;\n typeWasDetected: boolean;\n possibleTypes: Types[];\n }) {\n this.typeWasDetected = opts.typeWasDetected;\n this.possibleTypes = opts.possibleTypes;\n this.log = new Logger(this);\n this.id = defaultIfNullOrEmpty<string>(endpointId(opts.id), randomUUID());\n this.friendlyName = defaultIfNullOrEmpty<string>(opts.friendlyName, randomUUID());\n this.controls = defaultIfNullOrEmpty<Control[]>(opts.controls, []);\n this.autoDetected = !!opts.autoDetected;\n this.roomName = opts.roomName;\n this.funcName = opts.funcName;\n this.toggle = opts.toggle;\n }\n\n supports(event: AlexaV3Request): boolean {\n return this.controls.find(c => c.supports(event)) !== undefined;\n }\n\n async handle(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`handling alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n\n const promises: Promise<AlexaResponse>[] = [];\n if (this.toggle) {\n // get current state\n event.currentState = await this.reportState();\n }\n\n this.controls.forEach(control => promises.push(control.handle(event)));\n const results = await Promise.allSettled(promises);\n\n const fulfilled = results.find(item => item.status === 'fulfilled');\n\n return fulfilled !== undefined ? fulfilled.value : (results[0] as any).reason;\n }\n\n async reportState(): Promise<AlexaV3ReportedState[]> {\n const promises: Promise<AlexaV3ReportedState[]>[] = [];\n this.controls.forEach(control => promises.push(control.reportState()));\n const results = await Promise.allSettled(promises);\n\n const properties: {\n namespace: AlexaV3Namespace;\n instance?: string;\n name: string;\n value: any;\n }[] = results.filter(item => item.status === 'fulfilled').flatMap(item => item.value);\n\n return distinctByPropertyName<{\n namespace: AlexaV3Namespace;\n instance?: string;\n name: string;\n value: any;\n }>(properties, 'name', true);\n }\n\n get capabilities(): CapabilitiesBase[] {\n const allCapabilities = this.controls.flatMap(item => item.supported);\n return distinctByPropertyName(allCapabilities, 'namespace');\n }\n\n get displayCategories(): AlexaV3Category[] {\n return Array.from(new Set(this.controls.flatMap(item => item.categories)));\n }\n\n toString(): string {\n const controls = this.controls;\n const controlsAsString = function (): string {\n let repr = ' (Controls: ';\n for (const ctrl of controls) {\n repr += `${ctrl.toString()}, `;\n }\n repr = `${repr.slice(0, -2)})`;\n return repr;\n };\n return `${this.friendlyName}${controlsAsString()}`;\n }\n}\n"]}
|
|
@@ -232,7 +232,8 @@ class DeviceManager {
|
|
|
232
232
|
}
|
|
233
233
|
else if (control.groupNames?.length) {
|
|
234
234
|
// no room, but smart name (not only one)
|
|
235
|
-
control.groupNames
|
|
235
|
+
const names = [...control.groupNames];
|
|
236
|
+
names.forEach(groupName => {
|
|
236
237
|
if (!createdGroups.includes(groupName)) {
|
|
237
238
|
createdGroups.push(groupName);
|
|
238
239
|
processedControls = detectedControls.filter(item => item.groupNames?.includes(groupName));
|
|
@@ -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,wEA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import * 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};\n// const 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 public validTill: number = 0;\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', 2, 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 public setValidTill(validTill: number): void {\n this.validTill = validTill;\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 let iteration = 0;\n\n // First collect all custom friendly names assigned by user\n const customNamedControls: string[] = [];\n for (const control of detectedControls) {\n if (control.groupNames) {\n for (const groupName of control.groupNames) {\n if (!customNamedControls.includes(this.getName(groupName))) {\n customNamedControls.push(this.getName(groupName));\n break;\n }\n }\n }\n }\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 (customNamedControls.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 (customNamedControls.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\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 this.toDevice({\n detectedControls: JSON.parse(JSON.stringify(processedControls)),\n friendlyName: this.getName(groupName),\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 // Be sure, that the processed control is removed\n const index = detectedControls.indexOf(control);\n if (index !== -1) {\n detectedControls.splice(index, 1);\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 if (this.validTill > Date.now() || 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\n // fire state change report to Alexa\n if (this.validTill > Date.now() || 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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;AA5fD,gCA4fC","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};\n// const 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 public validTill: number = 0;\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', 2, 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 public setValidTill(validTill: number): void {\n this.validTill = validTill;\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 let iteration = 0;\n\n // First collect all custom friendly names assigned by user\n const customNamedControls: string[] = [];\n for (const control of detectedControls) {\n if (control.groupNames) {\n for (const groupName of control.groupNames) {\n if (!customNamedControls.includes(this.getName(groupName))) {\n customNamedControls.push(this.getName(groupName));\n break;\n }\n }\n }\n }\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 (customNamedControls.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 (customNamedControls.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\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 const names = [...control.groupNames];\n names.forEach(groupName => {\n if (!createdGroups.includes(groupName)) {\n createdGroups.push(groupName);\n processedControls = detectedControls.filter(item => item.groupNames?.includes(groupName));\n this.toDevice({\n detectedControls: JSON.parse(JSON.stringify(processedControls)),\n friendlyName: this.getName(groupName),\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 // Be sure, that the processed control is removed\n const index = detectedControls.indexOf(control);\n if (index !== -1) {\n detectedControls.splice(index, 1);\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 if (this.validTill > Date.now() || 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\n // fire state change report to Alexa\n if (this.validTill > Date.now() || 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"]}
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const
|
|
39
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
40
40
|
const HourlyDeviceRateLimitExceeded_1 = __importDefault(require("../Exceptions/HourlyDeviceRateLimitExceeded"));
|
|
41
41
|
const OverallDailyRateLimitExceeded_1 = __importDefault(require("../Exceptions/OverallDailyRateLimitExceeded"));
|
|
42
42
|
const FileHelper_1 = __importDefault(require("./FileHelper"));
|
|
@@ -64,7 +64,7 @@ class RateLimiter {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
static get storageFileName() {
|
|
67
|
-
return FileHelper_1.default.absolutePath(
|
|
67
|
+
return FileHelper_1.default.absolutePath(node_path_1.default.join(this.USAGE_STORAGE_FOLDER, this.USAGE_STORAGE_FILE_NAME));
|
|
68
68
|
}
|
|
69
69
|
static async store() {
|
|
70
70
|
if (process.env.TESTS_EXECUTION) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RateLimiter.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Helpers/RateLimiter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"RateLimiter.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Helpers/RateLimiter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA6B;AAC7B,gHAAwF;AACxF,gHAAwF;AACxF,8DAAsC;AACtC,+CAAiC;AAGjC,MAAqB,WAAW;IAC5B,MAAM,CAAC,iCAAiC,GAAG,EAAE,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AAY,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;aAC/C,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;aACnE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,aAAa,EAAE,CAAC,CAAC,CAAC;QAEhE,IAAI,YAAY,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC1C,MAAM,IAAI,uCAA6B,CAAC,2CAA2C,CAAC,CAAC;QACzF,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AA5FL,8BA6FC","sourcesContent":["import path from 'node:path';\nimport HourlyDeviceRateLimitExceeded from '../Exceptions/HourlyDeviceRateLimitExceeded';\nimport OverallDailyRateLimitExceeded from '../Exceptions/OverallDailyRateLimitExceeded';\nimport FileHelper from './FileHelper';\nimport * as Utils from './Utils';\nimport type { AlexaV3EndpointID } from '../types';\n\nexport default class RateLimiter {\n static MAX_DEVICE_STATE_CHANGES_PER_HOUR = 60;\n static MAX_CHANGES_PER_DAY = 1000;\n static USAGE_STORAGE_FOLDER = 'usage';\n static USAGE_STORAGE_FILE_NAME = 'usage.json';\n\n static usage: Map<\n string,\n {\n changeCounter: number;\n timestamp: string;\n }\n > = new Map();\n\n static async init(): Promise<void> {\n try {\n if (process.env.TESTS_EXECUTION) {\n await FileHelper.createFolder(FileHelper.absolutePath(this.USAGE_STORAGE_FOLDER));\n const raw = await FileHelper.read(this.storageFileName);\n this.usage = new Map(JSON.parse(raw));\n } else {\n this.usage = new Map();\n }\n } catch {\n this.usage = new Map();\n }\n return;\n }\n\n static get storageFileName(): string {\n return FileHelper.absolutePath(path.join(this.USAGE_STORAGE_FOLDER, this.USAGE_STORAGE_FILE_NAME));\n }\n\n static async store(): Promise<void> {\n if (process.env.TESTS_EXECUTION) {\n try {\n await FileHelper.write(this.storageFileName, JSON.stringify(Array.from(this.usage.entries())));\n } catch {\n // nop\n }\n }\n }\n\n static get(endpointId: AlexaV3EndpointID): {\n changeCounter: number;\n timestamp: string;\n } {\n let item = this.usage.get(endpointId);\n if (!item) {\n item = {\n changeCounter: 0,\n timestamp: Utils.currentHour().toISOString(),\n };\n this.usage.set(endpointId, item);\n }\n return item;\n }\n\n static async incrementAndGet(endpointId: AlexaV3EndpointID): Promise<{\n changeCounter: number;\n timestamp: string;\n }> {\n const item = this.get(endpointId);\n\n if (!Utils.isCurrentHour(Utils.parseISOString(item.timestamp))) {\n item.changeCounter = 1;\n item.timestamp = Utils.currentHour().toISOString();\n } else {\n item.changeCounter += 1;\n }\n\n this.usage.set(endpointId, item);\n\n try {\n await this.store();\n } catch {\n // nop\n }\n\n if (item.changeCounter > this.MAX_DEVICE_STATE_CHANGES_PER_HOUR) {\n throw new HourlyDeviceRateLimitExceeded(`Hourly state change limit for ${endpointId} exceeded`);\n }\n\n const changesToday = Array.from(this.usage.values())\n .filter(item => Utils.isToday(Utils.parseISOString(item.timestamp)))\n .reduce((sum, { changeCounter }) => sum + changeCounter, 0);\n\n if (changesToday > this.MAX_CHANGES_PER_DAY) {\n throw new OverallDailyRateLimitExceeded(`Overall daily state change limit exceeded`);\n }\n\n return item;\n }\n}\n"]}
|
|
@@ -67,7 +67,7 @@ exports.rgbw2hal = rgbw2hal;
|
|
|
67
67
|
const node_crypto_1 = require("node:crypto");
|
|
68
68
|
const AdapterProvider_1 = __importDefault(require("./AdapterProvider"));
|
|
69
69
|
const type_detector_1 = __importStar(require("@iobroker/type-detector"));
|
|
70
|
-
const roleEnumUtils_1 = require("@iobroker/type-detector/roleEnumUtils");
|
|
70
|
+
const roleEnumUtils_1 = require("@iobroker/type-detector/build/roleEnumUtils");
|
|
71
71
|
const rooms_1 = __importDefault(require("../../rooms"));
|
|
72
72
|
const functions_1 = __importDefault(require("../../functions"));
|
|
73
73
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|