-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Extended map to support geo location entities #2337
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c4b7e1
initial version of geo location map
exxamalte 33ddb72
configuring entities not required but source is
exxamalte b823190
extending existing map instead of adding a new one
exxamalte 85b68ff
renamed source to geo_location_source; clearer handling of geo locati…
exxamalte f38c9d2
geo location sources must now be an array
exxamalte 1e130ed
code cleanup
exxamalte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| 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; | ||
| } | ||
|
|
||
|
|
@@ -205,7 +222,24 @@ class HuiMapCard extends PolymerElement { | |
| } | ||
| const mapItems = (this._mapItems = []); | ||
|
|
||
| this._configEntities.forEach((entity) => { | ||
| var allEntities = []; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing use var
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, will replace with |
||
| 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; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, moving code around.