Skip to content
Merged
Changes from 5 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
38 changes: 36 additions & 2 deletions src/panels/lovelace/cards/hui-map-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,24 @@ class HuiMapCard extends PolymerElement {
throw new Error("Error in card configuration.");
}

this._configEntities = processConfigEntities(config.entities);
this._configGeoLocationSources = config.geo_location_sources;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't assign before raising errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, moving code around.

this._configEntities = config.entities;

if (!this._configEntities && !this._configGeoLocationSources) {
throw new Error(
"Either entities or geo_location_sources must be defined"
);
}
if (this._configEntities && !Array.isArray(this._configEntities)) {
throw new Error("Entities need to be an array");
}
if (
this._configGeoLocationSources &&
!Array.isArray(this._configGeoLocationSources)
) {
throw new Error("Geo_location_sources needs to be an array");
}

this._config = config;
}

Expand Down Expand Up @@ -205,7 +222,24 @@ class HuiMapCard extends PolymerElement {
}
const mapItems = (this._mapItems = []);

this._configEntities.forEach((entity) => {
var allEntities = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing use var

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will replace with let

if (this._configEntities) {
allEntities = allEntities.concat(this._configEntities);
}
if (this._configGeoLocationSources) {
Object.keys(this.hass.states).forEach((entityId) => {
const stateObj = this.hass.states[entityId];
if (
computeStateDomain(stateObj) === "geo_location" &&
this._configGeoLocationSources.includes(stateObj.attributes.source)
) {
allEntities.push(entityId);
}
});
}
allEntities = processConfigEntities(allEntities);

allEntities.forEach((entity) => {
const entityId = entity.entity;
if (!(entityId in hass.states)) {
return;
Expand Down