-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
205 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
4 changes: 2 additions & 2 deletions
4
.../show-dialog-dashboard-strategy-editor.ts → .../show-dialog-dashboard-strategy-editor.ts
This file contains 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
This file contains 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
This file contains 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
This file contains 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
32 changes: 32 additions & 0 deletions
32
src/panels/lovelace/strategies/map/map-dashboard-strategy.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ReactiveElement } from "lit"; | ||
import { customElement } from "lit/decorators"; | ||
import { LovelaceConfig } from "../../../../data/lovelace/config/types"; | ||
import { HomeAssistant } from "../../../../types"; | ||
import { MapViewStrategyConfig } from "./map-view-strategy"; | ||
|
||
export type MapDashboardStrategyConfig = MapViewStrategyConfig; | ||
|
||
@customElement("map-dashboard-strategy") | ||
export class MapDashboardStrategy extends ReactiveElement { | ||
static async generate( | ||
config: MapDashboardStrategyConfig, | ||
hass: HomeAssistant | ||
): Promise<LovelaceConfig> { | ||
return { | ||
title: hass.localize("panel.map"), | ||
views: [ | ||
{ | ||
strategy: config, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
static noEditor = true; | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"map-dashboard-strategy": MapDashboardStrategy; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ReactiveElement } from "lit"; | ||
import { customElement } from "lit/decorators"; | ||
import { computeStateDomain } from "../../../../common/entity/compute_state_domain"; | ||
import { LovelaceViewConfig } from "../../../../data/lovelace/config/view"; | ||
import { HomeAssistant } from "../../../../types"; | ||
import { MapCardConfig } from "../../cards/types"; | ||
|
||
export type MapViewStrategyConfig = { | ||
type: "map"; | ||
}; | ||
|
||
const getMapEntities = (hass: HomeAssistant) => { | ||
const personSources = new Set<string>(); | ||
const locationEntities: string[] = []; | ||
Object.values(hass.states).forEach((entity) => { | ||
if ( | ||
entity.state === "home" || | ||
!("latitude" in entity.attributes) || | ||
!("longitude" in entity.attributes) | ||
) { | ||
return; | ||
} | ||
locationEntities.push(entity.entity_id); | ||
if (computeStateDomain(entity) === "person" && entity.attributes.source) { | ||
personSources.add(entity.attributes.source); | ||
} | ||
}); | ||
|
||
return locationEntities.filter((entity) => !personSources.has(entity)); | ||
}; | ||
|
||
@customElement("map-view-strategy") | ||
export class MapViewStrategy extends ReactiveElement { | ||
static async generate( | ||
_config: MapViewStrategyConfig, | ||
hass: HomeAssistant | ||
): Promise<LovelaceViewConfig> { | ||
const entities = getMapEntities(hass); | ||
return { | ||
type: "panel", | ||
title: hass.localize("panel.map"), | ||
icon: "mdi:map", | ||
cards: [ | ||
{ | ||
type: "map", | ||
auto_fit: true, | ||
entities: entities, | ||
} as MapCardConfig, | ||
], | ||
}; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"map-view-strategy": MapViewStrategy; | ||
} | ||
} |
This file contains 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
12 changes: 6 additions & 6 deletions
12
...rategies/original-states-view-strategy.ts → ...l-states/original-states-view-strategy.ts
This file contains 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
This file contains 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
This file contains 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