Skip to content

Commit

Permalink
Fix toggle state attribute supported item types (#426)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <jeremy.setton@gmail.com>
  • Loading branch information
jsetton authored Dec 5, 2021
1 parent 6bd1478 commit 874b15d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lambda/alexa/smarthome/device/attributes/toggleState.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class ToggleState extends DeviceAttribute {
const itemType = item.groupType || item.type;

switch (itemType) {
// Switch toggle with action controls
// Number/String/Switch toggle with action controls
case ItemType.NUMBER:
case ItemType.STRING:
case ItemType.SWITCH:
return [
{ name: Capability.TOGGLE_CONTROLLER, property: Property.TOGGLE_STATE },
Expand Down
62 changes: 56 additions & 6 deletions lambda/test/alexa/cases/discovery/other.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
alexa: {
value: 'RangeValue',
config: {
// No playback action or toggle action support for number with dimension
// No playback action or turn on/off action support for number with dimension
actionMappings: 'TurnOff=0,TurnOn=1,Stop=0'
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ module.exports = {
value: 'RangeValue',
config: {
// code coverage test for state mappings with same range
stateMappings: ['Closed=1:100', 'Open=1:100']
stateMappings: 'Closed=1:100,Open=1:100'
}
}
}
Expand Down Expand Up @@ -176,15 +176,33 @@ module.exports = {
}
},
{
type: 'Switch',
type: 'String',
name: 'toggle2',
label: 'Toggle State 2',
metadata: {
alexa: {
value: 'ToggleState',
config: {
OFF: 'off',
ON: 'on',
// code coverage test for state mappings with same value
stateMappings: ['Closed=ON', 'Open=ON']
stateMappings: 'Closed=ON,Open=ON'
}
}
}
},
{
type: 'Number',
name: 'toggle3',
label: 'Toggle State 3',
metadata: {
alexa: {
value: 'ToggleState',
config: {
OFF: '0',
ON: '1',
// No turn on/off action support for number
actionMappings: 'TurnOff=0,TurnOn=1'
}
}
}
Expand Down Expand Up @@ -846,9 +864,41 @@ module.exports = {
property: 'toggleState',
parameters: {
capabilityNames: ['@Setting.ToggleState'],
stateMappings: { Closed: 'ON', Open: 'ON' }
stateMappings: { Closed: 'ON', Open: 'ON' },
OFF: 'off',
ON: 'on'
},
item: { name: 'toggle2', type: 'String' }
}
]
},
toggle3: {
capabilities: ['Alexa.ToggleController:toggle3.toggleState', 'Alexa.EndpointHealth.connectivity', 'Alexa'],
displayCategories: ['OTHER'],
friendlyName: 'Toggle State 3',
propertyFlags: {
'Alexa.ToggleController:toggle3': {
proactivelyReported: false,
retrievable: true,
nonControllable: false
}
},
resources: {
'Alexa.ToggleController:toggle3': {
friendlyNames: ['text:Toggle State:en-US']
}
},
cookie: [
{
name: 'ToggleController',
instance: 'Toggle:toggle3',
property: 'toggleState',
parameters: {
capabilityNames: ['@Setting.ToggleState'],
OFF: '0',
ON: '1'
},
item: { name: 'toggle2', type: 'Switch' }
item: { name: 'toggle3', type: 'Number' }
}
]
}
Expand Down

0 comments on commit 874b15d

Please sign in to comment.