Skip to content

Commit dcbf72c

Browse files
committed
feat: getLangugage route
1 parent 647211d commit dcbf72c

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Completed features so far:
3131
- [x] Group - Update Name
3232
- [x] Introspect Data
3333
- [x] Key Press, Release
34-
- [ ] Language
34+
- [x] Language
3535
- [ ] Media Servers List
3636
- [ ] Music Library - Get Items
3737
- [ ] Music Library - Search

src/client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
22
import { XMLParser, XMLBuilder } from "fast-xml-parser";
3-
import { AudioDSPControls, AudioDSPMode, Bass, BassCapabilities, BluetoothInfo, Capabilities, ClockDisplay, ClockTime, ConfigurationStatus, DeviceInfo, DSPMonoStereo, Group, IntrospectRequest, Key, KeyPressResponse, KeyPressState, KeySender, RemoveGroup, SpotifyAccountIntrospectResponse } from "./types.js";
3+
import { AudioDSPControls, AudioDSPMode, Bass, BassCapabilities, BluetoothInfo, Capabilities, ClockDisplay, ClockTime, ConfigurationStatus, DeviceInfo, DSPMonoStereo, Group, IntrospectRequest, Key, KeyPressResponse, KeyPressState, KeySender, Language, RemoveGroup, SpotifyAccountIntrospectResponse } from "./types.js";
44

55
export class SoundTouchApiClient {
66
private client: AxiosInstance;
@@ -279,5 +279,12 @@ export class SoundTouchApiClient {
279279
return this.parseResponse<KeyPressResponse>(res as any);
280280
}
281281

282+
/**
283+
* Gets the current Language of the device
284+
* @returns Language
285+
*/
286+
async getLanguage(): Promise<Language> {
287+
return this.get<Language>("/language");
288+
}
282289

283290
}

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,9 @@ export enum KeySender {
283283

284284
export interface KeyPressResponse {
285285
status: string;
286+
}
287+
288+
export interface Language {
289+
// i dont know what the numbers mean
290+
sysLanguage: number;
286291
}

tests/language.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
2+
import nock from "nock";
3+
import { SoundTouchApiClient } from "../src/client.js";
4+
import { SoundTouchConfigurationStatus } from "../src/types.js";
5+
6+
const mockXML = `<?xml version="1.0" encoding="UTF-8" ?>
7+
<sysLanguage>3</sysLanguage>`;
8+
9+
describe("SoundTouchAPI /language endpoint", () => {
10+
const baseURL = "http://localhost:8090";
11+
let api: SoundTouchApiClient;
12+
13+
beforeEach(() => {
14+
api = new SoundTouchApiClient(baseURL);
15+
nock.cleanAll();
16+
});
17+
18+
afterEach(() => {
19+
nock.cleanAll();
20+
});
21+
22+
it("parses /language response correctly", async () => {
23+
nock(baseURL)
24+
.get("/language")
25+
.reply(200, mockXML, { "Content-Type": "application/xml" });
26+
27+
const language = await api.getLanguage();
28+
29+
expect(language).toMatchObject({
30+
sysLanguage: 3,
31+
});
32+
});
33+
34+
});

0 commit comments

Comments
 (0)