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