* Fix demo

Fix energy and notification in demo

* Update config_entries.ts
This commit is contained in:
Bram Kragten 2023-07-31 12:16:46 +02:00 committed by GitHub
parent b154607552
commit 0ee231ee85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 29 deletions

View File

@ -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,
}));
};

View File

@ -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 () => {};
});
};

View File

@ -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,
});