Skip to content

Commit

Permalink
Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Jul 1, 2024
1 parent c098eb1 commit 0a8c001
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ jobs:
npm-token: ${{ secrets.NPM_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}

# When using Sentry for error reporting, Sentry can be informed about new releases
# To enable create a API-Token in Sentry (User settings, API keys)
# Enter this token as a GitHub secret (with name SENTRY_AUTH_TOKEN) in the repository options
# Then uncomment and customize the following block:
# sentry: true
# sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
# sentry-project: "iobroker-awtrix-light"
# sentry-version-prefix: "iobroker.awtrix-light"
# sentry-sourcemap-paths: "build/"
sentry: true
sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
sentry-project: "iobroker-awtrix-light"
sentry-version-prefix: "iobroker.awtrix-light"
sentry-sourcemap-paths: "build/"
# If your sentry project is linked to a GitHub repository, you can enable the following option
# sentry-github-integration: true
43 changes: 40 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const NATIVE_APPS = ['Time', 'Date', 'Temperature', 'Humidity', 'Battery'];
export class AwtrixLight extends utils.Adapter {
private _isMainInstance: boolean;

private currentVersion: string | undefined;
private supportedVersion: string;
private displayedVersionWarning: boolean;

Expand All @@ -40,6 +41,7 @@ export class AwtrixLight extends utils.Adapter {

this._isMainInstance = true;

this.currentVersion = undefined;
this.supportedVersion = '0.96';
this.displayedVersionWarning = false;

Expand Down Expand Up @@ -114,6 +116,8 @@ export class AwtrixLight extends utils.Adapter {
customApp.position = pos++;
}
this.apps.push(new AppTypeCustom.Custom(this.apiClient, this, customApp));
} else {
this.log.warn(`App with name ${customApp.name} already exists. Skipping custom app!`);
}
}

Expand All @@ -123,6 +127,8 @@ export class AwtrixLight extends utils.Adapter {
historyApp.position = pos++;
}
this.apps.push(new AppTypeHistory.History(this.apiClient, this, historyApp));
} else {
this.log.warn(`App with name ${historyApp.name} already exists. Skipping history app!`);
}
}

Expand All @@ -132,6 +138,8 @@ export class AwtrixLight extends utils.Adapter {
expertApp.position = pos++;
}
this.apps.push(new AppTypeExpert.Expert(this.apiClient, this, expertApp));
} else {
this.log.warn(`App with name ${expertApp.name} already exists. Skipping expert app!`);
}
}

Expand Down Expand Up @@ -520,10 +528,12 @@ export class AwtrixLight extends utils.Adapter {
.then(async (content) => {
await this.setApiConnected(true);

if (this.isNewerVersion(content.version, this.supportedVersion) && !this.displayedVersionWarning) {
this.registerNotification('awtrix-light', 'deviceUpdate', `Firmware update: ${content.version} -> ${this.supportedVersion}`);
this.currentVersion = String(content.version);

this.log.warn(`You should update your Awtrix Light - supported version of this adapter is ${this.supportedVersion} (or later). Your current version is ${content.version}`);
if (this.isNewerVersion(this.currentVersion, this.supportedVersion) && !this.displayedVersionWarning) {
this.registerNotification('awtrix-light', 'deviceUpdate', `Firmware update: ${this.currentVersion} -> ${this.supportedVersion}`);

this.log.warn(`You should update your Awtrix Light - supported version of this adapter is ${this.supportedVersion} (or later). Your current version is ${this.currentVersion}`);
this.displayedVersionWarning = true; // Just show once
}

Expand All @@ -543,6 +553,8 @@ export class AwtrixLight extends utils.Adapter {
await this.setStateChangedAsync('device.uptime', { val: parseInt(content.uptime), ack: true });
})
.catch((error) => {
this.currentVersion = undefined;

this.log.debug(`(stats) received error - API is now offline: ${JSON.stringify(error)}`);
this.setApiConnected(false);
});
Expand Down Expand Up @@ -854,6 +866,31 @@ export class AwtrixLight extends utils.Adapter {
}
return false;
}

private getSentryObject(): any {
if (this.supportsFeature && this.supportsFeature('PLUGINS')) {
const sentryInstance = this.getPluginInstance('sentry');
if (sentryInstance) {
return sentryInstance.getSentryObject();
}
}

return undefined;
}

public addSentryMessage(msg: string): void {
const sentryObj = this.getSentryObject();

if (sentryObj) {
sentryObj.withScope((scope: any) => {
if (this.currentVersion) {
scope.setTag('firmwareVersion', this.currentVersion || 'unknown');
}

sentryObj.captureMessage(msg, 'info');
});
}
}
}

if (require.main !== module) {
Expand Down

0 comments on commit 0a8c001

Please sign in to comment.