iobroker.iot 5.0.13 → 6.0.3
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/README.md +9 -14
- package/admin/assets/{index-DCr4hGKK.js → index-BdqghSg7.js} +40 -40
- package/admin/index_m.html +1 -1
- package/admin/rules/@mf-types/compiled-types/ActionVisu.d.ts +1 -1
- package/admin/rules/@mf-types.zip +0 -0
- package/admin/rules/assets/{ActionVisu-BN0Kjfo9.js → ActionVisu-BCZFwf_Y.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__.js-aa1tDx2C.js → ActionVisu__loadShare__react__loadShare__.js-B4USkKO5.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__.js_commonjs-proxy-DX6cx281.js → ActionVisu__loadShare__react__loadShare__.js_commonjs-proxy-CEUqE4IA.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react_mf_2_dom__loadShare__.js_commonjs-proxy-27bLZRGy.js → ActionVisu__loadShare__react_mf_2_dom__loadShare__.js_commonjs-proxy-MphP5XTI.js} +1 -1
- package/admin/rules/assets/{bootstrap-QjsDSZNA.js → bootstrap-BKoQjf4I.js} +1 -1
- package/admin/rules/assets/{index-DiSsXjpZ.js → index-BlSAfGU-.js} +4 -4
- package/admin/rules/assets/index-Dk5YUp3j.js +1187 -0
- package/admin/rules/assets/{index-C1ZEp-2N.js → index-pMP6L5OL.js} +2 -2
- package/admin/rules/assets/{jsx-runtime-CnsYFZsa.js → jsx-runtime-D-zp5RaI.js} +1 -1
- package/admin/rules/assets/{localSharedImportMap-8wECk2hR.js → localSharedImportMap-BsAeuDnA.js} +1 -1
- package/admin/rules/assets/{virtualExposes-b6CxLzZb.js → virtualExposes-B2aPQUg7.js} +1 -1
- package/admin/rules/customRuleBlocks.js +5 -5
- package/build/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js +11 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js +8 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js +8 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/AirCondition.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Controls/AirCondition.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Control.js +7 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Control.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Ct.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Ct.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Rgb.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Rgb.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Thermostat.js +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Thermostat.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Volume.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Controls/Volume.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js +18 -9
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/DiscoveryValidator.js +283 -0
- package/build/lib/AlexaSmartHomeV3/Helpers/DiscoveryValidator.js.map +1 -0
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js +4 -0
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -1
- package/build/lib/alisa.js +15 -14
- package/build/lib/googleHome.js +151 -207
- package/build/lib/remote.js +1 -1
- package/build/lib/remote.js.map +1 -1
- package/io-package.json +27 -27
- package/package.json +5 -5
- package/admin/rules/assets/index-FrXvyqvW.js +0 -1187
- package/admin/rules/mf-stats.json +0 -1
- /package/admin/rules/assets/{index-Ccpql4vu.js → index-BPY9gF0q.js} +0 -0
|
@@ -46,7 +46,7 @@ class RgbwSingle extends AdjustableControl_1.default {
|
|
|
46
46
|
// if the state ON, DIMMER or BRIGHTNESS configured
|
|
47
47
|
if (this.states[map.on] || this._brightness) {
|
|
48
48
|
if (!this.states[map.on]) {
|
|
49
|
-
this._offValue = (0, Utils_1.denormalize_0_100)(AdapterProvider_1.default.deviceOffLevel(), this._brightness.valuesRangeMin, this._brightness.
|
|
49
|
+
this._offValue = (0, Utils_1.denormalize_0_100)(AdapterProvider_1.default.deviceOffLevel(), this._brightness.valuesRangeMin, this._brightness.valuesRangeMax || 100);
|
|
50
50
|
}
|
|
51
51
|
this._supported.push(new Capabilities_1.default.PowerController(this.composeInitObjectPowerState()));
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RgbwSingle.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/RgbwSingle.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,4CAAsH;AACtH,iFAAyD;AACzD,4EAAoD;AAGpD,gFAAwD;AACxD,4GAAoF;AAEpF,gFAAwD;AAExD,0FAAkE;AAClE,sEAA8C;AAE9C,qCAAqC;AACrC,EAAE;AACF,yFAAyF;AACzF,EAAE;AACF,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAElJ,MAAqB,UAAW,SAAQ,2BAAiB;IACpC,qBAAqB,CAAmC;I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AAG,KAAK,IAAI,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;oBACnG,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBAC7C,CAAC;gBACD,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;oBACpB,qBAAqB;oBACrB,MAAM,OAAO,GAAG,IAAA,uBAAe,EAC1B,IAAI,CAAC,YAAuB,IAAI,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAC9D,IAAI,CAAC,qBAAqB,CAC7B,CAAC;oBACF,IAAI,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;oBAC5D,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;oBAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBAC7C,CAAC;gBAED,2BAA2B;gBAC3B,IAAI,QAAQ,EAAE,CAAC;oBACX,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAI,UAAqB,CAAC,CAAC;gBACxD,CAAC;gBAED,OAAO,UAAoB,CAAC;YAChC,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,2BAA2B;gBAC3B,IAAI,QAAQ,EAAE,CAAC;oBACX,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAI,KAAgB,CAAC,CAAC;gBACnD,CAAC;gBACD,OAAO,KAAe,CAAC;YAC3B,CAAC;YACD,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,CAAC;CACJ;AA9OD,6BA8OC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport { denormalize_0_100, normalize_0_100, closestFromList, rgbwToHex, rgbw2hal, hal2rgbw } from '../Helpers/Utils';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport type BrightnessController from '../Alexa/Capabilities/BrightnessController';\nimport Brightness from '../Alexa/Properties/Brightness';\nimport ColorTemperatureInKelvin from '../Alexa/Properties/ColorTemperatureInKelvin';\nimport type ColorTemperatureController from '../Alexa/Capabilities/ColorTemperatureController';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type { AlexaV3Category, AlexaV3DirectiveValue, AlexaV3Request, IotExternalPatternControl } from '../types';\nimport EndpointHealth from '../Alexa/Capabilities/EndpointHealth';\nimport Color from '../Alexa/Properties/Color';\n\n// ### RGBW Light Single [rgbwSingle]\n//\n// RGBW light one state of color. Could be HEX #RRGGBBWW, or rgba(0-255,0-255,0-255,0-1).\n//\n// | R | Name | Role | Unit | Type | Wr | Ind | Multi | Regex |\n// |---|-----------------|-------------------------------|------|---------|----|-----|-------|---------------------------------------------------|\n// | * | RGBW | level.color.rgbw | | string | W | | | `/^level\\.color\\.rgbw$/` |\n// | | DIMMER | level.dimmer | % | number | W | | | `/^level\\.dimmer$/` |\n// | | BRIGHTNESS | | % | number | W | | | `/^level\\.brightness$/` |\n// | | TEMPERATURE | level.color.temperature | °K | number | W | | | `/^level\\.color\\.temperature$/` |\n// | | ON | switch.light | | boolean | W | | | `/^switch(\\.light)?$/` |\n// | | ON_ACTUAL | sensor.light | | boolean | - | | | `/^(state|switch|sensor)\\.light|switch$/` |\n\nexport default class RgbwSingle extends AdjustableControl {\n private readonly _brightnessCapability: BrightnessController | undefined;\n private readonly _brightness: Brightness | undefined;\n private readonly _colorTemperatureCapability: ColorTemperatureController | undefined;\n private readonly _offValue: number = 0;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n const map = this.statesMap;\n this._supported = [new Capabilities.ColorController(this.composeInitObjectColor())];\n\n if (this.states[map.temperature]) {\n this._colorTemperatureCapability = new Capabilities.ColorTemperatureController(\n this.composeInitObjectColorTemperature(),\n );\n this._supported.push(this._colorTemperatureCapability);\n }\n\n // if the state DIMMER or BRIGHTNESS configured\n if (this.states[map.dimmer] || this.states[map.brightness]) {\n this._brightnessCapability = new Capabilities.BrightnessController(this.composeInitObjectBrightness());\n this._brightness = this._brightnessCapability.brightness;\n this._supported.push(this._brightnessCapability);\n }\n\n // if the state ON, DIMMER or BRIGHTNESS configured\n if (this.states[map.on] || this._brightness) {\n if (!this.states[map.on]) {\n this._offValue = denormalize_0_100(\n AdapterProvider.deviceOffLevel(),\n this._brightness!.valuesRangeMin as number,\n (this._brightness!.valuesRangeMin as number) || 100,\n ) as number;\n }\n this._supported.push(new Capabilities.PowerController(this.composeInitObjectPowerState()));\n }\n\n const health = this.connectivityInitObject();\n if (health) {\n this._supported.push(new EndpointHealth(health));\n }\n }\n\n get categories(): AlexaV3Category[] {\n return ['LIGHT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [ColorTemperatureInKelvin];\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n const map = this.statesMap;\n\n if (property.currentValue === undefined) {\n property.currentValue = await AdapterProvider.getState(property.getId);\n // convert the non-zero brightness to power = true\n if (property.propertyName === PowerState.propertyName && !this.states[map.on]) {\n property.currentValue = (property.currentValue as number) > this._offValue;\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 setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[this.statesMap.on]) {\n await AdapterProvider.setState(property.setId, value ?? false);\n property.currentValue = value;\n } else {\n // this will be processed in Brightness property\n }\n } else if (property.propertyName === Color.propertyName) {\n await AdapterProvider.setState(property.setId, value ?? '#00000000');\n property.currentValue = value;\n } else if (\n property.propertyName === Brightness.propertyName ||\n property.propertyName === ColorTemperatureInKelvin.propertyName\n ) {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\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\n // convert delta to iobroker value\n const value = property.value(delta);\n\n // set iobroker state\n await this.setState(property, value ?? 0);\n\n return value as AlexaV3DirectiveValue;\n }\n\n protected composeInitObjectColor(): ControlStateInitObject {\n const map = this.statesMap;\n\n return {\n setState: this.states[map.rgbw]!,\n getState: this.states[map.rgbw]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n // Convert {\n // \"hue\": 350.5,\n // \"saturation\": 0.7138,\n // \"brightness\": 0.6524\n // } to RGB hex #RRGGBBWW\n if (typeof alexaValue === 'object' && alexaValue !== null) {\n return hal2rgbw(alexaValue as { hue: number; saturation: number; brightness: number });\n }\n\n return null;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return rgbw2hal(rgbwToHex(value as string));\n },\n rgbw: this.states[map.rgbw]!,\n };\n }\n\n protected composeInitObjectPowerState(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n getState:\n this.states[map.on_actual] ||\n this.states[map.on] ||\n this.states[map.dimmer] ||\n this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? PowerState.ON : PowerState.OFF;\n },\n multiPurposeProperty: !this.states[map.on], // Could handle brightness events\n handleSimilarEvents: true, // If brightness set to non-zero value and power is off, turn the lamp on\n };\n }\n\n protected composeInitObjectBrightness(): ControlStateInitObject {\n const map = this.statesMap;\n let onValue: number | 'stored' | 'omit' | undefined = undefined;\n const offValue = AdapterProvider.deviceOffLevel();\n if (this.smartName && typeof this.smartName === 'object') {\n const byOn = this.smartName.byON;\n if (byOn !== null && byOn !== undefined && !isNaN(byOn as unknown as number)) {\n onValue = parseFloat(byOn as any);\n if (onValue < offValue) {\n onValue = offValue;\n }\n } else if (byOn === 'stored' || byOn === 'omit') {\n onValue = byOn;\n }\n }\n\n return {\n setState: this.states[map.dimmer] || this.states[map.brightness]!,\n getState: this.states[map.dimmer] || this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax 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.valuesRangeMin as number, this.valuesRangeMax as number);\n },\n multiPurposeProperty: !this.states[map.on], // Could handle powerState events\n handleSimilarEvents: true, // If power set ON and brightness is 0, set to non-zero value\n offValue,\n onValue,\n };\n }\n\n protected composeInitObjectColorTemperature(): ControlStateInitObject {\n const map = this.statesMap;\n const isMireds = this.states[map.temperature]?.common?.unit === 'mireds';\n\n return {\n setState: this.states[map.temperature]!,\n getState: this.states[map.temperature]!,\n alexaSetter: function (\n this: ColorTemperatureInKelvin,\n alexaValue: AlexaV3DirectiveValue,\n ): ioBroker.StateValue {\n if (alexaValue === 1) {\n // increase directive\n const closest = closestFromList(\n (this.currentValue as number) || this.colorTemperatureTable[0],\n this.colorTemperatureTable,\n );\n let index = this.colorTemperatureTable.indexOf(closest) + 1;\n index = index >= this.colorTemperatureTable.length ? this.colorTemperatureTable.length - 1 : index;\n return this.colorTemperatureTable[index];\n }\n if (alexaValue === -1) {\n // decrease directive\n const closest = closestFromList(\n (this.currentValue as number) || this.colorTemperatureTable[0],\n this.colorTemperatureTable,\n );\n let index = this.colorTemperatureTable.indexOf(closest) - 1;\n index = index < 0 ? 0 : index;\n return this.colorTemperatureTable[index];\n }\n\n // Convert Kelvin to mireds\n if (isMireds) {\n return Math.round(1000000 / (alexaValue as number));\n }\n\n return alexaValue as number;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n // Convert Mireds to Kelvin\n if (isMireds) {\n return Math.round(1000000 / (value as number));\n }\n return value as number;\n },\n percentage: true,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RgbwSingle.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/RgbwSingle.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,4CAAsH;AACtH,iFAAyD;AACzD,4EAAoD;AAGpD,gFAAwD;AACxD,4GAAoF;AAEpF,gFAAwD;AAExD,0FAAkE;AAClE,sEAA8C;AAE9C,qCAAqC;AACrC,EAAE;AACF,yFAAyF;AACzF,EAAE;AACF,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAClJ,kJAAkJ;AAElJ,MAAqB,UAAW,SAAQ,2BAAiB;IACpC,qBAAqB,CAAmC;IACxD,WAAW,CAAyB;IACpC,2BAA2B,CAAyC;IACpE,SAAS,GAAW,CAAC,CAAC;IAEvC,YAAY,eAA0C;QAClD,KAAK,CAAC,eAAe,CAAC,CAAC;QAEvB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,sBAAY,CAAC,eAAe,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;QAEpF,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,2BAA2B,GAAG,IAAI,sBAAY,CAAC,0BAA0B,CAC1E,IAAI,CAAC,iCAAiC,EAAE,CAC3C,CAAC;YACF,IAAI,CAAC,UAAU,CAAC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AAC,GAAG,CAAC,CAAC;oBAC5D,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;oBAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBAC7C,CAAC;gBAED,2BAA2B;gBAC3B,IAAI,QAAQ,EAAE,CAAC;oBACX,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAI,UAAqB,CAAC,CAAC;gBACxD,CAAC;gBAED,OAAO,UAAoB,CAAC;YAChC,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,2BAA2B;gBAC3B,IAAI,QAAQ,EAAE,CAAC;oBACX,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAI,KAAgB,CAAC,CAAC;gBACnD,CAAC;gBACD,OAAO,KAAe,CAAC;YAC3B,CAAC;YACD,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,CAAC;CACJ;AA9OD,6BA8OC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport { denormalize_0_100, normalize_0_100, closestFromList, rgbwToHex, rgbw2hal, hal2rgbw } from '../Helpers/Utils';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport type BrightnessController from '../Alexa/Capabilities/BrightnessController';\nimport Brightness from '../Alexa/Properties/Brightness';\nimport ColorTemperatureInKelvin from '../Alexa/Properties/ColorTemperatureInKelvin';\nimport type ColorTemperatureController from '../Alexa/Capabilities/ColorTemperatureController';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type { AlexaV3Category, AlexaV3DirectiveValue, AlexaV3Request, IotExternalPatternControl } from '../types';\nimport EndpointHealth from '../Alexa/Capabilities/EndpointHealth';\nimport Color from '../Alexa/Properties/Color';\n\n// ### RGBW Light Single [rgbwSingle]\n//\n// RGBW light one state of color. Could be HEX #RRGGBBWW, or rgba(0-255,0-255,0-255,0-1).\n//\n// | R | Name | Role | Unit | Type | Wr | Ind | Multi | Regex |\n// |---|-----------------|-------------------------------|------|---------|----|-----|-------|---------------------------------------------------|\n// | * | RGBW | level.color.rgbw | | string | W | | | `/^level\\.color\\.rgbw$/` |\n// | | DIMMER | level.dimmer | % | number | W | | | `/^level\\.dimmer$/` |\n// | | BRIGHTNESS | | % | number | W | | | `/^level\\.brightness$/` |\n// | | TEMPERATURE | level.color.temperature | °K | number | W | | | `/^level\\.color\\.temperature$/` |\n// | | ON | switch.light | | boolean | W | | | `/^switch(\\.light)?$/` |\n// | | ON_ACTUAL | sensor.light | | boolean | - | | | `/^(state|switch|sensor)\\.light|switch$/` |\n\nexport default class RgbwSingle extends AdjustableControl {\n private readonly _brightnessCapability: BrightnessController | undefined;\n private readonly _brightness: Brightness | undefined;\n private readonly _colorTemperatureCapability: ColorTemperatureController | undefined;\n private readonly _offValue: number = 0;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n const map = this.statesMap;\n this._supported = [new Capabilities.ColorController(this.composeInitObjectColor())];\n\n if (this.states[map.temperature]) {\n this._colorTemperatureCapability = new Capabilities.ColorTemperatureController(\n this.composeInitObjectColorTemperature(),\n );\n this._supported.push(this._colorTemperatureCapability);\n }\n\n // if the state DIMMER or BRIGHTNESS configured\n if (this.states[map.dimmer] || this.states[map.brightness]) {\n this._brightnessCapability = new Capabilities.BrightnessController(this.composeInitObjectBrightness());\n this._brightness = this._brightnessCapability.brightness;\n this._supported.push(this._brightnessCapability);\n }\n\n // if the state ON, DIMMER or BRIGHTNESS configured\n if (this.states[map.on] || this._brightness) {\n if (!this.states[map.on]) {\n this._offValue = denormalize_0_100(\n AdapterProvider.deviceOffLevel(),\n this._brightness!.valuesRangeMin as number,\n (this._brightness!.valuesRangeMax as number) || 100,\n ) as number;\n }\n this._supported.push(new Capabilities.PowerController(this.composeInitObjectPowerState()));\n }\n\n const health = this.connectivityInitObject();\n if (health) {\n this._supported.push(new EndpointHealth(health));\n }\n }\n\n get categories(): AlexaV3Category[] {\n return ['LIGHT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [ColorTemperatureInKelvin];\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n const map = this.statesMap;\n\n if (property.currentValue === undefined) {\n property.currentValue = await AdapterProvider.getState(property.getId);\n // convert the non-zero brightness to power = true\n if (property.propertyName === PowerState.propertyName && !this.states[map.on]) {\n property.currentValue = (property.currentValue as number) > this._offValue;\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 setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[this.statesMap.on]) {\n await AdapterProvider.setState(property.setId, value ?? false);\n property.currentValue = value;\n } else {\n // this will be processed in Brightness property\n }\n } else if (property.propertyName === Color.propertyName) {\n await AdapterProvider.setState(property.setId, value ?? '#00000000');\n property.currentValue = value;\n } else if (\n property.propertyName === Brightness.propertyName ||\n property.propertyName === ColorTemperatureInKelvin.propertyName\n ) {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\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\n // convert delta to iobroker value\n const value = property.value(delta);\n\n // set iobroker state\n await this.setState(property, value ?? 0);\n\n return value as AlexaV3DirectiveValue;\n }\n\n protected composeInitObjectColor(): ControlStateInitObject {\n const map = this.statesMap;\n\n return {\n setState: this.states[map.rgbw]!,\n getState: this.states[map.rgbw]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n // Convert {\n // \"hue\": 350.5,\n // \"saturation\": 0.7138,\n // \"brightness\": 0.6524\n // } to RGB hex #RRGGBBWW\n if (typeof alexaValue === 'object' && alexaValue !== null) {\n return hal2rgbw(alexaValue as { hue: number; saturation: number; brightness: number });\n }\n\n return null;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return rgbw2hal(rgbwToHex(value as string));\n },\n rgbw: this.states[map.rgbw]!,\n };\n }\n\n protected composeInitObjectPowerState(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n getState:\n this.states[map.on_actual] ||\n this.states[map.on] ||\n this.states[map.dimmer] ||\n this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? PowerState.ON : PowerState.OFF;\n },\n multiPurposeProperty: !this.states[map.on], // Could handle brightness events\n handleSimilarEvents: true, // If brightness set to non-zero value and power is off, turn the lamp on\n };\n }\n\n protected composeInitObjectBrightness(): ControlStateInitObject {\n const map = this.statesMap;\n let onValue: number | 'stored' | 'omit' | undefined = undefined;\n const offValue = AdapterProvider.deviceOffLevel();\n if (this.smartName && typeof this.smartName === 'object') {\n const byOn = this.smartName.byON;\n if (byOn !== null && byOn !== undefined && !isNaN(byOn as unknown as number)) {\n onValue = parseFloat(byOn as any);\n if (onValue < offValue) {\n onValue = offValue;\n }\n } else if (byOn === 'stored' || byOn === 'omit') {\n onValue = byOn;\n }\n }\n\n return {\n setState: this.states[map.dimmer] || this.states[map.brightness]!,\n getState: this.states[map.dimmer] || this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax 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.valuesRangeMin as number, this.valuesRangeMax as number);\n },\n multiPurposeProperty: !this.states[map.on], // Could handle powerState events\n handleSimilarEvents: true, // If power set ON and brightness is 0, set to non-zero value\n offValue,\n onValue,\n };\n }\n\n protected composeInitObjectColorTemperature(): ControlStateInitObject {\n const map = this.statesMap;\n const isMireds = this.states[map.temperature]?.common?.unit === 'mireds';\n\n return {\n setState: this.states[map.temperature]!,\n getState: this.states[map.temperature]!,\n alexaSetter: function (\n this: ColorTemperatureInKelvin,\n alexaValue: AlexaV3DirectiveValue,\n ): ioBroker.StateValue {\n if (alexaValue === 1) {\n // increase directive\n const closest = closestFromList(\n (this.currentValue as number) || this.colorTemperatureTable[0],\n this.colorTemperatureTable,\n );\n let index = this.colorTemperatureTable.indexOf(closest) + 1;\n index = index >= this.colorTemperatureTable.length ? this.colorTemperatureTable.length - 1 : index;\n return this.colorTemperatureTable[index];\n }\n if (alexaValue === -1) {\n // decrease directive\n const closest = closestFromList(\n (this.currentValue as number) || this.colorTemperatureTable[0],\n this.colorTemperatureTable,\n );\n let index = this.colorTemperatureTable.indexOf(closest) - 1;\n index = index < 0 ? 0 : index;\n return this.colorTemperatureTable[index];\n }\n\n // Convert Kelvin to mireds\n if (isMireds) {\n return Math.round(1000000 / (alexaValue as number));\n }\n\n return alexaValue as number;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n // Convert Mireds to Kelvin\n if (isMireds) {\n return Math.round(1000000 / (value as number));\n }\n return value as number;\n },\n percentage: true,\n };\n }\n}\n"]}
|
|
@@ -136,7 +136,7 @@ class Thermostat extends AdjustableControl_1.default {
|
|
|
136
136
|
return 0;
|
|
137
137
|
},
|
|
138
138
|
alexaGetter: function (value) {
|
|
139
|
-
return (value !== undefined && states[value]
|
|
139
|
+
return (value !== undefined && states[value]) || 'AUTO';
|
|
140
140
|
},
|
|
141
141
|
supportedModes: supportedModes,
|
|
142
142
|
};
|
|
@@ -1 +1 @@
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C,IAAI,CAAC,IAAK,EAAE,EAAE,EAAE,SAAS,EAA0C;YAC7F,WAAW,EAAE,UAAgC,UAAiC;gBAC1E,qCAAqC;gBACrC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAmC,CAAC,CAAC;gBAC7E,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;oBACb,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;gBACD,OAAO,CAAC,CAAC;YACb,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAe,CAAC,KAAK,SAAS,CAAC,IAAI,MAAM,CAAC;YACpF,CAAC;YACD,cAAc,EAAE,cAAc;SACjC,CAAC;IACN,CAAC;CACJ;AA9ID,6BA8IC","sourcesContent":["import type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ThermostatMode,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\nimport TemperatureSensor from '../Alexa/Capabilities/TemperatureSensor';\nimport ThermostatController from '../Alexa/Capabilities/ThermostatController';\nimport PowerController from '../Alexa/Capabilities/PowerController';\nimport AdjustableControl from './AdjustableControl';\nimport { ensureValueInRange } from '../Helpers/Utils';\nimport TargetSetpoint from '../Alexa/Properties/TargetSetpoint';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport EndpointHealth from '../Alexa/Capabilities/EndpointHealth';\n\nexport default class Thermostat extends AdjustableControl {\n private readonly _temperatureSensor: TemperatureSensor | null = null;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n const temperatureSensorConfig = this.composeInitObjectTemperature();\n this._supported = [\n new ThermostatController(this.composeInitObjectTargetSetpoint(), this.composeInitObjectThermostatMode()),\n ];\n if (temperatureSensorConfig) {\n this._temperatureSensor = new TemperatureSensor(temperatureSensorConfig);\n this._supported.push(this._temperatureSensor);\n }\n\n const map = this.statesMap;\n\n // if the state POWER is present, then we can switch it ON/OFF\n if (this.states[map.power]) {\n this._supported.push(new PowerController(this.composeInitObjectPowerState()));\n }\n\n const health = this.connectivityInitObject();\n if (health) {\n this._supported.push(new EndpointHealth(health));\n }\n }\n\n get categories(): AlexaV3Category[] {\n if (this._temperatureSensor) {\n return ['THERMOSTAT', 'TEMPERATURE_SENSOR'];\n }\n return ['THERMOSTAT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [TargetSetpoint];\n }\n\n private composeInitObjectPowerState(): ControlStateInitObject {\n const map = this.statesMap;\n\n return {\n setState: this.states[map.power] || this.states[map.set]!,\n getState: this.states[map.power] || this.states[map.set]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n private composeInitObjectTemperature(): ControlStateInitObject | null {\n const map = this.statesMap;\n const detectorState = this.states[map.actual];\n if (!detectorState) {\n return null;\n }\n return {\n setState: detectorState,\n getState: detectorState,\n };\n }\n\n private composeInitObjectTargetSetpoint(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.set]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return ensureValueInRange(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax as number,\n );\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value as number;\n },\n };\n }\n\n private composeInitObjectThermostatMode(): ControlStateInitObject {\n const map = this.statesMap;\n // extract all modes\n const modes = this.states[map.mode];\n let states = modes?.common?.states || {};\n const supportedModes: AlexaV3ThermostatMode[] = [];\n if (states) {\n if (Array.isArray(states)) {\n const _states: { [modeValue: string]: string } = {};\n states.forEach(state => {\n _states[state] = state.toUpperCase();\n });\n states = _states;\n }\n // Try map to known modes 'AUTO' | 'COOL' | 'HEAT' | 'OFF' | 'ECO' | 'EM_HEAT'\n Object.keys(states).forEach(state => {\n const mode = states[state].toUpperCase();\n if (mode.includes('AUTO')) {\n supportedModes[parseInt(state, 10)] = 'AUTO';\n states[state] = 'AUTO';\n } else if (mode.includes('COOL')) {\n supportedModes[parseInt(state, 10)] = 'COOL';\n states[state] = 'COOL';\n } else if (mode.includes('HEAT')) {\n supportedModes[parseInt(state, 10)] = 'HEAT';\n states[state] = 'HEAT';\n } else if (mode.includes('ECO')) {\n supportedModes[parseInt(state, 10)] = 'ECO';\n states[state] = 'ECO';\n } else if (mode.includes('OFF')) {\n supportedModes[parseInt(state, 10)] = 'OFF';\n states[state] = 'OFF';\n } else {\n states[state] = mode;\n }\n });\n }\n if (!supportedModes.length) {\n supportedModes.push('AUTO');\n }\n\n return {\n setState: this.states[map.mode] || ({ id: undefined } as unknown as IotExternalDetectorState),\n getState: this.states[map.mode] || ({ id: undefined } as unknown as IotExternalDetectorState),\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n // Convert 'AUTO' and so on into 0, 1\n const pos = Object.keys(states).indexOf(alexaValue as AlexaV3ThermostatMode);\n if (pos !== -1) {\n return Object.keys(states)[pos];\n }\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return (value !== undefined && states[value as number] !== undefined) || 'AUTO';\n },\n supportedModes: supportedModes,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Thermostat.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Thermostat.ts"],"names":[],"mappings":";;;;;AAOA,gGAAwE;AACxE,sGAA8E;AAC9E,4FAAoE;AACpE,4EAAoD;AACpD,4CAAsD;AACtD,wFAAgE;AAChE,gF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IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;oBACb,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;gBACD,OAAO,CAAC,CAAC;YACb,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAe,CAAC,CAAC,IAAI,MAAM,CAAC;YACtE,CAAC;YACD,cAAc,EAAE,cAAc;SACjC,CAAC;IACN,CAAC;CACJ;AA9ID,6BA8IC","sourcesContent":["import type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ThermostatMode,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\nimport TemperatureSensor from '../Alexa/Capabilities/TemperatureSensor';\nimport ThermostatController from '../Alexa/Capabilities/ThermostatController';\nimport PowerController from '../Alexa/Capabilities/PowerController';\nimport AdjustableControl from './AdjustableControl';\nimport { ensureValueInRange } from '../Helpers/Utils';\nimport TargetSetpoint from '../Alexa/Properties/TargetSetpoint';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport EndpointHealth from '../Alexa/Capabilities/EndpointHealth';\n\nexport default class Thermostat extends AdjustableControl {\n private readonly _temperatureSensor: TemperatureSensor | null = null;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n const temperatureSensorConfig = this.composeInitObjectTemperature();\n this._supported = [\n new ThermostatController(this.composeInitObjectTargetSetpoint(), this.composeInitObjectThermostatMode()),\n ];\n if (temperatureSensorConfig) {\n this._temperatureSensor = new TemperatureSensor(temperatureSensorConfig);\n this._supported.push(this._temperatureSensor);\n }\n\n const map = this.statesMap;\n\n // if the state POWER is present, then we can switch it ON/OFF\n if (this.states[map.power]) {\n this._supported.push(new PowerController(this.composeInitObjectPowerState()));\n }\n\n const health = this.connectivityInitObject();\n if (health) {\n this._supported.push(new EndpointHealth(health));\n }\n }\n\n get categories(): AlexaV3Category[] {\n if (this._temperatureSensor) {\n return ['THERMOSTAT', 'TEMPERATURE_SENSOR'];\n }\n return ['THERMOSTAT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [TargetSetpoint];\n }\n\n private composeInitObjectPowerState(): ControlStateInitObject {\n const map = this.statesMap;\n\n return {\n setState: this.states[map.power] || this.states[map.set]!,\n getState: this.states[map.power] || this.states[map.set]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n private composeInitObjectTemperature(): ControlStateInitObject | null {\n const map = this.statesMap;\n const detectorState = this.states[map.actual];\n if (!detectorState) {\n return null;\n }\n return {\n setState: detectorState,\n getState: detectorState,\n };\n }\n\n private composeInitObjectTargetSetpoint(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.set]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return ensureValueInRange(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax as number,\n );\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value as number;\n },\n };\n }\n\n private composeInitObjectThermostatMode(): ControlStateInitObject {\n const map = this.statesMap;\n // extract all modes\n const modes = this.states[map.mode];\n let states = modes?.common?.states || {};\n const supportedModes: AlexaV3ThermostatMode[] = [];\n if (states) {\n if (Array.isArray(states)) {\n const _states: { [modeValue: string]: string } = {};\n states.forEach(state => {\n _states[state] = state.toUpperCase();\n });\n states = _states;\n }\n // Try map to known modes 'AUTO' | 'COOL' | 'HEAT' | 'OFF' | 'ECO' | 'EM_HEAT'\n Object.keys(states).forEach(state => {\n const mode = states[state].toUpperCase();\n if (mode.includes('AUTO')) {\n supportedModes[parseInt(state, 10)] = 'AUTO';\n states[state] = 'AUTO';\n } else if (mode.includes('COOL')) {\n supportedModes[parseInt(state, 10)] = 'COOL';\n states[state] = 'COOL';\n } else if (mode.includes('HEAT')) {\n supportedModes[parseInt(state, 10)] = 'HEAT';\n states[state] = 'HEAT';\n } else if (mode.includes('ECO')) {\n supportedModes[parseInt(state, 10)] = 'ECO';\n states[state] = 'ECO';\n } else if (mode.includes('OFF')) {\n supportedModes[parseInt(state, 10)] = 'OFF';\n states[state] = 'OFF';\n } else {\n states[state] = mode;\n }\n });\n }\n if (!supportedModes.length) {\n supportedModes.push('AUTO');\n }\n\n return {\n setState: this.states[map.mode] || ({ id: undefined } as unknown as IotExternalDetectorState),\n getState: this.states[map.mode] || ({ id: undefined } as unknown as IotExternalDetectorState),\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n // Convert 'AUTO' and so on into 0, 1\n const pos = Object.keys(states).indexOf(alexaValue as AlexaV3ThermostatMode);\n if (pos !== -1) {\n return Object.keys(states)[pos];\n }\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return (value !== undefined && states[value as number]) || 'AUTO';\n },\n supportedModes: supportedModes,\n };\n }\n}\n"]}
|
|
@@ -39,8 +39,8 @@ class Volume extends AdjustableControl_1.default {
|
|
|
39
39
|
// set volume
|
|
40
40
|
if (value) {
|
|
41
41
|
// set volume to 0 on MUTED true
|
|
42
|
-
await AdapterProvider_1.default.setState(this._speaker.volume.setId, 0);
|
|
43
42
|
this._lastVolume = this._speaker.volume.currentValue;
|
|
43
|
+
await AdapterProvider_1.default.setState(this._speaker.volume.setId, 0);
|
|
44
44
|
this._speaker.volume.currentValue = 0;
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
@@ -72,7 +72,7 @@ class Volume extends AdjustableControl_1.default {
|
|
|
72
72
|
async getOrRetrieveCurrentValue(property) {
|
|
73
73
|
if (property.currentValue === undefined) {
|
|
74
74
|
property.currentValue = await AdapterProvider_1.default.getState(property.getId);
|
|
75
|
-
// convert non
|
|
75
|
+
// convert non-zero volumes to muted = false
|
|
76
76
|
if (property.propertyName === this._speaker.muted.propertyName &&
|
|
77
77
|
property.getId === this._speaker.volume.getId) {
|
|
78
78
|
property.currentValue = property.currentValue === 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Volume.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Volume.ts"],"names":[],"mappings":";;;;;AAAA,4EAAoD;AACpD,qEAA6C;AAE7C,uDAAwE;AACxE,iFAAyD;AACzD,4CAAsE;AACtE,4EAAoD;AAEpD,0FAAkE;AAElE,MAAqB,MAAO,SAAQ,2BAAiB;IAChC,QAAQ,CAAU;IAC3B,WAAW,CAAkC;IAErD,YAAY,eAA0C;QAClD,KAAK,CAAC,eAAe,CAAC,CAAC;QAEvB,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAC;QAC3F,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAElC,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC7C,IAAI,MAAM,EAAE,CAAC;YACT,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IAED,IAAI,UAAU;QACV,OAAO,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IAED,oBAAoB;QAChB,OAAO,CAAC,eAAgB,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAwB,EAAE,KAAsC;QAC3E,0BAA0B;QAC1B,MAAM,yBAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAM,CAAC,CAAC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CAAC;CACJ;AAhID,yBAgIC","sourcesContent":["import Speaker from '../Alexa/Capabilities/Speaker';\nimport Properties from '../Alexa/Properties';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport { Volume as PropertiesVolume } from '../Alexa/Properties/Volume';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport { denormalize_0_100, normalize_0_100 } from '../Helpers/Utils';\nimport AdjustableControl from './AdjustableControl';\nimport type { AlexaV3Category, AlexaV3DirectiveValue, IotExternalPatternControl } from '../types';\nimport EndpointHealth from '../Alexa/Capabilities/EndpointHealth';\n\nexport default class Volume extends AdjustableControl {\n private readonly _speaker: Speaker;\n private _lastVolume: ioBroker.StateValue | undefined;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n this._speaker = new Speaker(this.composeInitObjectVolume(), this.composeInitObjectMuted());\n this._supported = [this._speaker];\n\n const health = this.connectivityInitObject();\n if (health) {\n this._supported.push(new EndpointHealth(health));\n }\n }\n\n get categories(): AlexaV3Category[] {\n return ['SPEAKER'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [PropertiesVolume];\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue | undefined): Promise<void> {\n // set the property itself\n await AdapterProvider.setState(property.setId, value!);\n property.currentValue = value;\n\n if (property.propertyName === Properties.Muted.propertyName) {\n if (!this._speaker) {\n throw new Error('Muted property name is missing');\n }\n // set volume\n if (value) {\n // set volume to 0 on MUTED true\n this._lastVolume = this._speaker.volume.currentValue;\n await AdapterProvider.setState(this._speaker.volume.setId, 0);\n this._speaker.volume.currentValue = 0;\n } else {\n // set volume to the last known, configured or 20 otherwise on MUTED false\n if (this._lastVolume === undefined) {\n const smartName = this.states[this.statesMap.set]!.smartName;\n if (typeof smartName === 'object' && smartName && smartName.byON !== undefined) {\n this._lastVolume = smartName.byON;\n }\n this._lastVolume =\n this._lastVolume === undefined || isNaN(this._lastVolume as unknown as number)\n ? denormalize_0_100(\n 20,\n this._speaker.volume.valuesRangeMin as number,\n this._speaker.volume.valuesRangeMax as number,\n )\n : parseInt(this._lastVolume as string, 10);\n }\n await AdapterProvider.setState(this._speaker.volume.setId, this._lastVolume as number);\n this._speaker.volume.currentValue = this._lastVolume;\n }\n } else {\n // set muted\n const muted = value === 0;\n // only on different IDs for volume and muted\n if (this._speaker.volume.setId !== this._speaker.muted.setId) {\n await AdapterProvider.setState(this._speaker.muted.setId, muted);\n }\n this._speaker.muted.currentValue = muted;\n }\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n if (property.currentValue === undefined) {\n property.currentValue = await AdapterProvider.getState(property.getId);\n\n // convert non-zero volumes to muted = false\n if (\n property.propertyName === this._speaker.muted.propertyName &&\n property.getId === this._speaker.volume.getId\n ) {\n property.currentValue = property.currentValue === 0;\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 private composeInitObjectVolume(): ControlStateInitObject {\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 (\n this: PropertiesBase,\n alexaValue: AlexaV3DirectiveValue,\n ): ioBroker.StateValue | undefined {\n return denormalize_0_100(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax as number,\n );\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return normalize_0_100(value as number, this.valuesRangeMin as number, this.valuesRangeMax as number);\n },\n };\n }\n\n private composeInitObjectMuted(): ControlStateInitObject {\n const map = this.statesMap;\n\n return {\n setState: this.states[map.mute] || this.states[map.set]!,\n getState: this.states[map.mute] || this.states[map.set]!,\n alexaSetter: function (alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n return alexaValue as boolean;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value as boolean;\n },\n };\n }\n}\n"]}
|
|
@@ -178,14 +178,14 @@ class DeviceManager {
|
|
|
178
178
|
// detectedControls = detectedControls.filter(c => ['light', 'dimmer'].includes(c.type));
|
|
179
179
|
const createdGroups = [];
|
|
180
180
|
let iteration = 0;
|
|
181
|
-
// First collect all custom
|
|
181
|
+
// First, collect all custom-friendly names assigned by user
|
|
182
182
|
const customNamedControls = [];
|
|
183
183
|
for (const control of detectedControls) {
|
|
184
184
|
if (control.groupNames) {
|
|
185
185
|
for (const groupName of control.groupNames) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
const name = this.getName(groupName);
|
|
187
|
+
if (!customNamedControls.includes(name)) {
|
|
188
|
+
customNamedControls.push(name);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
@@ -227,8 +227,17 @@ class DeviceManager {
|
|
|
227
227
|
else {
|
|
228
228
|
this.log.debug(`Control of type [${control.type}] assigned to room [${this.getName(control.room.common.name)}] has no function. Skipped.`);
|
|
229
229
|
}
|
|
230
|
-
// delete
|
|
231
|
-
|
|
230
|
+
// delete all processed controls from detected controls
|
|
231
|
+
if (processedControls.length > 1) {
|
|
232
|
+
for (let i = detectedControls.length - 1; i >= 0; i--) {
|
|
233
|
+
if (processedControls.includes(detectedControls[i])) {
|
|
234
|
+
detectedControls.splice(i, 1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
detectedControls.splice(0, 1);
|
|
240
|
+
}
|
|
232
241
|
}
|
|
233
242
|
else if (control.groupNames?.length) {
|
|
234
243
|
// no room, but smart name (not only one)
|
|
@@ -259,7 +268,7 @@ class DeviceManager {
|
|
|
259
268
|
}
|
|
260
269
|
}
|
|
261
270
|
});
|
|
262
|
-
// Be sure
|
|
271
|
+
// Be sure that the processed control is removed
|
|
263
272
|
const index = detectedControls.indexOf(control);
|
|
264
273
|
if (index !== -1) {
|
|
265
274
|
detectedControls.splice(index, 1);
|
|
@@ -281,7 +290,7 @@ class DeviceManager {
|
|
|
281
290
|
for (const device of this.devices) {
|
|
282
291
|
this.log.debug(`${device.toString()}`);
|
|
283
292
|
}
|
|
284
|
-
// a new discovery process is needed in case we had
|
|
293
|
+
// a new discovery process is needed in case we already had devices and device collection was
|
|
285
294
|
// triggered again by, e.g., a change in room/function enums
|
|
286
295
|
// if (discoveryNeeded) {
|
|
287
296
|
// this.log.info(`Please delete all managed by ioBroker devices in your Alexa app and then start discovery`);
|
|
@@ -343,7 +352,7 @@ class DeviceManager {
|
|
|
343
352
|
const promises = [];
|
|
344
353
|
for (const id of this.subscribed) {
|
|
345
354
|
this.log.silly(`unsubscribing from updates of ${id}`);
|
|
346
|
-
promises.push(AdapterProvider_1.default.
|
|
355
|
+
promises.push(AdapterProvider_1.default.unsubscribe(id));
|
|
347
356
|
}
|
|
348
357
|
await Promise.allSettled(promises);
|
|
349
358
|
this.subscribed = [];
|
|
@@ -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,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;CACd,CAAC;AACF,mDAAmD;AACnD,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AAM,CAAC,iBAAiB,GAAG,WAAW,CAAC;4BACvC,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;4BAErC,oCAAoC;4BACpC,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;gCAC7D,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;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"]}
|
|
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,OAA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,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;AApgBD,gCAogBC","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 const name = this.getName(groupName);\n if (!customNamedControls.includes(name)) {\n customNamedControls.push(name);\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 all processed controls from detected controls\n if (processedControls.length > 1) {\n for (let i = detectedControls.length - 1; i >= 0; i--) {\n if (processedControls.includes(detectedControls[i])) {\n detectedControls.splice(i, 1);\n }\n }\n } else {\n detectedControls.splice(0, 1);\n }\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 already had 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.unsubscribe(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"]}
|