Skip to content

Commit

Permalink
improve interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Nov 6, 2024
1 parent be215b9 commit 1451ca3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
31 changes: 16 additions & 15 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ export class API implements IAPI {
return this.#api.post('/HolidayMode/Update', postData)
}

public async setLanguage(language: string): Promise<boolean> {
const { data: didLanguageChange } = await this.#setLanguage({
postData: { language: this.#getLanguageCode(language) },
})
if (didLanguageChange) {
this.language = language
public async setLanguage(language: string): Promise<void> {
if (language !== this.language) {
const { data: hasLanguageChanged } = await this.updateLanguage({
postData: { language: this.#getLanguageCode(language) },
})
if (hasLanguageChanged) {
this.language = language
}
}
return didLanguageChange
}

public async setPower({
Expand All @@ -340,6 +341,14 @@ export class API implements IAPI {
return this.#api.post('/Device/Power', postData)
}

public async updateLanguage({
postData,
}: {
postData: { language: Language }
}): Promise<{ data: boolean }> {
return this.#api.post<boolean>('/User/UpdateLanguage', postData)
}

async #authenticate({
password,
username,
Expand Down Expand Up @@ -450,14 +459,6 @@ export class API implements IAPI {
}
}

async #setLanguage({
postData,
}: {
postData: { language: Language }
}): Promise<{ data: boolean }> {
return this.#api.post<boolean>('/User/UpdateLanguage', postData)
}

#setOptionalProperties({
language,
password,
Expand Down
8 changes: 6 additions & 2 deletions src/services/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DeviceType } from '../enums.js'
import type { DeviceType, Language } from '../enums.js'
import type {
Building,
EnergyData,
Expand Down Expand Up @@ -143,11 +143,15 @@ export interface IAPI {
}: {
postData: HolidayModePostData
}) => Promise<{ data: FailureData | SuccessData }>
setLanguage: (language: string) => Promise<boolean>
setPower: ({
postData,
}: {
postData: SetPowerPostData
}) => Promise<{ data: boolean }>
updateLanguage: ({
postData,
}: {
postData: { language: Language }
}) => Promise<{ data: boolean }>
onSync?: () => Promise<void>
}

0 comments on commit 1451ca3

Please sign in to comment.