Skip to content

Commit

Permalink
Update channel request by name substitution pattern (#558)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <[email protected]>
  • Loading branch information
jsetton authored Jan 22, 2023
1 parent d7ce073 commit 0ba5434
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
5 changes: 3 additions & 2 deletions lambda/alexa/smarthome/handlers/channelController.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export default class ChannelController extends AlexaHandler {
// 3) undefined
const command = channelName
? Object.keys(channelMappings).find((channel) => {
const mapping = channelMappings[channel].replace(/\s/g, '');
const name = channelName.replace(/\s/g, '');
const pattern = /[\s_.-]+/g;
const mapping = channelMappings[channel].replace(pattern, '');
const name = channelName.replace(pattern, '');
return new RegExp(`^${name}`, 'i').test(mapping);
})
: supportsChannelNumber
Expand Down
52 changes: 26 additions & 26 deletions lambda/test/alexa/cases/channelController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
parameters: { channelMappings: { foo1: 'FOO 1', foo2: 'FOO 2' } },
item: { name: 'channel', type: 'String' }
}
]
Expand Down Expand Up @@ -220,7 +220,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { 12: 'FOO 1', 34: 'BAR 2', 56: 'BAZ 3' } },
parameters: { channelMappings: { 12: 'FOO 1', 34: 'FOO 2' } },
item: { name: 'channel', type: 'Number' }
}
]
Expand All @@ -229,11 +229,11 @@ export default [
payload: {
channel: {},
channelMetadata: {
name: 'baz'
name: 'foo'
}
}
},
items: [{ name: 'channel', state: '56', type: 'Number' }],
items: [{ name: 'channel', state: '12', type: 'Number' }],
expected: {
alexa: {
context: {
Expand All @@ -242,8 +242,8 @@ export default [
namespace: 'Alexa.ChannelController',
name: 'channel',
value: {
number: '56',
callSign: 'BAZ 3'
number: '12',
callSign: 'FOO 1'
}
}
]
Expand All @@ -256,7 +256,7 @@ export default [
}
},
openhab: {
commands: [{ name: 'channel', value: '56' }]
commands: [{ name: 'channel', value: '12' }]
}
}
},
Expand All @@ -274,7 +274,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
parameters: { channelMappings: { foo1: 'FOO 1', foo2: 'FOO 2' } },
item: { name: 'channel', type: 'String' }
}
]
Expand All @@ -283,11 +283,11 @@ export default [
payload: {
channel: {},
channelMetadata: {
name: 'baz3'
name: 'foo2'
}
}
},
items: [{ name: 'channel', state: 'baz', type: 'String' }],
items: [{ name: 'channel', state: 'foo2', type: 'String' }],
expected: {
alexa: {
context: {
Expand All @@ -296,7 +296,7 @@ export default [
namespace: 'Alexa.ChannelController',
name: 'channel',
value: {
callSign: 'BAZ 3'
callSign: 'FOO 2'
}
}
]
Expand All @@ -309,7 +309,7 @@ export default [
}
},
openhab: {
commands: [{ name: 'channel', value: 'baz' }]
commands: [{ name: 'channel', value: 'foo2' }]
}
}
},
Expand All @@ -327,7 +327,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { 12: 'FOO 1', 34: 'BAR 2' } },
parameters: { channelMappings: { 12: 'FOO 1', 34: 'FOO 2' } },
item: { name: 'channel', type: 'Number' }
}
]
Expand All @@ -336,7 +336,7 @@ export default [
payload: {
channel: {},
channelMetadata: {
name: 'baz'
name: 'bar'
}
}
},
Expand All @@ -349,7 +349,7 @@ export default [
},
payload: {
type: 'INVALID_VALUE',
message: 'The channel cannot be changed to baz.'
message: 'The channel cannot be changed to bar.'
}
}
}
Expand All @@ -369,7 +369,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
parameters: { channelMappings: { foo1: 'FOO 1', foo2: 'FOO 2' } },
item: { name: 'channel', type: 'Number' }
}
]
Expand All @@ -378,7 +378,7 @@ export default [
payload: {
channel: {},
channelMetadata: {
name: 'baz'
name: 'foo.2'
}
}
},
Expand All @@ -391,7 +391,7 @@ export default [
},
payload: {
type: 'INVALID_VALUE',
message: 'The channel cannot be changed to baz.'
message: 'The channel cannot be changed to foo2.'
}
}
}
Expand Down Expand Up @@ -506,7 +506,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
parameters: { channelMappings: { foo1: 'FOO 1', foo2: 'FOO 2' } },
item: { name: 'channel', type: 'String' }
}
]
Expand All @@ -517,8 +517,8 @@ export default [
}
},
items: [
{ name: 'channel', state: 'bar', type: 'String' },
{ name: 'channel', state: 'baz', type: 'String' }
{ name: 'channel', state: 'foo1', type: 'String' },
{ name: 'channel', state: 'foo2', type: 'String' }
],
expected: {
alexa: {
Expand All @@ -528,7 +528,7 @@ export default [
namespace: 'Alexa.ChannelController',
name: 'channel',
value: {
callSign: 'BAZ 3'
callSign: 'FOO 2'
}
}
]
Expand All @@ -541,7 +541,7 @@ export default [
}
},
openhab: {
commands: [{ name: 'channel', value: 'baz' }]
commands: [{ name: 'channel', value: 'foo2' }]
}
}
},
Expand Down Expand Up @@ -637,7 +637,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2' } },
parameters: { channelMappings: { foo1: 'FOO 1', foo2: 'FOO 2' } },
item: { name: 'channel', type: 'String' }
}
]
Expand All @@ -647,7 +647,7 @@ export default [
channelCount: -1
}
},
items: [{ name: 'channel', state: 'baz', type: 'String' }],
items: [{ name: 'channel', state: 'bar', type: 'String' }],
expected: {
alexa: {
event: {
Expand All @@ -657,7 +657,7 @@ export default [
},
payload: {
type: 'INVALID_VALUE',
message: 'Current channel baz is not defined in channel mappings.'
message: 'Current channel bar is not defined in channel mappings.'
}
}
}
Expand Down

0 comments on commit 0ba5434

Please sign in to comment.