iobroker.iot 4.1.2 → 4.1.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 +5 -3
- package/admin/assets/{index-6Itc0U48.js → index-CyfkYMpa.js} +85 -85
- package/admin/index_m.html +1 -1
- package/admin/rules/assets/{index-208Qrr3S.js → index-DBQ_ihVx.js} +83 -83
- package/admin/rules/customRuleBlocks.js +2 -2
- package/build/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js +7 -0
- package/build/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js +3 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/SceneController.js +38 -0
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/SceneController.js.map +1 -0
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js +2 -0
- package/build/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js +67 -14
- package/build/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Button.js +74 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Button.js.map +1 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Control.js +2 -0
- package/build/lib/AlexaSmartHomeV3/Controls/Control.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Ct.js +1 -7
- package/build/lib/AlexaSmartHomeV3/Controls/Ct.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Hue.js +8 -5
- package/build/lib/AlexaSmartHomeV3/Controls/Hue.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/Light.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js +200 -0
- package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js.map +1 -0
- package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js +210 -0
- package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js.map +1 -0
- package/build/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Controls/index.js +15 -3
- package/build/lib/AlexaSmartHomeV3/Controls/index.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js +9 -2
- package/build/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -1
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js +287 -0
- package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -1
- package/build/lib/alexaCustom.js +1 -1
- package/build/lib/alexaCustom.js.map +1 -1
- package/io-package.json +14 -14
- package/package.json +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Control.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Control.ts"],"names":[],"mappings":";;;;;AAAA,2EAAmD;AACnD,4CAAuH;AACvH,+DAAuC;AACvC,iFAAyD;AAEzD,gFAAwD;AACxD,wFAAgE;AAWhE;;;GAGG;AACH,MAAqB,OAAO;IACxB,MAAM,CAAC,SAAS,GAAG;QACf,KAAK;QACL,QAAQ;QACR,QAAQ;QACR,WAAW;QACX,OAAO;QACP,MAAM;QACN,KAAK;QACL,QAAQ;QACR,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,IAAI;QACJ,MAAM;KACT,CAAC;IACc,GAAG,CAAS;IAClB,UAAU,CAAqB;IAC/B,SAAS,CAAqB;IACrB,OAAO,GAAyD,EAAE,CAAC;IAEtF;;OAEG;IACH,YAAY,eAA0C;QAClD,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,IAA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ensureValueInRange_0_100, denormalize_0_100, normalize_0_100 } from '../Helpers/Utils';\nimport Logger from '../Helpers/Logger';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport type { ControlStateInitObject, Base as PropertiesBase } from '../Alexa/Properties/Base';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport DetectionState from '../Alexa/Properties/DetectionState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ReportedState,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\nimport type { Base as CapabilitiesBase } from '../Alexa/Capabilities/Base';\n\n/**\n * Represents the base functionality for a control in a smart device. A smart device has at least one control.\n * The specific functionality, natively supported capabilities, etc. are defined in derived classes.\n */\nexport default class Control {\n static stateKeys = [\n 'SET',\n 'ACTUAL',\n 'ON_SET',\n 'ON_ACTUAL',\n 'POWER',\n 'MODE',\n 'HUE',\n 'DIMMER',\n 'BRIGHTNESS',\n 'SATURATION',\n 'TEMPERATURE',\n 'ON',\n 'MUTE',\n ];\n public readonly log: Logger;\n protected _supported: CapabilitiesBase[];\n protected _enforced: CapabilitiesBase[];\n protected readonly _states: Record<string, IotExternalDetectorState | undefined> = {};\n\n /**\n * @param detectedControl - The detected control in terms of iobroker type detector.\n */\n constructor(detectedControl: IotExternalPatternControl) {\n this.log = new Logger(this);\n this.log.silly(`created instance`);\n\n this.initStates(detectedControl);\n this._supported = [];\n this._enforced = [];\n }\n\n get allCapabilities(): CapabilitiesBase[] {\n return this.supported.concat(this.enforced);\n }\n\n static get type(): string {\n return firstLower(className(this.toString()));\n }\n /**\n * Getter for Alexa categories\n */\n get categories(): AlexaV3Category[] {\n return ['OTHER'];\n }\n\n get name(): string {\n return `${this.constructor.name}`;\n }\n /**\n * Getter for _supported\n */\n get supported(): CapabilitiesBase[] {\n return this._supported;\n }\n /**\n * Getter for _enforced\n */\n get enforced(): CapabilitiesBase[] {\n return this._enforced;\n }\n /**\n * This function returns whether the control natively supports the passed on Alexa directive.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control natively supports the directive, false - otherwise\n */\n supports(event: AlexaV3Request): boolean {\n return this.supported.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function returns whether the control though doesn't natively support the passed on Alexa directive, but able to handle it.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control can handle the directive, false - otherwise\n */\n canHandle(event: AlexaV3Request): boolean {\n return this.enforced.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value\n * as a reaction to an interaction with Alexa via voice, app, etc.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns Object containing the response to be sent to Alexa Service\n */\n async handle(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`handling Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n\n const property = this.allCapabilities\n .flatMap(item => item.properties)\n .find(property => property.matches(event));\n\n if (property) {\n let alexaValue: AlexaV3DirectiveValue;\n try {\n const setter = this.valueSetter(event);\n alexaValue = await setter(event, property);\n } catch (error) {\n this.log.debug(`${error}`);\n this.log.error(`failed handling Alexa event`);\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(AlexaResponse.endpointUnreachable(event.directive.header.messageId).get());\n }\n\n // even though the handler successfully processed the Alexa event,\n // we return an error here for ENFORCED capabilities, to prevent\n // reporting multiple successes for the same capability and\n // running into a situation of returning a wrong value back to Alexa\n if (this.enforced.find(capability => capability.matches(event))) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(\n AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n ).get(),\n );\n }\n\n const response = AlexaResponse.handled(\n event,\n property.propertyName,\n property.reportValue(alexaValue),\n property.instance,\n );\n\n // though the processed directive required to change a single value, the response must contain values of all \"relevant\" properties\n // Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event\n\n // TODO: add values of relevant properties to response\n\n this.log.silly(`${JSON.stringify(response.get())}`);\n return response.get();\n }\n\n const errorResponse = AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n );\n this.log.silly(`${JSON.stringify(errorResponse.get())}`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(errorResponse.get());\n }\n\n valueSetter(\n _event: AlexaV3Request,\n ): (event: AlexaV3Request, property: PropertiesBase) => Promise<AlexaV3DirectiveValue> {\n return this.setValue.bind(this);\n }\n\n async setValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract alexa value from event\n const alexaValue = property.alexaDirectiveValue(event);\n\n // convert alexa value to iobroker value\n let value = property.value(alexaValue);\n\n // if set, the device could support toggle\n if (event.currentState) {\n // console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);\n const state = event.currentState.find(item => item.name === property.propertyName);\n if (state && value === true) {\n // it could support toggle.\n // get current value\n const current = property.value(state.value);\n if (current === true) {\n // turn off\n value = false;\n } else if (current !== false) {\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n if (currentValue === true) {\n // turn off\n value = false;\n }\n }\n }\n }\n\n // set iobroker state\n await this.setState(property, value!);\n\n property.currentValue = value;\n // return value as expected by Alexa\n return property.alexaValue(value);\n }\n\n async adjustValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract Alexa delta value from event\n const delta = property.alexaDirectiveValue(event);\n // get current value\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n // convert the current value to Alexa value\n const valueToAdjust = property.alexaValue(currentValue);\n // adjust Alexa value\n const adjustedValue = ensureValueInRange_0_100(\n parseFloat((valueToAdjust as string) || '0') + parseFloat((delta as string) || '0'),\n );\n // convert adjusted value to iobroker value\n const value = property.value(adjustedValue);\n\n // set iobroker state\n await this.setState(property, value as ioBroker.StateValue);\n\n return adjustedValue;\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n if (property.currentValue === undefined) {\n const id = property.getId;\n if (!id) {\n throw new Error(`no ID defined for property \"${property.propertyName}\" of \"${this.name}\"`);\n }\n property.currentValue = await AdapterProvider.getState(id);\n }\n\n if (property.currentValue === undefined) {\n throw new Error(`unable to retrieve ${property.getId}`);\n }\n\n return property.currentValue;\n }\n\n async reportState(): Promise<AlexaV3ReportedState[]> {\n const propertiesToReport: AlexaV3ReportedState[] = [];\n\n for (const capability of this.supported) {\n for (const property of capability.properties) {\n try {\n await this.getOrRetrieveCurrentValue(property);\n\n const toReport: AlexaV3ReportedState = {\n namespace: capability.namespace,\n instance: property.instance,\n name: property.propertyName,\n value: property.reportValue(property.alexaValue(property.currentValue)),\n };\n\n if (!toReport.instance) {\n delete toReport.instance;\n }\n\n propertiesToReport.push(toReport);\n } catch (error) {\n this.log.error(`failed reporting state for property \"${property.propertyName}\" of \"${this.name}\"`);\n if (error.stack) {\n this.log.debug(`${error.stack}`);\n }\n this.log.debug(`${error}`);\n }\n }\n }\n\n this.log.debug(`reporting state: ${JSON.stringify(propertiesToReport)}`);\n return propertiesToReport;\n }\n\n toString(): string {\n return `${this.constructor.name}`;\n }\n\n private initStates(ctrl: IotExternalPatternControl): void {\n for (const stateKey of Control.stateKeys) {\n this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);\n }\n }\n\n get states(): Record<string, IotExternalDetectorState | undefined> {\n return this._states;\n }\n\n get statesMap(): Record<string, string> {\n const map: Record<string, string> = {};\n for (const stateKey of Control.stateKeys) {\n map[stateKey.toLowerCase()] = stateKey;\n }\n return map;\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\n\n //-------------------------------------------------------\n // standard property init objects\n //\n\n protected blankInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n };\n }\n\n protected powerStateInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (alexaValue) {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n protected detectedStateInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (_alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n // should be never called\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? DetectionState.DETECTED : DetectionState.NOT_DETECTED;\n },\n };\n }\n\n protected percentageInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n // const range = configuredRangeOrDefault(this.states[map.set]);\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(\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 };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Control.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Control.ts"],"names":[],"mappings":";;;;;AAAA,2EAAmD;AACnD,4CAAuH;AACvH,+DAAuC;AACvC,iFAAyD;AAEzD,gFAAwD;AACxD,wFA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AAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAE;YAClC,WAAW,EAAE,UAAgC,UAAiC;gBAC1E,OAAO,CACH,IAAA,yBAAiB,EACb,UAAoB,EACpB,IAAI,CAAC,cAAwB,EAC7B,IAAI,CAAC,cAAwB,CAChC,IAAI,CAAC,CACT,CAAC;YACN,CAAC;YACD,WAAW,EAAE,UAET,KAAsC;gBAEtC,OAAO,IAAA,uBAAe,EAAC,KAAe,EAAE,IAAI,CAAC,cAAwB,EAAE,IAAI,CAAC,cAAwB,CAAC,CAAC;YAC1G,CAAC;SACJ,CAAC;IACN,CAAC;;AAtWL,0BAuWC","sourcesContent":["import AlexaResponse from '../Alexa/AlexaResponse';\nimport { firstLower, className, ensureValueInRange_0_100, denormalize_0_100, normalize_0_100 } from '../Helpers/Utils';\nimport Logger from '../Helpers/Logger';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport type { ControlStateInitObject, Base as PropertiesBase } from '../Alexa/Properties/Base';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport DetectionState from '../Alexa/Properties/DetectionState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ReportedState,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\nimport type { Base as CapabilitiesBase } from '../Alexa/Capabilities/Base';\n\nexport type StateName =\n | 'SET'\n | 'ACTUAL'\n | 'ON_SET'\n | 'ON_ACTUAL'\n | 'POWER'\n | 'MODE'\n | 'HUE'\n | 'RGB'\n | 'RGBW'\n | 'DIMMER'\n | 'BRIGHTNESS'\n | 'SATURATION'\n | 'TEMPERATURE'\n | 'ON'\n | 'MUTE';\n\n/**\n * Represents the base functionality for a control in a smart device. A smart device has at least one control.\n * The specific functionality, natively supported capabilities, etc. are defined in derived classes.\n */\nexport default class Control {\n static stateKeys: StateName[] = [\n 'SET',\n 'ACTUAL',\n 'ON_SET',\n 'ON_ACTUAL',\n 'POWER',\n 'MODE',\n 'HUE',\n 'RGB',\n 'RGBW',\n 'DIMMER',\n 'BRIGHTNESS',\n 'SATURATION',\n 'TEMPERATURE',\n 'ON',\n 'MUTE',\n ];\n public readonly log: Logger;\n protected _supported: CapabilitiesBase[];\n protected _enforced: CapabilitiesBase[];\n protected readonly _states: Record<string, IotExternalDetectorState | undefined> = {};\n\n /**\n * @param detectedControl - The detected control in terms of iobroker type detector.\n */\n constructor(detectedControl: IotExternalPatternControl) {\n this.log = new Logger(this);\n this.log.silly(`created instance`);\n\n this.initStates(detectedControl);\n this._supported = [];\n this._enforced = [];\n }\n\n get allCapabilities(): CapabilitiesBase[] {\n return this.supported.concat(this.enforced);\n }\n\n static get type(): string {\n return firstLower(className(this.toString()));\n }\n /**\n * Getter for Alexa categories\n */\n get categories(): AlexaV3Category[] {\n return ['OTHER'];\n }\n\n get name(): string {\n return `${this.constructor.name}`;\n }\n /**\n * Getter for _supported\n */\n get supported(): CapabilitiesBase[] {\n return this._supported;\n }\n /**\n * Getter for _enforced\n */\n get enforced(): CapabilitiesBase[] {\n return this._enforced;\n }\n /**\n * This function returns whether the control natively supports the passed on Alexa directive.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control natively supports the directive, false - otherwise\n */\n supports(event: AlexaV3Request): boolean {\n return this.supported.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function returns whether the control though doesn't natively support the passed on Alexa directive, but able to handle it.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control can handle the directive, false - otherwise\n */\n canHandle(event: AlexaV3Request): boolean {\n return this.enforced.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value\n * as a reaction to an interaction with Alexa via voice, app, etc.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns Object containing the response to be sent to Alexa Service\n */\n async handle(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`handling Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n\n const property = this.allCapabilities\n .flatMap(item => item.properties)\n .find(property => property.matches(event));\n\n if (property) {\n let alexaValue: AlexaV3DirectiveValue;\n try {\n const setter = this.valueSetter(event);\n alexaValue = await setter(event, property);\n } catch (error) {\n this.log.debug(`${error}`);\n this.log.error(`failed handling Alexa event`);\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(AlexaResponse.endpointUnreachable(event.directive.header.messageId).get());\n }\n\n // even though the handler successfully processed the Alexa event,\n // we return an error here for ENFORCED capabilities, to prevent\n // reporting multiple successes for the same capability and\n // running into a situation of returning a wrong value back to Alexa\n if (this.enforced.find(capability => capability.matches(event))) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(\n AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n ).get(),\n );\n }\n\n const response = AlexaResponse.handled(\n event,\n property.propertyName,\n property.reportValue(alexaValue),\n property.instance,\n );\n\n // though the processed directive required to change a single value, the response must contain values of all \"relevant\" properties\n // Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event\n\n // TODO: add values of relevant properties to response\n\n this.log.silly(`${JSON.stringify(response.get())}`);\n return response.get();\n }\n\n const errorResponse = AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n );\n this.log.silly(`${JSON.stringify(errorResponse.get())}`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(errorResponse.get());\n }\n\n valueSetter(\n _event: AlexaV3Request,\n ): (event: AlexaV3Request, property: PropertiesBase) => Promise<AlexaV3DirectiveValue> {\n return this.setValue.bind(this);\n }\n\n async setValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract alexa value from event\n const alexaValue = property.alexaDirectiveValue(event);\n\n // convert alexa value to iobroker value\n let value: ioBroker.StateValue | undefined = property.value(alexaValue);\n\n // if set, the device could support toggle\n if (event.currentState) {\n // console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);\n const state = event.currentState.find(item => item.name === property.propertyName);\n if (state && value === true) {\n // it could support toggle.\n // get current value\n const current = property.value(state.value);\n if (current === true) {\n // turn off\n value = false;\n } else if (current !== false) {\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n if (currentValue === true) {\n // turn off\n value = false;\n }\n }\n }\n }\n\n // set iobroker state\n await this.setState(property, value!);\n\n property.currentValue = value;\n // return value as expected by Alexa\n return property.alexaValue(value);\n }\n\n async adjustValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract Alexa delta value from event\n const delta = property.alexaDirectiveValue(event);\n // get current value\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n // convert the current value to Alexa value\n const valueToAdjust = property.alexaValue(currentValue);\n // adjust Alexa value\n const adjustedValue = ensureValueInRange_0_100(\n parseFloat((valueToAdjust as string) || '0') + parseFloat((delta as string) || '0'),\n );\n // convert adjusted value to iobroker value\n const value = property.value(adjustedValue);\n\n // set iobroker state\n await this.setState(property, value as ioBroker.StateValue);\n\n return adjustedValue;\n }\n\n protected async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n if (property.currentValue === undefined) {\n const id = property.getId;\n if (!id) {\n throw new Error(`no ID defined for property \"${property.propertyName}\" of \"${this.name}\"`);\n }\n property.currentValue = await AdapterProvider.getState(id);\n }\n\n if (property.currentValue === undefined) {\n throw new Error(`unable to retrieve ${property.getId}`);\n }\n\n return property.currentValue;\n }\n\n async reportState(): Promise<AlexaV3ReportedState[]> {\n const propertiesToReport: AlexaV3ReportedState[] = [];\n\n for (const capability of this.supported) {\n for (const property of capability.properties) {\n try {\n await this.getOrRetrieveCurrentValue(property);\n\n const toReport: AlexaV3ReportedState = {\n namespace: capability.namespace,\n instance: property.instance,\n name: property.propertyName,\n value: property.reportValue(property.alexaValue(property.currentValue)),\n };\n\n if (!toReport.instance) {\n delete toReport.instance;\n }\n\n propertiesToReport.push(toReport);\n } catch (error) {\n this.log.error(`failed reporting state for property \"${property.propertyName}\" of \"${this.name}\"`);\n if (error.stack) {\n this.log.debug(`${error.stack}`);\n }\n this.log.debug(`${error}`);\n }\n }\n }\n\n this.log.debug(`reporting state: ${JSON.stringify(propertiesToReport)}`);\n return propertiesToReport;\n }\n\n toString(): string {\n return `${this.constructor.name}`;\n }\n\n private initStates(ctrl: IotExternalPatternControl): void {\n for (const stateKey of Control.stateKeys) {\n this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);\n }\n }\n\n get states(): Record<string, IotExternalDetectorState | undefined> {\n return this._states;\n }\n\n get statesMap(): Record<string, StateName> {\n const map: Record<string, StateName> = {};\n for (const stateKey of Control.stateKeys) {\n map[stateKey.toLowerCase()] = stateKey;\n }\n return map;\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\n\n //-------------------------------------------------------\n // standard property init objects\n //\n\n protected blankInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n };\n }\n\n protected powerStateInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (alexaValue) {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n protected detectedStateInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (_alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n // should be never called\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? DetectionState.DETECTED : DetectionState.NOT_DETECTED;\n },\n };\n }\n\n protected percentageInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n // const range = configuredRangeOrDefault(this.states[map.set]);\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(\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 };\n }\n}\n"]}
|
|
@@ -13,24 +13,18 @@ const PowerState_1 = __importDefault(require("../Alexa/Properties/PowerState"));
|
|
|
13
13
|
class Ct extends AdjustableControl_1.default {
|
|
14
14
|
_brightnessCapability;
|
|
15
15
|
_brightness;
|
|
16
|
-
_colorTemperatureCapability;
|
|
17
16
|
_powerControllerCapability;
|
|
18
17
|
_powerState;
|
|
19
18
|
constructor(detectedControl) {
|
|
20
19
|
super(detectedControl);
|
|
21
20
|
const map = this.statesMap;
|
|
22
|
-
this._supported = [new Capabilities_1.default.
|
|
21
|
+
this._supported = [new Capabilities_1.default.ColorTemperatureController(this.composeInitObjectColorTemperature())];
|
|
23
22
|
// if the state DIMMER or BRIGHTNESS configured
|
|
24
23
|
if (this.states[map.dimmer] || this.states[map.brightness]) {
|
|
25
24
|
this._brightnessCapability = new Capabilities_1.default.BrightnessController(this.composeInitObjectBrightness());
|
|
26
25
|
this._brightness = this._brightnessCapability.brightness;
|
|
27
26
|
this._supported.push(this._brightnessCapability);
|
|
28
27
|
}
|
|
29
|
-
// if the state TEMPERATURE configured
|
|
30
|
-
if (this.states[map.temperature]) {
|
|
31
|
-
this._colorTemperatureCapability = new Capabilities_1.default.ColorTemperatureController(this.composeInitObjectColorTemperature());
|
|
32
|
-
this._supported.push(this._colorTemperatureCapability);
|
|
33
|
-
}
|
|
34
28
|
// if the state ON, DIMMER or BRIGHTNESS configured
|
|
35
29
|
if (this.states[map.on] || this._brightness) {
|
|
36
30
|
this._powerControllerCapability = new Capabilities_1.default.PowerController(this.composeInitObjectPowerState());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ct.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Ct.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,4CAAiH;AACjH,iFAAyD;AACzD,4EAAoD;AAGpD,gFAAwD;AACxD,4GAAoF;AAGpF,gFAAwD;AASxD,MAAqB,EAAG,SAAQ,2BAAiB;IAC5B,qBAAqB,CAAmC;IACxD,WAAW,CAAyB;IACpC,2BAA2B,CAAyC;IACpE,0BAA0B,CAA8B;IACxD,WAAW,CAAyB;IAErD,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,eAAe,EAAE,CAAC,CAAC,CAAC;QAE7E,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC,qBAAqB,GAAG,IAAI,sBAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC,CAAC;YACvG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC;YACzD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACrD,CAAC;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,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,OAAO,UAAoB,CAAC;YAChC,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,OAAO,KAAe,CAAC;YAC3B,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AAtND,qBAsNC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport { configuredRangeOrDefault, denormalize_0_100, normalize_0_100, closestFromList } from '../Helpers/Utils';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as PropertiesBase } 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 type PowerController from '../Alexa/Capabilities/PowerController';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\n\nexport default class Ct extends AdjustableControl {\n private readonly _brightnessCapability: BrightnessController | undefined;\n private readonly _brightness: Brightness | undefined;\n private readonly _colorTemperatureCapability: ColorTemperatureController | undefined;\n private readonly _powerControllerCapability: PowerController | undefined;\n private readonly _powerState: PowerState | undefined;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n const map = this.statesMap;\n this._supported = [new Capabilities.ColorController(this.blankInitObject())];\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 TEMPERATURE configured\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 ON, DIMMER or BRIGHTNESS configured\n if (this.states[map.on] || this._brightness) {\n this._powerControllerCapability = new Capabilities.PowerController(this.composeInitObjectPowerState());\n this._powerState = this._powerControllerCapability.powerState;\n this._supported.push(this._powerControllerCapability);\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 !== 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 async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n const map = this.statesMap;\n\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[map.on]) {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n } else {\n if (!this._brightness) {\n throw new Error('No brightness property configured');\n }\n if (!this._powerState) {\n throw new Error('No powerState property configured');\n }\n\n if (value) {\n // set brightness\n // set byOn to the configured value or range.max otherwise\n const range = configuredRangeOrDefault(this.states[map.dimmer] || this.states[map.brightness]!);\n const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;\n let byOn: number | string | undefined | null;\n if (smartName && typeof smartName === 'object') {\n byOn = smartName.byON;\n } else {\n byOn = undefined;\n }\n if (byOn === undefined || byOn === null || isNaN(byOn as unknown as number)) {\n byOn = range.max as number | string | undefined | null;\n } else {\n byOn = parseFloat(byOn);\n }\n await AdapterProvider.setState(this._brightness.setId, byOn ?? 100);\n this._brightness.currentValue = byOn;\n this._powerState.currentValue = true;\n } else {\n // set brightness to 0 on power OFF\n await AdapterProvider.setState(this._brightness.setId, 0);\n this._brightness.currentValue = 0;\n this._powerState.currentValue = false;\n }\n }\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 composeInitObjectPowerState(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\n const map = this.statesMap;\n return {\n setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n getState: this.states[map.on] || this.states[map.dimmer] || 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 };\n }\n\n protected composeInitObjectBrightness(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\n const map = this.statesMap;\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 };\n }\n\n protected composeInitObjectColorTemperature(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\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":"Ct.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Ct.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,4CAAiH;AACjH,iFAAyD;AACzD,4EAAoD;AAGpD,gFAAwD;AACxD,4GAAoF;AAEpF,gFAAwD;AASxD,MAAqB,EAAG,SAAQ,2BAAiB;IAC5B,qBAAqB,CAAmC;IACxD,WAAW,CAAyB;IACpC,0BAA0B,CAA8B;IACxD,WAAW,CAAyB;IAErD,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,0BAA0B,CAAC,IAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAE1G,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC,qBAAqB,GAAG,IAAI,sBAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC,CAAC;YACvG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC;YACzD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACrD,CAAC;QAED,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,0BAA0B,GAAG,IAAI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;gBAC7C,CAAC;gBAED,OAAO,UAAoB,CAAC;YAChC,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,OAAO,KAAe,CAAC;YAC3B,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AA7MD,qBA6MC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport { configuredRangeOrDefault, denormalize_0_100, normalize_0_100, closestFromList } from '../Helpers/Utils';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as PropertiesBase } 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 PowerController from '../Alexa/Capabilities/PowerController';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\n\nexport default class Ct extends AdjustableControl {\n private readonly _brightnessCapability: BrightnessController | undefined;\n private readonly _brightness: Brightness | undefined;\n private readonly _powerControllerCapability: PowerController | undefined;\n private readonly _powerState: PowerState | undefined;\n\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n const map = this.statesMap;\n this._supported = [new Capabilities.ColorTemperatureController(this.composeInitObjectColorTemperature())];\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 this._powerControllerCapability = new Capabilities.PowerController(this.composeInitObjectPowerState());\n this._powerState = this._powerControllerCapability.powerState;\n this._supported.push(this._powerControllerCapability);\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 !== 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 async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n const map = this.statesMap;\n\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[map.on]) {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n } else {\n if (!this._brightness) {\n throw new Error('No brightness property configured');\n }\n if (!this._powerState) {\n throw new Error('No powerState property configured');\n }\n\n if (value) {\n // set brightness\n // set byOn to the configured value or range.max otherwise\n const range = configuredRangeOrDefault(this.states[map.dimmer] || this.states[map.brightness]!);\n const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;\n let byOn: number | string | undefined | null;\n if (smartName && typeof smartName === 'object') {\n byOn = smartName.byON;\n } else {\n byOn = undefined;\n }\n if (byOn === undefined || byOn === null || isNaN(byOn as unknown as number)) {\n byOn = range.max as number | string | undefined | null;\n } else {\n byOn = parseFloat(byOn);\n }\n await AdapterProvider.setState(this._brightness.setId, byOn ?? 100);\n this._brightness.currentValue = byOn;\n this._powerState.currentValue = true;\n } else {\n // set brightness to 0 on power OFF\n await AdapterProvider.setState(this._brightness.setId, 0);\n this._brightness.currentValue = 0;\n this._powerState.currentValue = false;\n }\n }\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 composeInitObjectPowerState(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\n const map = this.statesMap;\n return {\n setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n getState: this.states[map.on] || this.states[map.dimmer] || 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 };\n }\n\n protected composeInitObjectBrightness(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\n const map = this.statesMap;\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 };\n }\n\n protected composeInitObjectColorTemperature(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\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"]}
|
|
@@ -55,7 +55,7 @@ class Hue extends AdjustableControl_1.default {
|
|
|
55
55
|
property.currentValue = property.currentValue !== 0;
|
|
56
56
|
}
|
|
57
57
|
if (property.propertyName === Properties_1.default.Color.propertyName) {
|
|
58
|
-
// @ts-expect-error special case for
|
|
58
|
+
// @ts-expect-error special case for Hue property
|
|
59
59
|
property.currentValue = {
|
|
60
60
|
hue: property.currentValue,
|
|
61
61
|
saturation: property.hal.saturation,
|
|
@@ -115,11 +115,14 @@ class Hue extends AdjustableControl_1.default {
|
|
|
115
115
|
}
|
|
116
116
|
else if (property.propertyName === Color_1.default.propertyName) {
|
|
117
117
|
const colorProperty = property;
|
|
118
|
-
const hueValue = value;
|
|
118
|
+
const hueValue = (0, Utils_1.rgb2hal)(value);
|
|
119
119
|
await AdapterProvider_1.default.setState(colorProperty.hal.hue, hueValue.hue);
|
|
120
120
|
if (colorProperty.hal.saturation) {
|
|
121
121
|
await AdapterProvider_1.default.setState(colorProperty.hal.saturation, hueValue.saturation);
|
|
122
122
|
}
|
|
123
|
+
if (colorProperty.hal.brightness) {
|
|
124
|
+
await AdapterProvider_1.default.setState(colorProperty.hal.brightness, hueValue.brightness);
|
|
125
|
+
}
|
|
123
126
|
// do not set brightness
|
|
124
127
|
// https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-colorcontroller.html
|
|
125
128
|
// Important: For the best user experience, when you make a color change, maintain the current brightness setting of the endpoint.
|
|
@@ -172,9 +175,9 @@ class Hue extends AdjustableControl_1.default {
|
|
|
172
175
|
const map = this.statesMap;
|
|
173
176
|
return {
|
|
174
177
|
hal: {
|
|
175
|
-
hue: this.states[map.hue]
|
|
176
|
-
saturation: this.states[map.saturation]
|
|
177
|
-
brightness:
|
|
178
|
+
hue: this.states[map.hue],
|
|
179
|
+
saturation: this.states[map.saturation],
|
|
180
|
+
brightness: this.states[map.dimmer] || this.states[map.brightness],
|
|
178
181
|
},
|
|
179
182
|
};
|
|
180
183
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hue.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Hue.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AAIjD,4CAAiH;AACjH,qEAA6C;AAC7C,gFAAwD;AACxD,gFAAwD;AACxD,iFAAyD;AACzD,4EAAoD;AAGpD,sEAA8C;AAC9C,4GAAoF;AAEpF,MAAqB,GAAI,SAAQ,2BAAiB;IAC7B,0BAA0B,CAA8B;IACxD,WAAW,CAAyB;IACpC,qBAAqB,CAAmC;IACxD,WAAW,CAAyB;IACpC,2BAA2B,CAAyC;IAErF,YAAY,eAA0C;QAClD,KAAK,CAAC,eAAe,CAAC,CAAC;QAEvB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3B,IAAI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iPC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport type PowerController from '../Alexa/Capabilities/PowerController';\nimport type BrightnessController from '../Alexa/Capabilities/BrightnessController';\nimport type ColorTemperatureController from '../Alexa/Capabilities/ColorTemperatureController';\nimport { configuredRangeOrDefault, denormalize_0_100, normalize_0_100, closestFromList } from '../Helpers/Utils';\nimport Properties from '../Alexa/Properties';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport Brightness from '../Alexa/Properties/Brightness';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport type { AlexaV3Category, AlexaV3DirectiveValue, AlexaV3Request, IotExternalPatternControl } from '../types';\nimport Color from '../Alexa/Properties/Color';\nimport ColorTemperatureInKelvin from '../Alexa/Properties/ColorTemperatureInKelvin';\n\nexport default class Hue extends AdjustableControl {\n private readonly _powerControllerCapability: PowerController | undefined;\n private readonly _powerState: PowerState | undefined;\n private readonly _brightnessCapability: BrightnessController | undefined;\n private readonly _brightness: Brightness | undefined;\n private readonly _colorTemperatureCapability: ColorTemperatureController | undefined;\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 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 TEMPERATURE configured\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 ON, DIMMER or BRIGHTNESS configured\n if (this.states[map.on] || this._brightness) {\n this._powerControllerCapability = new Capabilities.PowerController(this.composeInitObjectPowerState());\n this._powerState = this._powerControllerCapability.powerState;\n this._supported.push(this._powerControllerCapability);\n }\n }\n\n get categories(): AlexaV3Category[] {\n return ['LIGHT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [Properties.ColorTemperatureInKelvin];\n }\n\n async getOrRetrieveCurrentValue(property: Color): 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 === Properties.PowerState.propertyName && !this.states[map.on]) {\n property.currentValue = property.currentValue !== 0;\n }\n\n if (property.propertyName === Properties.Color.propertyName) {\n // @ts-expect-error special case for Color property\n property.currentValue = {\n hue: property.currentValue,\n saturation: property.hal.saturation,\n brightness: property.hal.brightness,\n };\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 | undefined): Promise<void> {\n const map = this.statesMap;\n\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[map.on]) {\n await AdapterProvider.setState(property.setId, value ?? false);\n property.currentValue = value;\n } else {\n if (value) {\n // set brightness\n // set byOn to the configured value or range.max otherwise\n const range = configuredRangeOrDefault(this.states[map.dimmer] || this.states[map.brightness]!);\n const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;\n let byOn: string | number | undefined | null;\n if (smartName && typeof smartName === 'object') {\n byOn = smartName.byON;\n }\n byOn =\n byOn === null || byOn === undefined || isNaN(byOn as number)\n ? (range.max as number)\n : parseFloat(byOn as string);\n if (this._brightness) {\n await AdapterProvider.setState(this._brightness.setId, byOn);\n this._brightness.currentValue = byOn;\n }\n if (this._powerState) {\n this._powerState.currentValue = true;\n }\n } else {\n if (this._brightness) {\n // set brightness to 0 on power OFF\n await AdapterProvider.setState(this._brightness.setId, 0);\n this._brightness.currentValue = 0;\n }\n if (this._powerState) {\n this._powerState.currentValue = false;\n }\n }\n }\n } else if (property.propertyName === Brightness.propertyName) {\n await AdapterProvider.setState(property.setId, value ?? 0);\n property.currentValue = value;\n } else if (property.propertyName === Color.propertyName) {\n const colorProperty = property as Color;\n const hueValue = value as unknown as { hue: number; saturation: number };\n await AdapterProvider.setState(colorProperty.hal.hue, hueValue.hue);\n if (colorProperty.hal.saturation) {\n await AdapterProvider.setState(colorProperty.hal.saturation, hueValue.saturation);\n }\n\n // do not set brightness\n\n // https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-colorcontroller.html\n // Important: For the best user experience, when you make a color change, maintain the current brightness setting of the endpoint.\n // For example, if a light bulb is currently set to white at 0.5 brightness, and a user requests a color change to red,\n // the SetColor directive specifies hue = 0, saturation = 1, and brightness = 1. Here, set the hue to 0, the saturation to 1,\n // and ignore the brightness value of 1 in the directive. Instead, maintain the current brightness value of 0.5.\n\n property.currentValue = value;\n } else if (property.propertyName === ColorTemperatureInKelvin.propertyName) {\n await AdapterProvider.setState(property.setId, value ?? 2200);\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);\n\n return value as AlexaV3DirectiveValue;\n }\n\n private 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: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n private composeInitObjectBrightness(): ControlStateInitObject {\n const map = this.statesMap;\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 };\n }\n\n private composeInitObjectColor(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n hal: {\n hue: this.states[map.hue]!.id,\n saturation: this.states[map.saturation]?.id,\n brightness: (this.states[map.dimmer] || this.states[map.brightness])?.id,\n },\n };\n }\n\n private composeInitObjectColorTemperature(): ControlStateInitObject {\n const map = this.statesMap;\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 return alexaValue as number;\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return value as number;\n },\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Hue.js","sourceRoot":"","sources":["../../../../src/lib/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AC,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,OAAO,UAAoB,CAAC;YAChC,CAAC;YACD,WAAW,EAAE,UAET,KAAsC;gBAEtC,OAAO,KAAe,CAAC;YAC3B,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AApPD,sBAoPC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport type PowerController from '../Alexa/Capabilities/PowerController';\nimport type BrightnessController from '../Alexa/Capabilities/BrightnessController';\nimport type ColorTemperatureController from '../Alexa/Capabilities/ColorTemperatureController';\nimport {\n configuredRangeOrDefault,\n denormalize_0_100,\n normalize_0_100,\n closestFromList,\n rgb2hal,\n} from '../Helpers/Utils';\nimport Properties from '../Alexa/Properties';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport Brightness from '../Alexa/Properties/Brightness';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as PropertiesBase, ControlStateInitObject } from '../Alexa/Properties/Base';\nimport type { AlexaV3Category, AlexaV3DirectiveValue, AlexaV3Request, IotExternalPatternControl } from '../types';\nimport Color from '../Alexa/Properties/Color';\nimport ColorTemperatureInKelvin from '../Alexa/Properties/ColorTemperatureInKelvin';\n\nexport default class Hue extends AdjustableControl {\n private readonly _powerControllerCapability: PowerController | undefined;\n private readonly _powerState: PowerState | undefined;\n private readonly _brightnessCapability: BrightnessController | undefined;\n private readonly _brightness: Brightness | undefined;\n private readonly _colorTemperatureCapability: ColorTemperatureController | undefined;\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 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 TEMPERATURE configured\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 ON, DIMMER or BRIGHTNESS configured\n if (this.states[map.on] || this._brightness) {\n this._powerControllerCapability = new Capabilities.PowerController(this.composeInitObjectPowerState());\n this._powerState = this._powerControllerCapability.powerState;\n this._supported.push(this._powerControllerCapability);\n }\n }\n\n get categories(): AlexaV3Category[] {\n return ['LIGHT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [Properties.ColorTemperatureInKelvin];\n }\n\n async getOrRetrieveCurrentValue(property: Color): 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 === Properties.PowerState.propertyName && !this.states[map.on]) {\n property.currentValue = property.currentValue !== 0;\n }\n\n if (property.propertyName === Properties.Color.propertyName) {\n // @ts-expect-error special case for Hue property\n property.currentValue = {\n hue: property.currentValue,\n saturation: property.hal!.saturation,\n brightness: property.hal!.brightness,\n };\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 | undefined): Promise<void> {\n const map = this.statesMap;\n\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[map.on]) {\n await AdapterProvider.setState(property.setId, value ?? false);\n property.currentValue = value;\n } else {\n if (value) {\n // set brightness\n // set byOn to the configured value or range.max otherwise\n const range = configuredRangeOrDefault(this.states[map.dimmer] || this.states[map.brightness]!);\n const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;\n let byOn: string | number | undefined | null;\n if (smartName && typeof smartName === 'object') {\n byOn = smartName.byON;\n }\n byOn =\n byOn === null || byOn === undefined || isNaN(byOn as number)\n ? (range.max as number)\n : parseFloat(byOn as string);\n if (this._brightness) {\n await AdapterProvider.setState(this._brightness.setId, byOn);\n this._brightness.currentValue = byOn;\n }\n if (this._powerState) {\n this._powerState.currentValue = true;\n }\n } else {\n if (this._brightness) {\n // set brightness to 0 on power OFF\n await AdapterProvider.setState(this._brightness.setId, 0);\n this._brightness.currentValue = 0;\n }\n if (this._powerState) {\n this._powerState.currentValue = false;\n }\n }\n }\n } else if (property.propertyName === Brightness.propertyName) {\n await AdapterProvider.setState(property.setId, value ?? 0);\n property.currentValue = value;\n } else if (property.propertyName === Color.propertyName) {\n const colorProperty = property as Color;\n const hueValue = rgb2hal(value as string);\n await AdapterProvider.setState(colorProperty.hal!.hue, hueValue.hue);\n if (colorProperty.hal!.saturation) {\n await AdapterProvider.setState(colorProperty.hal!.saturation, hueValue.saturation);\n }\n if (colorProperty.hal!.brightness) {\n await AdapterProvider.setState(colorProperty.hal!.brightness, hueValue.brightness);\n }\n\n // do not set brightness\n\n // https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-colorcontroller.html\n // Important: For the best user experience, when you make a color change, maintain the current brightness setting of the endpoint.\n // For example, if a light bulb is currently set to white at 0.5 brightness, and a user requests a color change to red,\n // the SetColor directive specifies hue = 0, saturation = 1, and brightness = 1. Here, set the hue to 0, the saturation to 1,\n // and ignore the brightness value of 1 in the directive. Instead, maintain the current brightness value of 0.5.\n\n property.currentValue = value;\n } else if (property.propertyName === ColorTemperatureInKelvin.propertyName) {\n await AdapterProvider.setState(property.setId, value ?? 2200);\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);\n\n return value as AlexaV3DirectiveValue;\n }\n\n private 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: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n private composeInitObjectBrightness(): ControlStateInitObject {\n const map = this.statesMap;\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 };\n }\n\n private composeInitObjectColor(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n hal: {\n hue: this.states[map.hue]!,\n saturation: this.states[map.saturation],\n brightness: this.states[map.dimmer] || this.states[map.brightness],\n },\n };\n }\n\n private composeInitObjectColorTemperature(): ControlStateInitObject {\n const map = this.statesMap;\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 return alexaValue as number;\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return value as number;\n },\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Light.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Light.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"Light.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Light.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,wDAAoD;AAQpD,MAAqB,KAAM,SAAQ,iBAAO;IACtC,YAAY,eAA0C;QAClD,KAAK,CAAC,eAAe,CAAC,CAAC;QAEvB,oGAAoG;QACpG,6BAA6B;QAC7B,MAAM,oBAAoB,GAAG,IAAI,sBAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;QAChG,IAAI,CAAC,SAAS,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAExC,oBAAoB;QACpB,MAAM,eAAe,GAAG,IAAI,sBAAY,CAAC,eAAe,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;QACtF,IAAI,CAAC,UAAU,GAAG,CAAC,eAAe,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,UAAU;QACV,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,SAAS;QAIT,OAAO;YACH,GAAG,EAAE,KAAK;YACV,MAAM,EAAE,WAAW;SACtB,CAAC;IACN,CAAC;IAEO,oBAAoB;QAMxB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAE3B,OAAO;YACH,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE;YAC/B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAE;YAClC,WAAW,EAAE,UAAU,UAAiC;gBACpD,OAAQ,UAAqB,GAAG,CAAC,CAAC;YACtC,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AA/CD,wBA+CC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport Control, { type StateName } from './Control';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\n\nexport default class Light extends Control {\n constructor(detectedControl: IotExternalPatternControl) {\n super(detectedControl);\n\n // We support dimmer as enforced capability to allow setting group commands to dim to 0% and to 100%\n // Init enforced capabilities\n const brightnessController = new Capabilities.BrightnessController(this.brightnessInitObject());\n this._enforced = [brightnessController];\n\n // Init capabilities\n const powerController = new Capabilities.PowerController(this.powerStateInitObject());\n this._supported = [powerController];\n }\n\n get categories(): AlexaV3Category[] {\n return ['LIGHT'];\n }\n\n get statesMap(): {\n set: StateName;\n actual: StateName;\n } {\n return {\n set: 'SET',\n actual: 'ON_ACTUAL',\n };\n }\n\n private brightnessInitObject(): {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n } {\n const map = this.statesMap;\n\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n return (alexaValue as number) > 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? 100 : 0;\n },\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Capabilities_1 = __importDefault(require("../Alexa/Capabilities"));
|
|
7
|
+
const Utils_1 = require("../Helpers/Utils");
|
|
8
|
+
const AdapterProvider_1 = __importDefault(require("../Helpers/AdapterProvider"));
|
|
9
|
+
const AdjustableControl_1 = __importDefault(require("./AdjustableControl"));
|
|
10
|
+
const Brightness_1 = __importDefault(require("../Alexa/Properties/Brightness"));
|
|
11
|
+
const ColorTemperatureInKelvin_1 = __importDefault(require("../Alexa/Properties/ColorTemperatureInKelvin"));
|
|
12
|
+
const PowerState_1 = __importDefault(require("../Alexa/Properties/PowerState"));
|
|
13
|
+
const Color_1 = __importDefault(require("../Alexa/Properties/Color"));
|
|
14
|
+
// ### RGB Light Single [rgbSingle]
|
|
15
|
+
//
|
|
16
|
+
// RGB light with one state of color. Could be HEX #RRGGBB, or rgb(0-255,0-255,0-255).
|
|
17
|
+
//
|
|
18
|
+
// | R | Name | Role | Unit | Type | Wr | Ind | Multi | Regex |
|
|
19
|
+
// |---|-----------------|-------------------------------|------|---------|----|-----|-------|---------------------------------------------------|
|
|
20
|
+
// | * | RGB | level.color.rgb | | string | W | | | `/^level\.color\.rgb$/` |
|
|
21
|
+
// | | DIMMER | level.dimmer | % | number | W | | | `/^level\.dimmer$/` |
|
|
22
|
+
// | | BRIGHTNESS | | % | number | W | | | `/^level\.brightness$/` |
|
|
23
|
+
// | | TEMPERATURE | level.color.temperature | °K | number | W | | | `/^level\.color\.temperature$/` |
|
|
24
|
+
// | | ON | switch.light | | boolean | W | | | `/^switch(\.light)?$/` |
|
|
25
|
+
// | | ON_ACTUAL | sensor.light | | boolean | - | | | `/^(state|switch|sensor)\.light|switch$/` |
|
|
26
|
+
class RgbSingle extends AdjustableControl_1.default {
|
|
27
|
+
_brightnessCapability;
|
|
28
|
+
_brightness;
|
|
29
|
+
_colorTemperatureCapability;
|
|
30
|
+
_powerControllerCapability;
|
|
31
|
+
_powerState;
|
|
32
|
+
constructor(detectedControl) {
|
|
33
|
+
super(detectedControl);
|
|
34
|
+
const map = this.statesMap;
|
|
35
|
+
this._supported = [new Capabilities_1.default.ColorController(this.composeInitObjectColor())];
|
|
36
|
+
if (this.states[map.temperature]) {
|
|
37
|
+
this._colorTemperatureCapability = new Capabilities_1.default.ColorTemperatureController(this.composeInitObjectColorTemperature());
|
|
38
|
+
this._supported.push(this._colorTemperatureCapability);
|
|
39
|
+
}
|
|
40
|
+
// if the state DIMMER or BRIGHTNESS configured
|
|
41
|
+
if (this.states[map.dimmer] || this.states[map.brightness]) {
|
|
42
|
+
this._brightnessCapability = new Capabilities_1.default.BrightnessController(this.composeInitObjectBrightness());
|
|
43
|
+
this._brightness = this._brightnessCapability.brightness;
|
|
44
|
+
this._supported.push(this._brightnessCapability);
|
|
45
|
+
}
|
|
46
|
+
// if the state ON, DIMMER or BRIGHTNESS configured
|
|
47
|
+
if (this.states[map.on] || this._brightness) {
|
|
48
|
+
this._powerControllerCapability = new Capabilities_1.default.PowerController(this.composeInitObjectPowerState());
|
|
49
|
+
this._powerState = this._powerControllerCapability.powerState;
|
|
50
|
+
this._supported.push(this._powerControllerCapability);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
get categories() {
|
|
54
|
+
return ['LIGHT'];
|
|
55
|
+
}
|
|
56
|
+
adjustableProperties() {
|
|
57
|
+
return [ColorTemperatureInKelvin_1.default];
|
|
58
|
+
}
|
|
59
|
+
async getOrRetrieveCurrentValue(property) {
|
|
60
|
+
const map = this.statesMap;
|
|
61
|
+
if (property.currentValue === undefined) {
|
|
62
|
+
property.currentValue = await AdapterProvider_1.default.getState(property.getId);
|
|
63
|
+
// convert the non-zero brightness to power = true
|
|
64
|
+
if (property.propertyName === PowerState_1.default.propertyName && !this.states[map.on]) {
|
|
65
|
+
property.currentValue = property.currentValue !== 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (property.currentValue === undefined) {
|
|
69
|
+
throw new Error(`unable to retrieve ${property.getId}`);
|
|
70
|
+
}
|
|
71
|
+
return property.currentValue;
|
|
72
|
+
}
|
|
73
|
+
async setState(property, value) {
|
|
74
|
+
const map = this.statesMap;
|
|
75
|
+
if (property.propertyName === PowerState_1.default.propertyName) {
|
|
76
|
+
if (this.states[map.on]) {
|
|
77
|
+
await AdapterProvider_1.default.setState(property.setId, value);
|
|
78
|
+
property.currentValue = value;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (!this._brightness) {
|
|
82
|
+
throw new Error('No brightness property configured');
|
|
83
|
+
}
|
|
84
|
+
if (!this._powerState) {
|
|
85
|
+
throw new Error('No powerState property configured');
|
|
86
|
+
}
|
|
87
|
+
if (value) {
|
|
88
|
+
// set brightness
|
|
89
|
+
// set byOn to the configured value or range.max otherwise
|
|
90
|
+
const range = (0, Utils_1.configuredRangeOrDefault)(this.states[map.dimmer] || this.states[map.brightness]);
|
|
91
|
+
const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;
|
|
92
|
+
let byOn;
|
|
93
|
+
if (smartName && typeof smartName === 'object') {
|
|
94
|
+
byOn = smartName.byON;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
byOn = undefined;
|
|
98
|
+
}
|
|
99
|
+
if (byOn === undefined || byOn === null || isNaN(byOn)) {
|
|
100
|
+
byOn = range.max;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
byOn = parseFloat(byOn);
|
|
104
|
+
}
|
|
105
|
+
await AdapterProvider_1.default.setState(this._brightness.setId, byOn ?? 100);
|
|
106
|
+
this._brightness.currentValue = byOn;
|
|
107
|
+
this._powerState.currentValue = true;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// set brightness to 0 on power OFF
|
|
111
|
+
await AdapterProvider_1.default.setState(this._brightness.setId, 0);
|
|
112
|
+
this._brightness.currentValue = 0;
|
|
113
|
+
this._powerState.currentValue = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (property.propertyName === Color_1.default.propertyName) {
|
|
118
|
+
// For Color property, convert HAL format to RGB hex string
|
|
119
|
+
await AdapterProvider_1.default.setState(this.states[map.rgb].id, value);
|
|
120
|
+
property.currentValue = value;
|
|
121
|
+
}
|
|
122
|
+
else if (property.propertyName === Brightness_1.default.propertyName ||
|
|
123
|
+
property.propertyName === ColorTemperatureInKelvin_1.default.propertyName) {
|
|
124
|
+
await AdapterProvider_1.default.setState(property.setId, value);
|
|
125
|
+
property.currentValue = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async adjustValue(event, property) {
|
|
129
|
+
// extract Alexa delta value from event
|
|
130
|
+
const delta = property.alexaDirectiveValue(event);
|
|
131
|
+
// convert delta to iobroker value
|
|
132
|
+
const value = property.value(delta);
|
|
133
|
+
// set iobroker state
|
|
134
|
+
await this.setState(property, value ?? 0);
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
composeInitObjectColor() {
|
|
138
|
+
const map = this.statesMap;
|
|
139
|
+
return {
|
|
140
|
+
setState: this.states[map.rgb],
|
|
141
|
+
getState: this.states[map.rgb],
|
|
142
|
+
rgb: this.states[map.rgb],
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
composeInitObjectPowerState() {
|
|
146
|
+
const map = this.statesMap;
|
|
147
|
+
return {
|
|
148
|
+
setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness],
|
|
149
|
+
getState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness],
|
|
150
|
+
alexaSetter: function (alexaValue) {
|
|
151
|
+
return alexaValue === PowerState_1.default.ON;
|
|
152
|
+
},
|
|
153
|
+
alexaGetter: function (value) {
|
|
154
|
+
return value ? PowerState_1.default.ON : PowerState_1.default.OFF;
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
composeInitObjectBrightness() {
|
|
159
|
+
const map = this.statesMap;
|
|
160
|
+
return {
|
|
161
|
+
setState: this.states[map.dimmer] || this.states[map.brightness],
|
|
162
|
+
getState: this.states[map.dimmer] || this.states[map.brightness],
|
|
163
|
+
alexaSetter: function (alexaValue) {
|
|
164
|
+
return ((0, Utils_1.denormalize_0_100)(alexaValue, this.valuesRangeMin, this.valuesRangeMax) ?? 0);
|
|
165
|
+
},
|
|
166
|
+
alexaGetter: function (value) {
|
|
167
|
+
return (0, Utils_1.normalize_0_100)(value, this.valuesRangeMin, this.valuesRangeMax);
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
composeInitObjectColorTemperature() {
|
|
172
|
+
const map = this.statesMap;
|
|
173
|
+
return {
|
|
174
|
+
setState: this.states[map.temperature],
|
|
175
|
+
getState: this.states[map.temperature],
|
|
176
|
+
alexaSetter: function (alexaValue) {
|
|
177
|
+
if (alexaValue === 1) {
|
|
178
|
+
// increase directive
|
|
179
|
+
const closest = (0, Utils_1.closestFromList)(this.currentValue || this.colorTemperatureTable[0], this.colorTemperatureTable);
|
|
180
|
+
let index = this.colorTemperatureTable.indexOf(closest) + 1;
|
|
181
|
+
index = index >= this.colorTemperatureTable.length ? this.colorTemperatureTable.length - 1 : index;
|
|
182
|
+
return this.colorTemperatureTable[index];
|
|
183
|
+
}
|
|
184
|
+
if (alexaValue === -1) {
|
|
185
|
+
// decrease directive
|
|
186
|
+
const closest = (0, Utils_1.closestFromList)(this.currentValue || this.colorTemperatureTable[0], this.colorTemperatureTable);
|
|
187
|
+
let index = this.colorTemperatureTable.indexOf(closest) - 1;
|
|
188
|
+
index = index < 0 ? 0 : index;
|
|
189
|
+
return this.colorTemperatureTable[index];
|
|
190
|
+
}
|
|
191
|
+
return alexaValue;
|
|
192
|
+
},
|
|
193
|
+
alexaGetter: function (value) {
|
|
194
|
+
return value;
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.default = RgbSingle;
|
|
200
|
+
//# sourceMappingURL=RgbSingle.js.map
|