From 5c33a4abe273ad1498deafae4e44c3fc4ccd55db Mon Sep 17 00:00:00 2001 From: jsetton Date: Thu, 2 Dec 2021 21:32:48 -0500 Subject: [PATCH] Update alexa blind and channel attributes Signed-off-by: jsetton --- .../metadata/alexa/deviceattributes.js | 44 ++++++++++++++++--- .../definitions/metadata/alexa/devicetypes.js | 5 ++- .../definitions/metadata/alexa/parameters.js | 38 +++++++++++----- .../item/metadata/item-metadata-alexa.vue | 2 +- 4 files changed, 69 insertions(+), 20 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/deviceattributes.js b/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/deviceattributes.js index 62764d3db9..81a0fcb9ee 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/deviceattributes.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/deviceattributes.js @@ -45,23 +45,52 @@ export default { itemTypes: ['Dimmer', 'Rollershutter'], parameters: (item) => [ p.inverted(item.type === 'Rollershutter'), - p.presets(item.stateDescription, '20=Morning,60=Afternoon,80=Evening:@Setting.Night', true), - p.language(item.settings && item.settings.regional.language) + p.presets(item.stateDescription, '20=Morning,60=Afternoon,80=Evening:@Setting.Night'), + p.language(item.settings && item.settings.regional.language), + p.actionMappings( + { default: 'value' }, + 'Close=0,Open=100,Lower=0,Raise=100', + (config) => { + if (item.type === 'Dimmer') { + return config.inverted === true + ? ['Close=100', 'Open=0', 'Lower=100', 'Raise=0'] + : ['Close=0', 'Open=100', 'Lower=0', 'Raise=100'] + } + if (item.type === 'Rollershutter') { + return ['Close=DOWN', 'Open=UP', 'Lower=DOWN', 'Raise=UP', 'Stop=STOP'] + } + } + ) ] }, TiltAngle: { itemTypes: ['Dimmer', 'Number', 'Number:Angle', 'Rollershutter'], parameters: (item) => [ p.inverted(item.type === 'Rollershutter'), - p.presets(item.stateDescription, '20=Morning,60=Afternoon,80=Evening:@Setting.Night', true), - p.language(item.settings && item.settings.regional.language) + p.presets(item.stateDescription, '20=Morning,60=Afternoon,80=Evening:@Setting.Night'), + p.language(item.settings && item.settings.regional.language), + p.actionMappings( + { default: 'value' }, + 'Close=0,Open=100', + (config) => { + if (item.type === 'Dimmer') { + return config.inverted === true ? ['Close=100', 'Open=0'] : ['Close=0', 'Open=100'] + } + if (item.type === 'Number' || item.type === 'Number:Angle') { + return config.inverted === true ? ['Close=90', 'Open=0'] : ['Close=-90', 'Open=0'] + } + if (item.type === 'Rollershutter') { + return ['Close=DOWN', 'Open=UP', 'Stop=STOP'] + } + } + ) ] }, // Entertainment Attributes Channel: { itemTypes: ['Number', 'String'], - parameters: () => [p.channelMappings(), p.retrievable()] + parameters: (item) => [p.channelMappings(item.stateDescription), p.channelRange(), p.retrievable()] }, Input: { itemTypes: ['Number', 'String'], @@ -396,9 +425,12 @@ export default { ] }, ToggleState: { - itemTypes: ['Switch'], + itemTypes: ['Number', 'String', 'Switch'], supports: ['multiInstance'], parameters: (item) => [ + ...(item.type === 'Number' || item.type === 'String' + ? [p.valueMapping('OFF', true), p.valueMapping('ON', true)] + : []), p.capabilityNames(item.groups.length ? item.label : '@Setting.ToggleState', '@Setting.Oscillate,Rotate'), p.nonControllable(item.stateDescription), p.retrievable(), diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/devicetypes.js b/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/devicetypes.js index bfb1bf39e9..13e08f63de 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/devicetypes.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/devicetypes.js @@ -79,8 +79,8 @@ export default { supportsGroup: false }, AirConditioner: { - defaultAttributes: ['HeatingCoolingMode'], - supportedAttributes: ['HeatingCoolingMode', 'TargetTemperature', 'CurrentTemperature', ...fanAttributes] + defaultAttributes: ['PowerState'], + supportedAttributes: ['PowerState', 'TargetTemperature', 'CurrentTemperature', ...fanAttributes] }, AirFreshener: { defaultAttributes: ['FanSpeed'], @@ -96,6 +96,7 @@ export default { 'FanSpeed', 'LockState', 'PowerState', + 'TargetTemperature', 'CurrentTemperature', ...genericAttributes ] diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/parameters.js b/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/parameters.js index 381c0ff7bf..0a4f8582a9 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/parameters.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/metadata/alexa/parameters.js @@ -18,13 +18,15 @@ import { } from './helpers.js' export default { - actionMappings: (format, placeholder) => ({ + actionMappings: (format, placeholder, defaultValue) => ({ name: 'actionMappings', label: 'Action Mappings', description: `Each mapping formatted as ${getSemanticFormat('action', format)} (${docLink('Semantic Extensions')})`, type: 'TEXT', + default: defaultValue, placeholder: placeholder.replace(/,/g, '\n'), - multiple: true + multiple: true, + advanced: !!defaultValue }), capabilityNames: (defaultValue, placeholder) => ({ name: 'capabilityNames', @@ -36,14 +38,29 @@ export default { multiple: true, required: !defaultValue }), - channelMappings: () => ({ + channelMappings: (stateDescription) => ({ name: 'channelMappings', label: 'Channel Mappings', - description: 'Each mapping formatted as channelName=channelNumber', + description: 'Each mapping formatted as channelNumber=channelName', type: 'TEXT', - placeholder: 'CBS=2\nNBC=4\nABC=7\nPBS=13', + default: + stateDescription && + stateDescription.options && + stateDescription.options + .filter((option) => !isNaN(option.value)) + .map((option) => `${option.value}=${option.label}`), + placeholder: '2=CBS\n4=NBC\n7=ABC\n13=PBS', multiple: true }), + channelRange: () => ({ + name: 'range', + label: 'Channel Range', + description: 'Formatted as minValue:maxValue', + type: 'TEXT', + default: '1:9999', + pattern: '[0-9]+:[0-9]+', + advanced: true + }), colorTemperatureBinding: () => ({ name: 'binding', label: 'Binding/Device Type', @@ -69,7 +86,7 @@ export default { colorTemperatureRange: () => ({ name: 'range', label: 'Temperature Range in Kelvin', - description: 'Formatted as minRange:maxRange', + description: 'Formatted as minValue:maxValue', type: 'TEXT', default: '1000:10000', pattern: '[0-9]+:[0-9]+', @@ -122,7 +139,7 @@ export default { equalizerRange: (defaultValue) => ({ name: 'range', label: 'Equalizer Range', - description: 'Formatted as minRange:maxRange', + description: 'Formatted as minValue:maxValue', type: 'TEXT', default: defaultValue, pattern: '[+-]?[0-9]+:[+-]?[0-9]+' @@ -196,7 +213,7 @@ export default { multiple: true, advanced: true }), - presets: (stateDescription, placeholder, advanced = false) => ({ + presets: (stateDescription, placeholder) => ({ name: 'presets', label: 'Presets', description: @@ -210,8 +227,7 @@ export default { .filter((option) => !isNaN(option.value)) .map((option) => `${option.value}=${option.label}`), placeholder: placeholder.replace(/,/g, '\n'), - multiple: true, - advanced + multiple: true }), primaryControl: () => ({ name: 'primaryControl', @@ -257,7 +273,7 @@ export default { setpointRange: (item) => ({ name: 'setpointRange', label: 'Setpoint Range', - description: 'Formatted as minRange:maxRange', + description: 'Formatted as minValue:maxValue', type: 'TEXT', default: (config) => { const scale = config.scale || getGroupParameter('scale', item.groups) || getTemperatureScale(item) diff --git a/bundles/org.openhab.ui/web/src/components/item/metadata/item-metadata-alexa.vue b/bundles/org.openhab.ui/web/src/components/item/metadata/item-metadata-alexa.vue index e0483694d0..4b4a5ca587 100644 --- a/bundles/org.openhab.ui/web/src/components/item/metadata/item-metadata-alexa.vue +++ b/bundles/org.openhab.ui/web/src/components/item/metadata/item-metadata-alexa.vue @@ -29,7 +29,7 @@ {{ cl }} - +