Skip to content

Commit

Permalink
Cleanup DWD integration code (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek authored May 25, 2024
1 parent efb333d commit 334d60d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/integrations/dwd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ export default class DWD implements MeteoalarmIntegration {
14: MeteoalarmEventType.CoastalEvent,
15: MeteoalarmEventType.CoastalEvent,
16: MeteoalarmEventType.CoastalEvent,
98: MeteoalarmEventType.Unknown, // Test warning
99: MeteoalarmEventType.Unknown, // Test warning
};
}

public getAlerts(entity: HassEntity): MeteoalarmAlert[] {
public getAlerts(entity: DWDEntity): MeteoalarmAlert[] {
const { warning_count: warningCount } = entity.attributes;

const result: MeteoalarmAlert[] = [];
Expand All @@ -117,19 +119,16 @@ export default class DWD implements MeteoalarmIntegration {
const level = entity.attributes[`warning_${i}_level`];
const id = entity.attributes[`warning_${i}_type`];
const headline = entity.attributes[`warning_${i}_headline`];
if (level == entity.state) {
if (id in this.eventTypes) {
result.push({
headline: headline,
level: this.convertAwarenessLevel(level) as MeteoalarmLevelType,
event: this.eventTypes[id],
kind: kind,
});
} else if (id == 98 || id == 99) {
throw new Error('An test warning was issued! ID: ' + id);
} else {
throw new Error('Unknown event ID: ' + id);
}

if (id in this.eventTypes) {
result.push({
headline: headline,
level: this.convertAwarenessLevel(level) as MeteoalarmLevelType,
event: this.eventTypes[id],
kind: kind,
});
} else {
throw new Error('Unknown event ID: ' + id);
}
}

Expand Down

0 comments on commit 334d60d

Please sign in to comment.