Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWD: Fix entity type detection when using translated enity_id #223

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];

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
Loading