Skip to content

Commit

Permalink
Add receiving system active notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sebilm committed Dec 22, 2023
1 parent 01358d0 commit 5ef23da
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/main.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions build/myuplinkRepository.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/myuplinkRepository.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ class Myuplink extends utils.Adapter {
system.devices?.forEach(async (dev: SystemDevice) => {
await this.setSystemDevice(dev, systemPath, accessToken);
});

const notifications = await this.myUplinkRepository?.getActiveNotifications(system.systemId, accessToken);
await createStringStateAsync(this, `${systemPath}.rawActiveNotifications`, 'Received raw JSON of active notifications', JSON.stringify(notifications, null, ''));
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/myuplinkRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios, { AxiosError } from 'axios';
import { AlarmsPaged } from './models/AlarmsPaged';
import { PagedSystemResult } from './models/PagedSystemResult';
import { ParameterData } from './models/ParameterData';

Expand Down Expand Up @@ -30,6 +31,10 @@ export class MyUplinkRepository {
return await this.getFromMyUplink<ParameterData[]>(`/v3/devices/${deviceId}/points`, accessToken);
}

async getActiveNotifications(systemId: string, accessToken: string): Promise<AlarmsPaged> {
return await this.getFromMyUplink<AlarmsPaged>(`/v2/systems/${systemId}/notifications/active?itemsPerPage=100`, accessToken);
}

private async getFromMyUplink<T>(suburl: string, accessToken: string): Promise<T> {
const lang = this.options.language;
this.log.debug(`GET ${suburl} (lang: ${lang})`);
Expand Down

0 comments on commit 5ef23da

Please sign in to comment.