Skip to content

Commit

Permalink
fix: Fix how string attributes are encoded in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuscc committed Jan 26, 2019
1 parent cc833f2 commit 1336a0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 9 additions & 1 deletion __tests__/write/heosCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Heos commands can be correctly created', () => {
expect(command).toEqual('heos://player/volume_up?pid=2&step=5\r\n')
})

test('A command can have no attributes', () => {
test('A command can have zero attributes', () => {
const command = generateHeosCommand('system', 'heart_beat', {})

expect(command).toEqual('heos://system/heart_beat\r\n')
Expand All @@ -28,4 +28,12 @@ describe('Heos commands can be correctly created', () => {

expect(command).toEqual('heos://player/get_volume?pid=1\r\n')
})

test('Strings are correctly encoded', () => {
const command = generateHeosCommand('system', 'register_for_change_events', {
enable: 'on'
})

expect(command).toEqual('heos://system/register_for_change_events?enable=on\r\n')
})
})
8 changes: 1 addition & 7 deletions src/write/heosCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ function attributeString(attributes?: HeosCommandAttribute): string {
return (
'?' +
Object.entries(attributes)
.map(([key, value]) => {
if (typeof value === 'string') {
return `${key}='${value}'`
} else {
return `${key}=${value.toString()}`
}
})
.map(([key, value]) => `${key}=${value}`)
.reduce((previous, current) => `${previous}&${current}`)
)
}
Expand Down

0 comments on commit 1336a0c

Please sign in to comment.