Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve channel request by name matching #555

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,9 @@ If paired with [`PositionState`](#positionstate), the primary controls (open/clo

#### `Channel`

Items that represent a channel. It is important to note only well-known channel names can be used as these are validated against a database on the Alexa side when requested. Unfortunately, Amazon doesn't provide a list of supported channel names. For String, by default, only requests by name are supported. To enable support for requests by number, set parameter `supportsChannelNumber=true`. For adjustment requests, by default, the increment is linear within the `range` parameter for Number, or the `channelMappings` parameter for String, based on the current state. For adjustment in incremental discrete steps, add [`ChannelStep`](#channelstep) to your entertainment group endpoint.
Items that represent a channel. For String, by default, only requests by name are supported. To enable support for requests by number, set parameter `supportsChannelNumber=true`. For adjustment requests, by default, the increment is linear within the `range` parameter for Number, or the `channelMappings` parameter for String, based on the current state. For adjustment in incremental discrete steps, add [`ChannelStep`](#channelstep) to your entertainment group endpoint.

It is important to note that only well-known channel names can be used as these are matched against a database on the Alexa side when requested. While Amazon doesn't provide a list of supported channel names, it is recommended using the names listed on [TV Channel Lists](https://www.tvchannellists.com) for your regional channel lineup.

* Supported item types:
* Number
Expand Down
8 changes: 5 additions & 3 deletions lambda/alexa/smarthome/handlers/channelController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export default class ChannelController extends AlexaHandler {
// 2) using directive payload channel number if supported
// 3) undefined
const command = channelName
? Object.keys(channelMappings).find(
(channel) => channelMappings[channel].toUpperCase() === channelName.toUpperCase()
)
? Object.keys(channelMappings).find((channel) => {
const mapping = channelMappings[channel].replace(/\s/g, '');
const name = channelName.replace(/\s/g, '');
return new RegExp(`^${name}`, 'i').test(mapping);
})
: supportsChannelNumber
? channelNumber
: undefined;
Expand Down
22 changes: 11 additions & 11 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', bar: 'BAR', baz: 'BAZ' } },
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
item: { name: 'channel', type: 'String' }
}
]
Expand Down Expand Up @@ -220,7 +220,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { 12: 'FOO', 34: 'BAR', 56: 'BAZ' } },
parameters: { channelMappings: { 12: 'FOO 1', 34: 'BAR 2', 56: 'BAZ 3' } },
item: { name: 'channel', type: 'Number' }
}
]
Expand All @@ -243,7 +243,7 @@ export default [
name: 'channel',
value: {
number: '56',
callSign: 'BAZ'
callSign: 'BAZ 3'
}
}
]
Expand Down Expand Up @@ -274,7 +274,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO', bar: 'BAR', baz: 'BAZ' } },
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
item: { name: 'channel', type: 'String' }
}
]
Expand All @@ -283,7 +283,7 @@ export default [
payload: {
channel: {},
channelMetadata: {
name: 'baz'
name: 'baz3'
}
}
},
Expand All @@ -296,7 +296,7 @@ export default [
namespace: 'Alexa.ChannelController',
name: 'channel',
value: {
callSign: 'BAZ'
callSign: 'BAZ 3'
}
}
]
Expand Down Expand Up @@ -327,7 +327,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { 12: 'FOO', 34: 'BAR' } },
parameters: { channelMappings: { 12: 'FOO 1', 34: 'BAR 2' } },
item: { name: 'channel', type: 'Number' }
}
]
Expand Down Expand Up @@ -369,7 +369,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO', bar: 'BAR', baz: 'BAZ' } },
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
item: { name: 'channel', type: 'Number' }
}
]
Expand Down Expand Up @@ -506,7 +506,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO', bar: 'BAR', baz: 'BAZ' } },
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2', baz: 'BAZ 3' } },
item: { name: 'channel', type: 'String' }
}
]
Expand All @@ -528,7 +528,7 @@ export default [
namespace: 'Alexa.ChannelController',
name: 'channel',
value: {
callSign: 'BAZ'
callSign: 'BAZ 3'
}
}
]
Expand Down Expand Up @@ -637,7 +637,7 @@ export default [
{
name: 'ChannelController',
property: 'channel',
parameters: { channelMappings: { foo: 'FOO', bar: 'BAR' } },
parameters: { channelMappings: { foo: 'FOO 1', bar: 'BAR 2' } },
item: { name: 'channel', type: 'String' }
}
]
Expand Down