Skip to content

Commit

Permalink
Fix demo map panel (#21265)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Jul 3, 2024
1 parent 57e48e2 commit 522f664
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
50 changes: 50 additions & 0 deletions demo/src/stubs/entities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
import { convertEntities } from "../../../src/fake_data/entity";

export const mapEntities = () =>
convertEntities({
"zone.home": {
entity_id: "zone.home",
state: "zoning",
attributes: {
hidden: true,
latitude: 52.3631339,
longitude: 4.8903147,
radius: 200,
friendly_name: "Home",
icon: "hademo:home",
},
},
"zone.uva": {
entity_id: "zone.buckhead",
state: "zoning",
attributes: {
hidden: true,
radius: 400,
friendly_name: "UvA",
icon: "hademo:school",
latitude: 52.3558182,
longitude: 4.9535376,
},
},
"person.arsaboo": {
entity_id: "person.arsaboo",
state: "not_home",
attributes: {
radius: 50,
friendly_name: "Arsaboo",
latitude: 52.3579946,
longitude: 4.8664597,
entity_picture: "/assets/arsaboo/images/arsaboo.jpg",
},
},
"person.melody": {
entity_id: "person.melody",
state: "not_home",
attributes: {
radius: 50,
friendly_name: "Melody",
latitude: 52.3408927,
longitude: 4.8711073,
entity_picture: "/assets/arsaboo/images/melody.jpg",
},
},
});

export const energyEntities = () =>
convertEntities({
"sensor.grid_fossil_fuel_percentage": {
Expand Down
17 changes: 13 additions & 4 deletions demo/src/stubs/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ import {
} from "../configs/demo-configs";
import "../custom-cards/cast-demo-row";
import "../custom-cards/ha-demo-card";
import { mapEntities } from "./entities";

export const mockLovelace = (
hass: MockHomeAssistant,
localizePromise: Promise<LocalizeFunc>
) => {
hass.mockWS("lovelace/config", () =>
Promise.all([selectedDemoConfig, localizePromise]).then(
hass.mockWS("lovelace/config", ({ url_path }) => {
if (url_path === "map") {
hass.addEntities(mapEntities());
return {
strategy: {
type: "map",
},
};
}
return Promise.all([selectedDemoConfig, localizePromise]).then(
([config, localize]) => config.lovelace(localize)
)
);
);
});

hass.mockWS("lovelace/config/save", () => Promise.resolve());
hass.mockWS("lovelace/resources", () => Promise.resolve([]));
Expand Down
4 changes: 2 additions & 2 deletions src/fake_data/demo_panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export const demoPanels: Panels = {
// url_path: "history",
// },
map: {
component_name: "map",
component_name: "lovelace",
icon: "hass:tooltip-account",
title: "map",
config: null,
config: { mode: "storage" },
url_path: "map",
},
energy: {
Expand Down

0 comments on commit 522f664

Please sign in to comment.