Skip to content

Commit

Permalink
Restrict generic semantic mappings support (#566)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <jeremy.setton@gmail.com>
  • Loading branch information
jsetton authored Feb 15, 2023
1 parent c1a6698 commit 2f649a3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lambda/alexa/smarthome/properties/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ export default class Generic extends DecoupleState {
// Upate non-controllable parameter using item state description read only property if not defined
parameters[Parameter.NON_CONTROLLABLE] = nonControllable ?? item.stateDescription?.readOnly;

const actionMappings = parameters[Parameter.ACTION_MAPPINGS] || {};
// Define action mappings using parameter values if property is controllable
const actionMappings = (!this.isNonControllable && parameters[Parameter.ACTION_MAPPINGS]) || {};
// Update action mappings parameter removing unsupported action semantics
parameters[Parameter.ACTION_MAPPINGS] = Object.entries(actionMappings)
.filter(([action]) => this.supportedActionSemantics.includes(action))
.reduce((actions, [action, mapping]) => ({ ...actions, [action]: mapping }), undefined);

const stateMappings = parameters[Parameter.STATE_MAPPINGS] || {};
// Define state mappings using parameter values if property is retrievable
const stateMappings = (this.isRetrievable && parameters[Parameter.STATE_MAPPINGS]) || {};
// Update state mappings parameter removing unsupported state semantics
parameters[Parameter.STATE_MAPPINGS] = Object.entries(stateMappings)
.filter(([state]) => this.supportedStateSemantics.includes(state))
Expand Down
55 changes: 54 additions & 1 deletion lambda/test/alexa/cases/discovery/other.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ export default {
}
}
},
{
type: 'Switch',
name: 'mode4',
label: 'Mode 4',
metadata: {
alexa: {
value: 'Mode',
config: {
supportedModes: 'OFF=@Value.Close,ON=@Value.Open',
retrievable: false,
// No state mappings support if not retrievable
stateMappings: 'Closed=OFF,Open=ON'
}
}
}
},
{
type: 'String',
name: 'mode99',
Expand Down Expand Up @@ -155,7 +171,9 @@ export default {
alexa: {
value: 'RangeValue',
config: {
nonControllable: true
nonControllable: true,
// No action mappings support if non controllable
actionMappings: 'Close=0'
}
}
}
Expand Down Expand Up @@ -511,6 +529,40 @@ export default {
}
]
},
mode4: {
capabilities: ['Alexa.ModeController:mode4', 'Alexa'],
displayCategories: ['OTHER'],
friendlyName: 'Mode 4',
propertyFlags: {}, // no property flags expected
resources: {
'Alexa.ModeController:mode4': {
friendlyNames: ['asset:Alexa.Setting.Mode']
}
},
configuration: {
'Alexa.ModeController:mode4': {
ordered: false,
supportedModes: {
OFF: { friendlyNames: ['asset:Alexa.Value.Close'] },
ON: { friendlyNames: ['asset:Alexa.Value.Open'] }
}
}
},
semantics: {}, // no semantics expected
cookie: [
{
name: 'ModeController',
instance: 'Mode:mode4',
property: 'mode',
parameters: {
capabilityNames: ['@Setting.Mode'],
supportedModes: { OFF: ['@Value.Close'], ON: ['@Value.Open'] },
retrievable: false
},
item: { name: 'mode4', type: 'Switch' }
}
]
},
range1: {
capabilities: [
'Alexa.ModeController:range1',
Expand Down Expand Up @@ -804,6 +856,7 @@ export default {
unitOfMeasure: 'Alexa.Unit.Angle.Degrees'
}
},
semantics: {}, // no semantics expected
cookie: [
{
name: 'RangeController',
Expand Down

0 comments on commit 2f649a3

Please sign in to comment.