iobroker.iot 4.2.8 → 4.2.10
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 +6 -4
- package/admin/assets/{index-CI6r4XAS.js → index-BlSWVNwK.js} +184 -62
- package/admin/index_m.html +1 -1
- package/admin/rules/assets/{ActionVisu-DE8dgNVF.js → ActionVisu-CRxreF9A.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__-BKaC-p5K.js → ActionVisu__loadShare__react__loadShare__-DD24U9rt.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react_mf_2_dom__loadShare__-Bs1o8DtQ.js → ActionVisu__loadShare__react_mf_2_dom__loadShare__-DByPam44.js} +1 -1
- package/admin/rules/assets/{ActionVisu__mf_v__runtimeInit__mf_v__-DtUoI3FU.js → ActionVisu__mf_v__runtimeInit__mf_v__-C2JRFvAF.js} +4 -4
- package/admin/rules/assets/bootstrap-B41OwrCv.js +1 -0
- package/admin/rules/assets/hostInit-Dxp6BaAc.js +1 -1
- package/admin/rules/assets/{index-HFkgiWl7.js → index-B9FmXZMM.js} +1 -1
- package/admin/rules/assets/{index-Bvn52imU.js → index-CWRtmMP6.js} +2 -2
- package/admin/rules/assets/{index-DjPMvPni.js → index-CxRjh2hi.js} +1 -1
- package/admin/rules/assets/{virtualExposes-O8-92o9I.js → virtualExposes-fQM_6VMq.js} +2 -2
- package/admin/rules/customRuleBlocks.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js +2 -0
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Ct.js +9 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Ct.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Hue.js +9 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Hue.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Rgb.js +9 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Rgb.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js +9 -0
- package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js +9 -0
- package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js +47 -2
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js +3 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -1
- package/io-package.json +26 -26
- package/package.json +1 -1
- package/admin/rules/assets/bootstrap-Ba57tu25.js +0 -1
|
@@ -177,6 +177,7 @@ class RgbwSingle extends AdjustableControl_1.default {
|
|
|
177
177
|
}
|
|
178
178
|
composeInitObjectColorTemperature() {
|
|
179
179
|
const map = this.statesMap;
|
|
180
|
+
const isMireds = this.states[map.temperature]?.common?.unit === 'mireds';
|
|
180
181
|
return {
|
|
181
182
|
setState: this.states[map.temperature],
|
|
182
183
|
getState: this.states[map.temperature],
|
|
@@ -195,9 +196,17 @@ class RgbwSingle extends AdjustableControl_1.default {
|
|
|
195
196
|
index = index < 0 ? 0 : index;
|
|
196
197
|
return this.colorTemperatureTable[index];
|
|
197
198
|
}
|
|
199
|
+
// Convert Kelvin to mireds
|
|
200
|
+
if (isMireds) {
|
|
201
|
+
return Math.round(1000000 / alexaValue);
|
|
202
|
+
}
|
|
198
203
|
return alexaValue;
|
|
199
204
|
},
|
|
200
205
|
alexaGetter: function (value) {
|
|
206
|
+
// Convert Mireds to Kelvin
|
|
207
|
+
if (isMireds) {
|
|
208
|
+
return Math.round(1000000 / value);
|
|
209
|
+
}
|
|
201
210
|
return value;
|
|
202
211
|
},
|
|
203
212
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RgbwSing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alize_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 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 return alexaValue as number;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value as number;\n },\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,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC3D,CAAC;QAED,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAA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K,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;SACJ,CAAC;IACN,CAAC;CACJ;AA7OD,6BA6OC","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 };\n }\n}\n"]}
|
|
@@ -51,6 +51,26 @@ const ChangeReport_1 = __importDefault(require("./Alexa/Directives/ChangeReport"
|
|
|
51
51
|
const Discovery_1 = __importDefault(require("./Alexa/Directives/Discovery"));
|
|
52
52
|
const ReportState_1 = __importDefault(require("./Alexa/Directives/ReportState"));
|
|
53
53
|
const node_crypto_1 = require("node:crypto");
|
|
54
|
+
const GroupWord = {
|
|
55
|
+
en: 'Group',
|
|
56
|
+
de: 'Gruppe',
|
|
57
|
+
it: 'Gruppo',
|
|
58
|
+
fr: 'Groupe',
|
|
59
|
+
ru: 'Группа',
|
|
60
|
+
es: 'Grupo',
|
|
61
|
+
pl: 'Grupa',
|
|
62
|
+
nl: 'Groep',
|
|
63
|
+
};
|
|
64
|
+
const DeviceWord = {
|
|
65
|
+
en: 'Device',
|
|
66
|
+
de: 'Gerät',
|
|
67
|
+
it: 'Dispositivo',
|
|
68
|
+
fr: 'Appareil',
|
|
69
|
+
ru: 'Устройство',
|
|
70
|
+
es: 'Dispositivo',
|
|
71
|
+
pl: 'Urządzenie',
|
|
72
|
+
nl: 'Dispositivo',
|
|
73
|
+
};
|
|
54
74
|
class DeviceManager {
|
|
55
75
|
lang = 'en';
|
|
56
76
|
devices = [];
|
|
@@ -153,6 +173,7 @@ class DeviceManager {
|
|
|
153
173
|
// as long as not all controls mapped to a device...
|
|
154
174
|
// detectedControls = detectedControls.filter(c => ['light', 'dimmer'].includes(c.type));
|
|
155
175
|
const createdGroups = [];
|
|
176
|
+
const usedFriendlyNames = [];
|
|
156
177
|
while (detectedControls.length) {
|
|
157
178
|
// take the next control
|
|
158
179
|
const control = detectedControls[0];
|
|
@@ -164,9 +185,21 @@ class DeviceManager {
|
|
|
164
185
|
item.room?.id === control.room.id &&
|
|
165
186
|
control.functionality &&
|
|
166
187
|
item.functionality?.id === control.functionality.id);
|
|
188
|
+
let friendlyName = Utils.friendlyNameByRoomAndFunctionName(control, this.lang);
|
|
189
|
+
// If a friendly name is already used, append Gruppe, Group, Gruppo, Groupe, etc.
|
|
190
|
+
if (usedFriendlyNames.includes(friendlyName)) {
|
|
191
|
+
let index = 0;
|
|
192
|
+
let newFriendlyName = '';
|
|
193
|
+
do {
|
|
194
|
+
newFriendlyName = `${friendlyName} ${GroupWord[this.lang] || GroupWord.en}${index ? ` ${index}` : ''}`;
|
|
195
|
+
index++;
|
|
196
|
+
} while (usedFriendlyNames.includes(newFriendlyName));
|
|
197
|
+
friendlyName = newFriendlyName;
|
|
198
|
+
}
|
|
199
|
+
usedFriendlyNames.push(friendlyName);
|
|
167
200
|
this.toDevice({
|
|
168
201
|
detectedControls: processedControls,
|
|
169
|
-
friendlyName
|
|
202
|
+
friendlyName,
|
|
170
203
|
autoDetected: true,
|
|
171
204
|
roomName: this.getName(control.room?.common?.name),
|
|
172
205
|
funcName: this.getName(control.functionality?.common?.name),
|
|
@@ -185,9 +218,21 @@ class DeviceManager {
|
|
|
185
218
|
if (!createdGroups.includes(groupName)) {
|
|
186
219
|
createdGroups.push(groupName);
|
|
187
220
|
processedControls = detectedControls.filter(item => item.groupNames?.includes(groupName));
|
|
221
|
+
let friendlyName = this.getName(groupName);
|
|
222
|
+
// If a friendly name is already used, append Device
|
|
223
|
+
if (usedFriendlyNames.includes(friendlyName)) {
|
|
224
|
+
let index = 0;
|
|
225
|
+
let newFriendlyName = '';
|
|
226
|
+
do {
|
|
227
|
+
newFriendlyName = `${friendlyName} ${DeviceWord[this.lang] || DeviceWord.en}${index ? ` ${index}` : ''}`;
|
|
228
|
+
index++;
|
|
229
|
+
} while (usedFriendlyNames.includes(newFriendlyName));
|
|
230
|
+
friendlyName = newFriendlyName;
|
|
231
|
+
}
|
|
232
|
+
usedFriendlyNames.push(friendlyName);
|
|
188
233
|
this.toDevice({
|
|
189
234
|
detectedControls: processedControls,
|
|
190
|
-
friendlyName
|
|
235
|
+
friendlyName,
|
|
191
236
|
autoDetected: false,
|
|
192
237
|
toggle: processedControls[0].object?.toggle ?? defaultToggle,
|
|
193
238
|
possibleTypes: processedControls[0].object?.possibleTypes || [],
|
|
@@ -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;AAC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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\nexport default class DeviceManager {\n private lang: ioBroker.Languages = 'en';\n private devices: Device[] = [];\n private subscribed: string[] = [];\n private log: Logger;\n private eventsPausedTill = 0; // timestamp\n\n private collecting = false;\n private recollect = false;\n\n /** Creates a Device Manager */\n constructor() {\n this.log = new Logger(this);\n }\n\n async informAboutStatesChange(): Promise<void> {\n await AdapterProvider.get().setStateAsync('smart.updates3', true, true);\n }\n\n get language(): ioBroker.Languages {\n return this.lang;\n }\n\n set language(value: ioBroker.Languages) {\n this.lang = value;\n }\n\n matchDirective(event: AlexaV3Request): ChangeReport | Discovery | ReportState | null {\n if (ChangeReport.matches(event)) {\n return new ChangeReport();\n }\n if (Discovery.matches(event)) {\n return new Discovery();\n }\n if (ReportState.matches(event)) {\n return new ReportState();\n }\n\n return null;\n }\n\n get endpoints(): Device[] {\n return this.devices;\n }\n\n endpointById(id: AlexaV3EndpointID): Device | undefined {\n return this.devices.find(device => device.id === id);\n }\n\n addDevice(device: Device): void {\n this.devices.push(device);\n }\n\n toDevice(options: {\n detectedControls: IotExternalPatternControl[];\n friendlyName: string;\n autoDetected: boolean;\n roomName?: string;\n funcName?: string;\n toggle?: boolean;\n possibleTypes: Types[];\n typeWasDetected: boolean;\n }): Device | undefined {\n const controls: Control[] = [];\n\n this.log.debug(`merging controls to a device with name ${options.friendlyName}`);\n\n options.detectedControls.forEach(item => {\n this.log.silly(`processing control: ${JSON.stringify(item)}`);\n const control = Controls.factory(item);\n\n if (control) {\n this.log.debug(`\"${item.type}\" added to \"${options.friendlyName}\"`);\n controls.push(control);\n } else {\n this.log.debug(`control of type \"${item.type}\" not supported yet. Skipped.`);\n }\n });\n\n if (!controls.length) {\n // the controls are not supported yet...\n return;\n }\n\n // create and add a new device to the collected devices\n this.addDevice(\n new Device({\n id: options.friendlyName,\n friendlyName: options.friendlyName,\n controls,\n autoDetected: options.autoDetected,\n roomName: options.roomName,\n funcName: options.funcName,\n toggle: options.toggle,\n possibleTypes: options.possibleTypes,\n typeWasDetected: options.typeWasDetected,\n }),\n );\n }\n\n getName(name: ioBroker.StringOrTranslated | undefined): string {\n if (!name) {\n return '';\n }\n if (typeof name === 'object') {\n return name[this.lang] || name.en || '';\n }\n return name;\n }\n\n async collectEndpoints(): Promise<void> {\n if (this.collecting) {\n this.log.debug(`collecting devices already in progress. Skipping...`);\n this.recollect = true;\n return;\n }\n this.collecting = true;\n this.log.debug(`(re)collecting devices...`);\n try {\n // const discoveryNeeded = this.devices.length > 0;\n\n this.devices = [];\n const defaultToggle = AdapterProvider.get().config.defaultToggle || false;\n\n // collect all iobroker controls in terms of iobroker type detector (https://github.com/ioBroker/ioBroker.type-detector)\n let 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\n while (detectedControls.length) {\n // take the next control\n const control = detectedControls[0];\n let processedControls: IotExternalPatternControl[] = [];\n\n if (control.room?.common?.name) {\n if (control.functionality?.common?.name) {\n // controls in the same room with the same functionality\n processedControls = detectedControls.filter(\n item =>\n control.room &&\n item.room?.id === control.room.id &&\n control.functionality &&\n item.functionality?.id === control.functionality.id,\n );\n this.toDevice({\n detectedControls: processedControls,\n friendlyName: Utils.friendlyNameByRoomAndFunctionName(control, this.lang),\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 } else if (control.groupNames) {\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: 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 });\n } else {\n // neither room nor smart name\n this.log.debug(`Control of type [${control.type}] has neither room no smart name. Skipped.`);\n }\n\n if (!processedControls.length) {\n processedControls = [control];\n }\n\n // remove processed controls\n const objectIds = processedControls.map(item => item.object?.id);\n detectedControls = detectedControls.filter(item => item.object && !objectIds.includes(item.object.id));\n }\n\n // done\n this.log.debug(`finished collecting devices. there is/are ${this.devices.length} device(s) in total`);\n for (const device of this.devices) {\n this.log.debug(`${device.toString()}`);\n }\n\n // a new discovery process is needed in case we had already devices and device collection was\n // triggered again by, e.g., a change in room/function enums\n // if (discoveryNeeded) {\n // this.log.info(`Please delete all managed by ioBroker devices in your Alexa app and then start discovery`);\n // }\n\n // collect all relevant states to subscribe to updates\n const stateIds = new Set(\n this.devices\n .flatMap(d => d.controls)\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .map(item => item.getId)\n .filter(id => id),\n );\n this.log.debug(`registering for updates of total ${stateIds.size} states`);\n const newSubscribed = Array.from(stateIds);\n const subscribe: string[] = [];\n for (const id of newSubscribed) {\n this.log.silly(`subscribing to updates of ${id}`);\n if (!this.subscribed.includes(id)) {\n this.subscribed.push(id);\n if (!subscribe.includes(id)) {\n subscribe.push(id);\n }\n }\n }\n\n this.subscribed.sort();\n\n // wait till all promises are settled\n if (subscribe.length) {\n await AdapterProvider.subscribe(subscribe);\n }\n\n // unsubscribe from unused states\n const unsubscribe: string[] = [];\n for (let i = this.subscribed.length - 1; i >= 0; i--) {\n const id = this.subscribed[i];\n if (!newSubscribed.includes(id)) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n this.subscribed.splice(i, 1);\n if (!unsubscribe.includes(id)) {\n unsubscribe.push(id);\n }\n }\n }\n if (unsubscribe.length) {\n await AdapterProvider.unsubscribe(unsubscribe);\n }\n } catch (e) {\n this.log.error(`failed to collect devices: ${e}`);\n if (e.stack) {\n this.log.error(e.stack);\n }\n }\n\n this.collecting = false;\n\n // if during the collection a new collection was triggered, start collecting again\n if (this.recollect) {\n this.recollect = false;\n setTimeout(() => this.collectEndpoints(), 1000);\n }\n }\n\n async destroy(): Promise<void> {\n const promises = [];\n for (const id of this.subscribed) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n promises.push(AdapterProvider.subscribe(id));\n }\n await Promise.allSettled(promises);\n\n this.subscribed = [];\n }\n\n publishStateChange(stateChange: AlexaResponse): void {\n if (this.eventsPausedTill < Date.now()) {\n this.log.silly(`publishing ${JSON.stringify(stateChange)}`);\n IotProxy.publishStateChange(stateChange);\n }\n }\n\n pauseEvents(): void {\n this.eventsPausedTill = Date.now() + 30 * 60 * 1000; // 30 minutes\n }\n\n async executeWithinRateLimits(\n endpointId: AlexaV3EndpointID,\n awaitable: () => Promise<AlexaResponse>,\n errorResponse: AlexaResponse,\n ): Promise<AlexaResponse> {\n try {\n await RateLimiter.incrementAndGet(endpointId);\n return await awaitable();\n } catch (error) {\n if (error instanceof OverallDailyRateLimitExceeded || error instanceof HourlyDeviceRateLimitExceeded) {\n this.log.warn(error.message);\n } else {\n this.log.error(error.message);\n }\n\n return errorResponse;\n }\n }\n\n async handleAlexaEvent(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`incoming Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n if (!event?.directive?.header) {\n throw new Error('Alexa event header is missing');\n }\n\n let response: AlexaResponse;\n const directive = this.matchDirective(event);\n if (directive) {\n response = await directive.handle(event, this);\n } else {\n const endpointId = event?.directive?.endpoint?.endpointId;\n const device = endpointId ? this.endpointById(endpointId) : undefined;\n\n if (device) {\n if (device.supports(event)) {\n response = await this.executeWithinRateLimits(\n endpointId!,\n async () => {\n response = await device.handle(event);\n if (!AlexaResponse.isErrorResponse(response)) {\n // report state change via voice interaction\n const propertyName = response.context?.properties[0].name;\n const responseEvent = ChangeReport.get(\n device.id,\n propertyName || '',\n false,\n event.directive.header.messageId,\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n // get device state (not just one control)\n const deviceState = await device.reportState();\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n // fire state change report to Alexa\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n this.publishStateChange(stateChange);\n }\n await this.informAboutStatesChange();\n } else {\n this.log.debug(\n `ignoring state change event for ${endpointId} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n return response;\n },\n AlexaResponse.throttlingException(event.directive.header.messageId).get(),\n );\n } else {\n response = AlexaResponse.directiveNotSupportedByDevice(\n device.friendlyName,\n event.directive.header.namespace,\n event.directive.header.messageId,\n event.directive.header.payloadVersion,\n ).get();\n }\n } else {\n response = AlexaResponse.endpointUnreachable(event.directive.header.messageId).get();\n }\n }\n\n this.log.silly(`response: ${JSON.stringify(response)}`);\n return response;\n }\n\n async handleStateUpdate(id: string, state: ioBroker.State | null | undefined): Promise<void> {\n // ignore updates not confirmed by a corresponding device\n if (!state?.ack) {\n this.log.silly(`ignoring state change event for ${id} due to state.ack == ${state?.ack}`);\n return;\n }\n if (id.startsWith(`${AdapterProvider.get().namespace}.`)) {\n // nop, this is just to inform Alexa app about changes\n return;\n }\n\n let notFound = true;\n\n for (const device of this.devices) {\n const property = device.controls\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .find(item => item.getId === id);\n\n if (property) {\n notFound = false;\n if (property.currentValue === state.val) {\n this.log.debug(`ignoring state change event for ${id} due to the same value [${state.val}]`);\n } else {\n property.currentValue = state.val;\n\n const responseEvent = Directives.ChangeReport.get(\n device.id,\n property.propertyName,\n true,\n randomUUID(),\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n\n // get device state (not just one control)\n const deviceState = await device.reportState();\n\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n await this.informAboutStatesChange();\n // fire state change report to Alexa\n\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n await this.executeWithinRateLimits(\n device.id,\n () => {\n this.publishStateChange(stateChange);\n return Promise.resolve(stateChange);\n },\n AlexaResponse.throttlingException(responseEvent.directive.header.messageId).get(),\n );\n }\n } else {\n this.log.debug(\n `ignoring state change event for ${id} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n\n // should be the only device having the id => stop processing here\n break;\n }\n }\n\n // this should never happen\n if (notFound) {\n this.log.debug(`state id ${id} doesn't belong to any device`);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DeviceManager.js","sourceRoot":"","sources":["../../../src/l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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;AAneD,gCAmeC","sourcesContent":["import Device from './Device';\nimport * as Utils from './Helpers/Utils';\nimport Directives from './Alexa/Directives';\nimport Controls from './Controls';\nimport type Control from './Controls/Control';\nimport Logger from './Helpers/Logger';\nimport AdapterProvider from './Helpers/AdapterProvider';\nimport AlexaResponse from './Alexa/AlexaResponse';\nimport IotProxy from './Helpers/IotProxy';\nimport RateLimiter from './Helpers/RateLimiter';\nimport OverallDailyRateLimitExceeded from './Exceptions/OverallDailyRateLimitExceeded';\nimport HourlyDeviceRateLimitExceeded from './Exceptions/HourlyDeviceRateLimitExceeded';\nimport type { AlexaV3EndpointID, AlexaV3Request, IotExternalPatternControl } from './types';\nimport ChangeReport from './Alexa/Directives/ChangeReport';\nimport Discovery from './Alexa/Directives/Discovery';\nimport ReportState from './Alexa/Directives/ReportState';\nimport { randomUUID } from 'node:crypto';\nimport type { Types } from '@iobroker/type-detector';\n\nconst GroupWord: { [lang: string]: string } = {\n en: 'Group',\n de: 'Gruppe',\n it: 'Gruppo',\n fr: 'Groupe',\n ru: 'Группа',\n es: 'Grupo',\n pl: 'Grupa',\n nl: 'Groep',\n};\nconst DeviceWord: { [lang: string]: string } = {\n en: 'Device',\n de: 'Gerät',\n it: 'Dispositivo',\n fr: 'Appareil',\n ru: 'Устройство',\n es: 'Dispositivo',\n pl: 'Urządzenie',\n nl: 'Dispositivo',\n};\n\nexport default class DeviceManager {\n private lang: ioBroker.Languages = 'en';\n private devices: Device[] = [];\n private subscribed: string[] = [];\n private log: Logger;\n private eventsPausedTill = 0; // timestamp\n\n private collecting = false;\n private recollect = false;\n\n /** Creates a Device Manager */\n constructor() {\n this.log = new Logger(this);\n }\n\n async informAboutStatesChange(): Promise<void> {\n await AdapterProvider.get().setStateAsync('smart.updates3', true, true);\n }\n\n get language(): ioBroker.Languages {\n return this.lang;\n }\n\n set language(value: ioBroker.Languages) {\n this.lang = value;\n }\n\n matchDirective(event: AlexaV3Request): ChangeReport | Discovery | ReportState | null {\n if (ChangeReport.matches(event)) {\n return new ChangeReport();\n }\n if (Discovery.matches(event)) {\n return new Discovery();\n }\n if (ReportState.matches(event)) {\n return new ReportState();\n }\n\n return null;\n }\n\n get endpoints(): Device[] {\n return this.devices;\n }\n\n endpointById(id: AlexaV3EndpointID): Device | undefined {\n return this.devices.find(device => device.id === id);\n }\n\n addDevice(device: Device): void {\n this.devices.push(device);\n }\n\n toDevice(options: {\n detectedControls: IotExternalPatternControl[];\n friendlyName: string;\n autoDetected: boolean;\n roomName?: string;\n funcName?: string;\n toggle?: boolean;\n possibleTypes: Types[];\n typeWasDetected: boolean;\n }): Device | undefined {\n const controls: Control[] = [];\n\n this.log.debug(`merging controls to a device with name ${options.friendlyName}`);\n\n options.detectedControls.forEach(item => {\n this.log.silly(`processing control: ${JSON.stringify(item)}`);\n const control = Controls.factory(item);\n\n if (control) {\n this.log.debug(`\"${item.type}\" added to \"${options.friendlyName}\"`);\n controls.push(control);\n } else {\n this.log.debug(`control of type \"${item.type}\" not supported yet. Skipped.`);\n }\n });\n\n if (!controls.length) {\n // the controls are not supported yet...\n return;\n }\n\n // create and add a new device to the collected devices\n this.addDevice(\n new Device({\n id: options.friendlyName,\n friendlyName: options.friendlyName,\n controls,\n autoDetected: options.autoDetected,\n roomName: options.roomName,\n funcName: options.funcName,\n toggle: options.toggle,\n possibleTypes: options.possibleTypes,\n typeWasDetected: options.typeWasDetected,\n }),\n );\n }\n\n getName(name: ioBroker.StringOrTranslated | undefined): string {\n if (!name) {\n return '';\n }\n if (typeof name === 'object') {\n return name[this.lang] || name.en || '';\n }\n return name;\n }\n\n async collectEndpoints(): Promise<void> {\n if (this.collecting) {\n this.log.debug(`collecting devices already in progress. Skipping...`);\n this.recollect = true;\n return;\n }\n this.collecting = true;\n this.log.debug(`(re)collecting devices...`);\n try {\n // const discoveryNeeded = this.devices.length > 0;\n\n this.devices = [];\n const defaultToggle = AdapterProvider.get().config.defaultToggle || false;\n\n // collect all iobroker controls in terms of iobroker type detector (https://github.com/ioBroker/ioBroker.type-detector)\n let detectedControls = await Utils.controls(AdapterProvider.get(), this.lang);\n\n this.log.debug(`type detector found ${detectedControls.length} controls`);\n\n // Normally, every control is a smart device. But due to the iobroker concept of 'rooms and functions'\n // multiple controls might be merged to a single device.\n\n // as long as not all controls mapped to a device...\n\n // detectedControls = detectedControls.filter(c => ['light', 'dimmer'].includes(c.type));\n const createdGroups: string[] = [];\n const usedFriendlyNames: string[] = [];\n\n while (detectedControls.length) {\n // take the next control\n const control = detectedControls[0];\n let processedControls: IotExternalPatternControl[] = [];\n\n if (control.room?.common?.name) {\n if (control.functionality?.common?.name) {\n // controls in the same room with the same functionality\n processedControls = detectedControls.filter(\n item =>\n control.room &&\n item.room?.id === control.room.id &&\n control.functionality &&\n item.functionality?.id === control.functionality.id,\n );\n let friendlyName = Utils.friendlyNameByRoomAndFunctionName(control, this.lang);\n // If a friendly name is already used, append Gruppe, Group, Gruppo, Groupe, etc.\n if (usedFriendlyNames.includes(friendlyName)) {\n let index = 0;\n let newFriendlyName = '';\n do {\n newFriendlyName = `${friendlyName} ${GroupWord[this.lang] || GroupWord.en}${index ? ` ${index}` : ''}`;\n index++;\n } while (usedFriendlyNames.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\n usedFriendlyNames.push(friendlyName);\n\n this.toDevice({\n detectedControls: processedControls,\n friendlyName,\n autoDetected: true,\n roomName: this.getName(control.room?.common?.name),\n funcName: this.getName(control.functionality?.common?.name),\n toggle: processedControls[0].object?.toggle ?? defaultToggle,\n possibleTypes: processedControls[0].object?.possibleTypes || [],\n typeWasDetected: processedControls[0].object?.typeWasDetected || false,\n });\n } else {\n this.log.debug(\n `Control of type [${control.type}] assigned to room [${this.getName(control.room.common.name)}] has no function. Skipped.`,\n );\n }\n } else if (control.groupNames) {\n // no room, but smart name (not only one)\n control.groupNames.forEach(groupName => {\n if (!createdGroups.includes(groupName)) {\n createdGroups.push(groupName);\n processedControls = detectedControls.filter(item => item.groupNames?.includes(groupName));\n let friendlyName = this.getName(groupName);\n // If a friendly name is already used, append Device\n if (usedFriendlyNames.includes(friendlyName)) {\n let index = 0;\n let newFriendlyName = '';\n do {\n newFriendlyName = `${friendlyName} ${DeviceWord[this.lang] || DeviceWord.en}${index ? ` ${index}` : ''}`;\n index++;\n } while (usedFriendlyNames.includes(newFriendlyName));\n friendlyName = newFriendlyName;\n }\n usedFriendlyNames.push(friendlyName);\n\n this.toDevice({\n detectedControls: processedControls,\n friendlyName,\n autoDetected: false,\n toggle: processedControls[0].object?.toggle ?? defaultToggle,\n possibleTypes: processedControls[0].object?.possibleTypes || [],\n typeWasDetected: processedControls[0].object?.typeWasDetected || false,\n });\n }\n });\n } else {\n // neither room nor smart name\n this.log.debug(`Control of type [${control.type}] has neither room no smart name. Skipped.`);\n }\n\n if (!processedControls.length) {\n processedControls = [control];\n }\n\n // remove processed controls\n const objectIds = processedControls.map(item => item.object?.id);\n detectedControls = detectedControls.filter(item => item.object && !objectIds.includes(item.object.id));\n }\n\n // done\n this.log.debug(`finished collecting devices. there is/are ${this.devices.length} device(s) in total`);\n for (const device of this.devices) {\n this.log.debug(`${device.toString()}`);\n }\n\n // a new discovery process is needed in case we had already devices and device collection was\n // triggered again by, e.g., a change in room/function enums\n // if (discoveryNeeded) {\n // this.log.info(`Please delete all managed by ioBroker devices in your Alexa app and then start discovery`);\n // }\n\n // collect all relevant states to subscribe to updates\n const stateIds = new Set(\n this.devices\n .flatMap(d => d.controls)\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .map(item => item.getId)\n .filter(id => id),\n );\n this.log.debug(`registering for updates of total ${stateIds.size} states`);\n const newSubscribed = Array.from(stateIds);\n const subscribe: string[] = [];\n for (const id of newSubscribed) {\n this.log.silly(`subscribing to updates of ${id}`);\n if (!this.subscribed.includes(id)) {\n this.subscribed.push(id);\n if (!subscribe.includes(id)) {\n subscribe.push(id);\n }\n }\n }\n\n this.subscribed.sort();\n\n // wait till all promises are settled\n if (subscribe.length) {\n await AdapterProvider.subscribe(subscribe);\n }\n\n // unsubscribe from unused states\n const unsubscribe: string[] = [];\n for (let i = this.subscribed.length - 1; i >= 0; i--) {\n const id = this.subscribed[i];\n if (!newSubscribed.includes(id)) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n this.subscribed.splice(i, 1);\n if (!unsubscribe.includes(id)) {\n unsubscribe.push(id);\n }\n }\n }\n if (unsubscribe.length) {\n await AdapterProvider.unsubscribe(unsubscribe);\n }\n } catch (e) {\n this.log.error(`failed to collect devices: ${e}`);\n if (e.stack) {\n this.log.error(e.stack);\n }\n }\n\n this.collecting = false;\n\n // if during the collection a new collection was triggered, start collecting again\n if (this.recollect) {\n this.recollect = false;\n setTimeout(() => this.collectEndpoints(), 1000);\n }\n }\n\n async destroy(): Promise<void> {\n const promises = [];\n for (const id of this.subscribed) {\n this.log.silly(`unsubscribing from updates of ${id}`);\n promises.push(AdapterProvider.subscribe(id));\n }\n await Promise.allSettled(promises);\n\n this.subscribed = [];\n }\n\n publishStateChange(stateChange: AlexaResponse): void {\n if (this.eventsPausedTill < Date.now()) {\n this.log.silly(`publishing ${JSON.stringify(stateChange)}`);\n IotProxy.publishStateChange(stateChange);\n }\n }\n\n pauseEvents(): void {\n this.eventsPausedTill = Date.now() + 30 * 60 * 1000; // 30 minutes\n }\n\n async executeWithinRateLimits(\n endpointId: AlexaV3EndpointID,\n awaitable: () => Promise<AlexaResponse>,\n errorResponse: AlexaResponse,\n ): Promise<AlexaResponse> {\n try {\n await RateLimiter.incrementAndGet(endpointId);\n return await awaitable();\n } catch (error) {\n if (error instanceof OverallDailyRateLimitExceeded || error instanceof HourlyDeviceRateLimitExceeded) {\n this.log.warn(error.message);\n } else {\n this.log.error(error.message);\n }\n\n return errorResponse;\n }\n }\n\n async handleAlexaEvent(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`incoming Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n if (!event?.directive?.header) {\n throw new Error('Alexa event header is missing');\n }\n\n let response: AlexaResponse;\n const directive = this.matchDirective(event);\n if (directive) {\n response = await directive.handle(event, this);\n } else {\n const endpointId = event?.directive?.endpoint?.endpointId;\n const device = endpointId ? this.endpointById(endpointId) : undefined;\n\n if (device) {\n if (device.supports(event)) {\n response = await this.executeWithinRateLimits(\n endpointId!,\n async () => {\n response = await device.handle(event);\n if (!AlexaResponse.isErrorResponse(response)) {\n // report state change via voice interaction\n const propertyName = response.context?.properties[0].name;\n const responseEvent = ChangeReport.get(\n device.id,\n propertyName || '',\n false,\n event.directive.header.messageId,\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n // get device state (not just one control)\n const deviceState = await device.reportState();\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n // fire state change report to Alexa\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n this.publishStateChange(stateChange);\n }\n await this.informAboutStatesChange();\n } else {\n this.log.debug(\n `ignoring state change event for ${endpointId} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n return response;\n },\n AlexaResponse.throttlingException(event.directive.header.messageId).get(),\n );\n } else {\n response = AlexaResponse.directiveNotSupportedByDevice(\n device.friendlyName,\n event.directive.header.namespace,\n event.directive.header.messageId,\n event.directive.header.payloadVersion,\n ).get();\n }\n } else {\n response = AlexaResponse.endpointUnreachable(event.directive.header.messageId).get();\n }\n }\n\n this.log.silly(`response: ${JSON.stringify(response)}`);\n return response;\n }\n\n async handleStateUpdate(id: string, state: ioBroker.State | null | undefined): Promise<void> {\n // ignore updates not confirmed by a corresponding device\n if (!state?.ack) {\n this.log.silly(`ignoring state change event for ${id} due to state.ack == ${state?.ack}`);\n return;\n }\n if (id.startsWith(`${AdapterProvider.get().namespace}.`)) {\n // nop, this is just to inform Alexa app about changes\n return;\n }\n\n let notFound = true;\n\n for (const device of this.devices) {\n const property = device.controls\n .flatMap(item => item.supported)\n .flatMap(item => item.properties)\n .find(item => item.getId === id);\n\n if (property) {\n notFound = false;\n if (property.currentValue === state.val) {\n this.log.debug(`ignoring state change event for ${id} due to the same value [${state.val}]`);\n } else {\n property.currentValue = state.val;\n\n const responseEvent = Directives.ChangeReport.get(\n device.id,\n property.propertyName,\n true,\n randomUUID(),\n );\n const directive = this.matchDirective(responseEvent);\n if (directive) {\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n const stateChange = await directive.handle(responseEvent, this);\n\n // get device state (not just one control)\n const deviceState = await device.reportState();\n\n if (JSON.stringify(device.lastReportedState) !== JSON.stringify(deviceState)) {\n device.lastReportedState = deviceState;\n await this.informAboutStatesChange();\n // fire state change report to Alexa\n\n // BF[2024.02.04]: temporarily disabled as produced a huge number of events\n if (process.env.TESTS_EXECUTION) {\n await this.executeWithinRateLimits(\n device.id,\n () => {\n this.publishStateChange(stateChange);\n return Promise.resolve(stateChange);\n },\n AlexaResponse.throttlingException(responseEvent.directive.header.messageId).get(),\n );\n }\n } else {\n this.log.debug(\n `ignoring state change event for ${id} due to the same_ value [${JSON.stringify(deviceState)}]`,\n );\n }\n }\n }\n\n // should be the only device having the id => stop processing here\n break;\n }\n }\n\n // this should never happen\n if (notFound) {\n this.log.debug(`state id ${id} doesn't belong to any device`);\n }\n }\n}\n"]}
|
|
@@ -612,6 +612,7 @@ async function controls(adapter, lang) {
|
|
|
612
612
|
states: devicesObject[s.id]?.common?.states,
|
|
613
613
|
role: devicesObject[s.id]?.common?.role,
|
|
614
614
|
name: devicesObject[s.id]?.common?.name,
|
|
615
|
+
unit: devicesObject[s.id]?.common?.unit,
|
|
615
616
|
};
|
|
616
617
|
});
|
|
617
618
|
devicesObject[id].common.smartName = smartName;
|
|
@@ -637,7 +638,7 @@ async function controls(adapter, lang) {
|
|
|
637
638
|
}
|
|
638
639
|
}
|
|
639
640
|
const name = smartName[lang] || smartName.en || smartName.de;
|
|
640
|
-
control.groupNames = name?.split(',').map(n => n.trim()) || [];
|
|
641
|
+
control.groupNames = (name?.split(',').map(n => n.trim()) || []).filter(n => n);
|
|
641
642
|
adapter.log.debug(`[ALEXA3] added ${id} with smartName as "${smartName.smartType}"`);
|
|
642
643
|
detectedControls.push(control);
|
|
643
644
|
}
|
|
@@ -683,6 +684,7 @@ async function controls(adapter, lang) {
|
|
|
683
684
|
states: devicesObject[s.id]?.common?.states,
|
|
684
685
|
role: devicesObject[s.id]?.common?.role,
|
|
685
686
|
name: devicesObject[s.id]?.common?.name,
|
|
687
|
+
unit: devicesObject[s.id]?.common?.unit,
|
|
686
688
|
};
|
|
687
689
|
});
|
|
688
690
|
if (smartDisabled) {
|