Allow map card to render passive zones (#15901)

This commit is contained in:
karwosts 2023-03-22 09:51:47 -07:00 committed by GitHub
parent 4f5fca7c60
commit 7c62b08fdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View File

@ -50,6 +50,10 @@ export class HaMap extends ReactiveElement {
@property({ type: Boolean }) public autoFit = false; @property({ type: Boolean }) public autoFit = false;
@property({ type: Boolean }) public renderPassive = false;
@property({ type: Boolean }) public interactiveZones = false;
@property({ type: Boolean }) public fitZones?: boolean; @property({ type: Boolean }) public fitZones?: boolean;
@property({ type: Boolean }) public darkMode?: boolean; @property({ type: Boolean }) public darkMode?: boolean;
@ -321,6 +325,10 @@ export class HaMap extends ReactiveElement {
const computedStyles = getComputedStyle(this); const computedStyles = getComputedStyle(this);
const zoneColor = computedStyles.getPropertyValue("--accent-color"); const zoneColor = computedStyles.getPropertyValue("--accent-color");
const passiveZoneColor = computedStyles.getPropertyValue(
"--secondary-text-color"
);
const darkPrimaryColor = computedStyles.getPropertyValue( const darkPrimaryColor = computedStyles.getPropertyValue(
"--dark-primary-color" "--dark-primary-color"
); );
@ -350,7 +358,7 @@ export class HaMap extends ReactiveElement {
if (computeStateDomain(stateObj) === "zone") { if (computeStateDomain(stateObj) === "zone") {
// DRAW ZONE // DRAW ZONE
if (passive) { if (passive && !this.renderPassive) {
continue; continue;
} }
@ -374,7 +382,7 @@ export class HaMap extends ReactiveElement {
iconSize: [24, 24], iconSize: [24, 24],
className, className,
}), }),
interactive: false, interactive: this.interactiveZones,
title, title,
}) })
); );
@ -383,7 +391,7 @@ export class HaMap extends ReactiveElement {
this._mapZones.push( this._mapZones.push(
Leaflet.circle([latitude, longitude], { Leaflet.circle([latitude, longitude], {
interactive: false, interactive: false,
color: zoneColor, color: passive ? passiveZoneColor : zoneColor,
radius, radius,
}) })
); );

View File

@ -16,7 +16,7 @@ import { getColorByIndex } from "../../../common/color/colors";
import { isComponentLoaded } from "../../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { formatDateTime } from "../../../common/datetime/format_date_time"; import { formatDateTime } from "../../../common/datetime/format_date_time";
import { import {
formatTime, formatTimeWithSeconds,
formatTimeWeekday, formatTimeWeekday,
} from "../../../common/datetime/format_time"; } from "../../../common/datetime/format_time";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
@ -152,6 +152,8 @@ class HuiMapCard extends LitElement implements LovelaceCard {
.paths=${this._getHistoryPaths(this._config, this._stateHistory)} .paths=${this._getHistoryPaths(this._config, this._stateHistory)}
.autoFit=${this._config.auto_fit} .autoFit=${this._config.auto_fit}
.darkMode=${this._config.dark_mode} .darkMode=${this._config.dark_mode}
interactiveZones
renderPassive
></ha-map> ></ha-map>
<ha-icon-button <ha-icon-button
.label=${this.hass!.localize( .label=${this.hass!.localize(
@ -329,6 +331,9 @@ class HuiMapCard extends LitElement implements LovelaceCard {
const paths: HaMapPaths[] = []; const paths: HaMapPaths[] = [];
for (const entityId of Object.keys(history)) { for (const entityId of Object.keys(history)) {
if (computeDomain(entityId) === "zone") {
continue;
}
const entityStates = history[entityId]; const entityStates = history[entityId];
if (!entityStates?.length) { if (!entityStates?.length) {
continue; continue;
@ -349,7 +354,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
// date and time // date and time
p.tooltip = formatDateTime(t, this.hass.locale); p.tooltip = formatDateTime(t, this.hass.locale);
} else if (isToday(t)) { } else if (isToday(t)) {
p.tooltip = formatTime(t, this.hass.locale); p.tooltip = formatTimeWithSeconds(t, this.hass.locale);
} else { } else {
p.tooltip = formatTimeWeekday(t, this.hass.locale); p.tooltip = formatTimeWeekday(t, this.hass.locale);
} }

View File

@ -38,7 +38,12 @@ class HaPanelMap extends LitElement {
: ""} : ""}
</app-toolbar> </app-toolbar>
</app-header> </app-header>
<ha-map .hass=${this.hass} .entities=${this._entities} autoFit></ha-map> <ha-map
.hass=${this.hass}
.entities=${this._entities}
autoFit
interactiveZones
></ha-map>
</ha-app-layout> </ha-app-layout>
`; `;
} }