Skip to content

Commit

Permalink
Improve enitities detection by getStubConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed May 29, 2021
1 parent b9e8b5a commit 1330a96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/integrations/meteofrance-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class MeteoFranceIntegration

static supports(entity)
{
return entity.attributes.attribution === 'Data provided by Météo-France';
return entity.attributes.attribution == 'Data provided by Météo-France' && entity.attributes[EVENT_WIND] != undefined;
}

static isWarningActive(entity)
Expand Down
11 changes: 5 additions & 6 deletions src/meteoalarm-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class MeteoalarmCard extends LitElement

static getStubConfig(hass, entities)
{
const [entity] = entities.filter(
(eid) => eid.includes('meteoalarm')
);
// Find fist entity that is supported by any integration
const entity = entities.find((eid) => this.integrations.some((integration) => integration.supports(hass.states[eid])))

return {
entity: entity || ''
Expand All @@ -43,7 +42,7 @@ class MeteoalarmCard extends LitElement
return document.createElement('meteoalarm-card-editor');
}

get integrations()
static get integrations()
{
return [MeteoAlarmIntegration, MeteoAlarmeuIntegration, MeteoFranceIntegration];
}
Expand Down Expand Up @@ -161,7 +160,7 @@ class MeteoalarmCard extends LitElement
{
if(key == 'automatic')
{
const result = this.integrations.find((i) => i.supports(entity))
const result = MeteoalarmCard.integrations.find((i) => i.supports(entity))
if(result == undefined)
{
throw Error(localize('error.automatic_failed'))
Expand All @@ -170,7 +169,7 @@ class MeteoalarmCard extends LitElement
}
else
{
return this.integrations.find((i) => i.name == key)
return MeteoalarmCard.find((i) => i.name == key)
}
}

Expand Down

0 comments on commit 1330a96

Please sign in to comment.