htd-lync
Version:
This library is meant to be used to interact with an HTD Lync 12
244 lines (219 loc) • 11.6 kB
text/typescript
import {describe, expect, test} from 'vitest'
import Protocol, {MP3, PartySource, Source, Zone} from "../src/Protocol";
describe.concurrent('Query', () => {
test('Command.get_status_all_zones()', async () => {
expect(Protocol.get_status_all_zones().get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x05,0x00,0x07]));
});
test('Command.get_status_all()', async () => {
expect(Protocol.get_status_all().get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x0C,0x00,0x0E]));
});
test('Command.get_id()', async () => {
expect(Protocol.get_id().get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x08,0x00,0x0A]));
});
});
describe.concurrent('All Power', () => {
test.each([
[]],
[]],
])('Command.set_all_power(%j) -> %o', (power, expected) => {
expect(Protocol.set_all_power(power).get_command()).toEqual(Buffer.from(expected));
});
});
describe.concurrent('Set Names', () => {
test('Command.set_zone_name(1, "Zone 1")', async () => {
expect(Protocol.set_zone_name(1, "Zone 1").get_command()).toEqual(Buffer.from([0x02,0x00,0x01,0x06,0x00,0x5A,0x6F,0x6E,0x65,0x20,0x31,0x00,0x00,0x00,0x00,0x00,0xF6]));
});
// FIXME: I'm unsure as of yet if data[0] should be 1-18 (per the docs) or the source hex
test('Command.set_zone_source_name(1, "Zone 1")', async () => {
expect(Protocol.set_zone_source_name(1, Source._01, "DVD").get_command()).toEqual(Buffer.from([0x02,0x00,0x01,0x07,0x10,0x44,0x56,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8]));
});
});
describe.concurrent('Files', () => {
test.each([
[]],
[]],
[]],
[]],
])('Command.recall_file(%i) -> %o', (file, expected) => {
expect(Protocol.recall_file(file).get_command()).toEqual(Buffer.from(expected));
})
test.each([
[]],
[]],
[]],
[]],
])('Command.save_file(%i) -> %o', (file, expected) => {
expect(Protocol.save_file(file).get_command()).toEqual(Buffer.from(expected));
});
});
describe.concurrent('MP3', () => {
test('Command.mp3(MP3.Back)', async () => {
expect(Protocol.mp3(MP3.Back).get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x04,0x0C,0x12]));
});
test('Command.mp3(MP3.FF)', async () => {
expect(Protocol.mp3(MP3.FF).get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x04,0x0A,0x10]));
});
test('Command.mp3(MP3.Play)', async () => {
expect(Protocol.mp3(MP3.Play).get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x04,0x0B,0x11]));
});
test('Command.mp3(MP3.Stop)', async () => {
expect(Protocol.mp3(MP3.Stop).get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x04,0x0D,0x13]));
});
test('Command.mp3(MP3.Repeat_Off)', async () => {
expect(Protocol.mp3(MP3.Repeat_Off).get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x01,0x00,0x03]));
});
test('Command.mp3(MP3.Repeat_On)', async () => {
expect(Protocol.mp3(MP3.Repeat_On).get_command()).toEqual(Buffer.from([0x02,0x00,0x00,0x01,0xFF,0x102]));
});
});
describe.concurrent('DND', () => {
test.concurrent.each([
[ 1, true, [0x02,0x00,0x01,0x04,0x59,0x60]],
[ 2, true, [0x02,0x00,0x02,0x04,0x59,0x61]],
[ 3, true, [0x02,0x00,0x03,0x04,0x59,0x62]],
[ 4, true, [0x02,0x00,0x04,0x04,0x59,0x63]],
[ 5, true, [0x02,0x00,0x05,0x04,0x59,0x64]],
[ 6, true, [0x02,0x00,0x06,0x04,0x59,0x65]],
[ 7, true, [0x02,0x00,0x07,0x04,0x59,0x66]],
[ 8, true, [0x02,0x00,0x08,0x04,0x59,0x67]],
[ 9, true, [0x02,0x00,0x09,0x04,0x59,0x68]],
[]],
[]],
[]],
[ 1, false, [0x02,0x00,0x01,0x04,0x5A,0x61]],
[ 2, false, [0x02,0x00,0x02,0x04,0x5A,0x62]],
[ 3, false, [0x02,0x00,0x03,0x04,0x5A,0x63]],
[ 4, false, [0x02,0x00,0x04,0x04,0x5A,0x64]],
[ 5, false, [0x02,0x00,0x05,0x04,0x5A,0x65]],
[ 6, false, [0x02,0x00,0x06,0x04,0x5A,0x66]],
[ 7, false, [0x02,0x00,0x07,0x04,0x5A,0x67]],
[ 8, false, [0x02,0x00,0x08,0x04,0x5A,0x68]],
[ 9, false, [0x02,0x00,0x09,0x04,0x5A,0x69]],
[]],
[]],
[]],
])('Command.set_dnd(%i, %j) -> %o', (zone, on, expected) => {
expect(Protocol.set_dnd(zone, on).get_command()).toEqual(Buffer.from(expected));
})
});
describe.concurrent('Mute', () => {
test.concurrent.each([
[ 1, true, [0x02,0x00,0x01,0x04,0x1E,0x25]],
[ 2, true, [0x02,0x00,0x02,0x04,0x1E,0x26]],
[ 3, true, [0x02,0x00,0x03,0x04,0x1E,0x27]],
[ 4, true, [0x02,0x00,0x04,0x04,0x1E,0x28]],
[ 5, true, [0x02,0x00,0x05,0x04,0x1E,0x29]],
[ 6, true, [0x02,0x00,0x06,0x04,0x1E,0x2A]],
[ 7, true, [0x02,0x00,0x07,0x04,0x1E,0x2B]],
[ 8, true, [0x02,0x00,0x08,0x04,0x1E,0x2C]],
[ 9, true, [0x02,0x00,0x09,0x04,0x1E,0x2D]],
[]],
[]],
[]],
[ 1, false, [0x02,0x00,0x01,0x04,0x1F,0x26]],
[ 2, false, [0x02,0x00,0x02,0x04,0x1F,0x27]],
[ 3, false, [0x02,0x00,0x03,0x04,0x1F,0x28]],
[ 4, false, [0x02,0x00,0x04,0x04,0x1F,0x29]],
[ 5, false, [0x02,0x00,0x05,0x04,0x1F,0x2A]],
[ 6, false, [0x02,0x00,0x06,0x04,0x1F,0x2B]],
[ 7, false, [0x02,0x00,0x07,0x04,0x1F,0x2C]],
[ 8, false, [0x02,0x00,0x08,0x04,0x1F,0x2D]],
[ 9, false, [0x02,0x00,0x09,0x04,0x1F,0x2E]],
[]],
[]],
[]],
])('Command.set_mute(%i, %j) -> %o', (zone, on, expected) => {
expect(Protocol.set_mute(zone, on).get_command()).toEqual(Buffer.from(expected));
})
});
describe.concurrent('Zone Power', () => {
test.concurrent.each([
[ 0, true, [0x02,0x00,0x00,0x04,0x57,0x5D]],
[ 1, true, [0x02,0x00,0x01,0x04,0x57,0x5E]],
[ 2, true, [0x02,0x00,0x02,0x04,0x57,0x5F]],
[ 3, true, [0x02,0x00,0x03,0x04,0x57,0x60]],
[ 4, true, [0x02,0x00,0x04,0x04,0x57,0x61]],
[ 5, true, [0x02,0x00,0x05,0x04,0x57,0x62]],
[ 6, true, [0x02,0x00,0x06,0x04,0x57,0x63]],
[ 7, true, [0x02,0x00,0x07,0x04,0x57,0x64]],
[ 8, true, [0x02,0x00,0x08,0x04,0x57,0x65]],
[ 9, true, [0x02,0x00,0x09,0x04,0x57,0x66]],
[]],
[]],
[]],
[ 0, false, [0x02,0x00,0x00,0x04,0x58,0x5E]],
[ 1, false, [0x02,0x00,0x01,0x04,0x58,0x5F]],
[ 2, false, [0x02,0x00,0x02,0x04,0x58,0x60]],
[ 3, false, [0x02,0x00,0x03,0x04,0x58,0x61]],
[ 4, false, [0x02,0x00,0x04,0x04,0x58,0x62]],
[ 5, false, [0x02,0x00,0x05,0x04,0x58,0x63]],
[ 6, false, [0x02,0x00,0x06,0x04,0x58,0x64]],
[ 7, false, [0x02,0x00,0x07,0x04,0x58,0x65]],
[ 8, false, [0x02,0x00,0x08,0x04,0x58,0x66]],
[ 9, false, [0x02,0x00,0x09,0x04,0x58,0x67]],
[]],
[]],
[]],
])('Command.set_zone_power(%i, %j) -> %o', (zone, on, expected) => {
expect(Protocol.set_zone_power(zone, on).get_command()).toEqual(Buffer.from(expected));
})
});
describe.concurrent('Party Mode (docs were wrong)', () => {
test.concurrent.each([
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]],
[]]
])('Command.set_party_mode(%i) -> %o', (party_input, expected) => {
expect(Protocol.set_party_mode(party_input).get_command()).toEqual(Buffer.from(expected));
})
});
describe.concurrent('Zone Settings', async () => {
test.concurrent.each([
[], 'below minimum'],
[], 'minimum'],
[], 'left'],
[], 'center'],
[], 'right'],
[], 'maximum'],
[], 'above maximum'],
])('Command.set_balance(%i, %i) -> %o - %s', async (zone, balance, expected) => {
expect(Protocol.set_balance(zone, balance).get_command()).toEqual(Buffer.from(expected));
});
test.concurrent.each([
[], 'below minimum'],
[], 'minimum'],
[], 'low'],
[], 'none'],
[], 'high'],
[], 'maximum'],
[], 'above maximum'],
])('Command.set_treble(%i, %i) -> %o - %s', async (zone, treble, expected) => {
expect(Protocol.set_treble(zone, treble).get_command()).toEqual(Buffer.from(expected));
});
test.concurrent.each([
[], 'below minimum'],
[], 'minimum'],
[], 'low'],
[], 'none'],
[], 'high'],
[], 'maximum'],
[], 'above maximum'],
])('Command.set_bass(%i, %i) -> %o - %s', async (zone, treble, expected) => {
expect(Protocol.set_bass(zone, treble).get_command()).toEqual(Buffer.from(expected));
});
});