This commit is contained in:
J. Nick Koston 2023-01-21 17:53:38 -10:00
parent 26730cb2e2
commit cfdbad504c

View File

@ -332,13 +332,17 @@ class HuiMapCard extends LitElement implements LovelaceCard {
for (const entityId of Object.keys(history)) {
const entityStates = history[entityId];
if (entityStates?.length > 1) {
if (!entityStates?.length) {
continue;
}
// filter location data from states and remove all invalid locations
const points = entityStates.reduce(
(accumulator: HaMapPathPoint[], entityState) => {
const points: HaMapPathPoint[] = [];
for (const entityState of entityStates) {
const latitude = entityState.a.latitude;
const longitude = entityState.a.longitude;
if (latitude && longitude) {
if (!latitude || !longitude) {
continue;
}
const p = {} as HaMapPathPoint;
p.point = [latitude, longitude] as LatLngTuple;
const t = new Date(entityState.lu * 1000);
@ -351,20 +355,14 @@ class HuiMapCard extends LitElement implements LovelaceCard {
} else {
p.tooltip = formatTimeWeekday(t, this.hass.locale);
}
accumulator.push(p);
points.push(p);
}
return accumulator;
},
[]
) as HaMapPathPoint[];
paths.push({
points,
color: this._getColor(entityId),
gradualOpacity: 0.8,
});
}
}
return paths;
}
);