From 0ee231ee85e525c916fab6aa137b365193a9ccb0 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 31 Jul 2023 12:16:46 +0200 Subject: [PATCH] Fix demo (#17438) * Fix demo Fix energy and notification in demo * Update config_entries.ts --- demo/src/stubs/config_entries.ts | 30 +++++++++++------------ demo/src/stubs/persistent_notification.ts | 26 +++++++++++--------- demo/src/stubs/recorder.ts | 6 +++-- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/demo/src/stubs/config_entries.ts b/demo/src/stubs/config_entries.ts index ddcdc1e43a..01a6da133e 100644 --- a/demo/src/stubs/config_entries.ts +++ b/demo/src/stubs/config_entries.ts @@ -1,20 +1,18 @@ import { MockHomeAssistant } from "../../../src/fake_data/provide_hass"; export const mockConfigEntries = (hass: MockHomeAssistant) => { - hass.mockWS("config_entries/get_matching", () => [ - { - entry_id: "co2signal", - domain: "co2signal", - title: "CO2 Signal", - source: "user", - state: "loaded", - supports_options: false, - supports_remove_device: false, - supports_unload: true, - pref_disable_new_entities: false, - pref_disable_polling: false, - disabled_by: null, - reason: null, - }, - ]); + hass.mockWS("config_entries/get", () => ({ + entry_id: "co2signal", + domain: "co2signal", + title: "Electricity Maps", + source: "user", + state: "loaded", + supports_options: false, + supports_remove_device: false, + supports_unload: true, + pref_disable_new_entities: false, + pref_disable_polling: false, + disabled_by: null, + reason: null, + })); }; diff --git a/demo/src/stubs/persistent_notification.ts b/demo/src/stubs/persistent_notification.ts index b5a2d7223d..04b46e5f97 100644 --- a/demo/src/stubs/persistent_notification.ts +++ b/demo/src/stubs/persistent_notification.ts @@ -1,16 +1,20 @@ -import { PersistentNotification } from "../../../src/data/persistent_notification"; +import { PersistentNotificationMessage } from "../../../src/data/persistent_notification"; import { MockHomeAssistant } from "../../../src/fake_data/provide_hass"; export const mockPersistentNotification = (hass: MockHomeAssistant) => { - hass.mockWS("persistent_notification/get", () => - Promise.resolve([ - { - created_at: new Date().toISOString(), - message: "There was motion detected in the backyard.", - notification_id: "demo-1", - title: "Motion Detected!", - status: "unread", + hass.mockWS("persistent_notification/subscribe", (_msg, _hass, onChange) => { + onChange!({ + type: "added", + notifications: { + "demo-1": { + created_at: new Date().toISOString(), + message: "There was motion detected in the backyard.", + notification_id: "demo-1", + title: "Motion Detected!", + status: "unread", + }, }, - ] as PersistentNotification[]) - ); + } as PersistentNotificationMessage); + return () => {}; + }); }; diff --git a/demo/src/stubs/recorder.ts b/demo/src/stubs/recorder.ts index 7ba78a805b..7cc9439ab0 100644 --- a/demo/src/stubs/recorder.ts +++ b/demo/src/stubs/recorder.ts @@ -72,6 +72,7 @@ const generateSumStatistics = ( min: null, max: null, last_reset: 0, + change: add, state: initValue + sum, sum, }); @@ -103,8 +104,8 @@ const generateCurvedStatistics = ( let half = false; const now = new Date(); while (end > currentDate && currentDate < now) { - const add = Math.random() * maxDiff; - sum += i * add; + const add = i * (Math.random() * maxDiff); + sum += add; statistics.push({ start: currentDate.getTime(), end: currentDate.getTime(), @@ -112,6 +113,7 @@ const generateCurvedStatistics = ( min: null, max: null, last_reset: 0, + change: add, state: initValue + sum, sum: metered ? sum : null, });