Skip to content

Commit

Permalink
DWD: Fix entity type detection when using translated enity_id (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek authored Oct 16, 2023
1 parent b4167f1 commit a05a52d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/integrations/dwd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,29 @@ export default class DWD implements MeteoalarmIntegration {
}

private getEntityKind(entity: HassEntity): MeteoalarmAlertKind | undefined {
if (entity.entity_id.split('_').includes('current')) {
return MeteoalarmAlertKind.Current;
} else if (entity.entity_id.split('_').includes('advance')) {
return MeteoalarmAlertKind.Expected;
} else if (entity.attributes.friendly_name?.split(' ').includes('Current')) {
/**
* Detecting only by English and German entity_id translations here is hardly
* a good solution but, it covers 99% of use cases, should be improved in the
* future
*/
const CURRENT_IDENTIFIERS = ['current', 'aktuelle'];
const EXPECTED_IDENTIFIERS = ['advance', 'vorwahnstufe'];

This comment has been minimized.

Copy link
@Tobboss

Tobboss Oct 16, 2023

typo: it's 'vorwarnstufe' not 'vorwahnstufe'

This comment has been minimized.

Copy link
@MrBartusek

MrBartusek Oct 16, 2023

Author Owner

Thank you, fixed


const friendlyName = entity.attributes.friendly_name || '';
const entityIdParts = entity.entity_id.split('_').map((p) => p.toLocaleLowerCase());
const friendlyNameParts = friendlyName?.split(' ').map((p) => p.toLocaleLowerCase());

if (
CURRENT_IDENTIFIERS.some(
(ident) => entityIdParts.includes(ident) || friendlyNameParts.includes(ident),
)
) {
return MeteoalarmAlertKind.Current;
} else if (entity.attributes.friendly_name?.split(' ').includes('Advance')) {
} else if (
EXPECTED_IDENTIFIERS.some(
(ident) => entityIdParts.includes(ident) || friendlyNameParts.includes(ident),
)
) {
return MeteoalarmAlertKind.Expected;
}
return undefined;
Expand Down

0 comments on commit a05a52d

Please sign in to comment.