mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Add more info to the energy demo (#28316)
* Add more info to the energy demo * Also add battery power
This commit is contained in:
committed by
Paul Bottein
parent
f6f40c1679
commit
a1412e90fd
@@ -156,7 +156,9 @@ const createTestTranslation = () =>
|
|||||||
*/
|
*/
|
||||||
const createMasterTranslation = () =>
|
const createMasterTranslation = () =>
|
||||||
gulp
|
gulp
|
||||||
.src([EN_SRC, ...(mergeBackend ? [`${inBackendDir}/en.json`] : [])])
|
.src([EN_SRC, ...(mergeBackend ? [`${inBackendDir}/en.json`] : [])], {
|
||||||
|
allowEmpty: true,
|
||||||
|
})
|
||||||
.pipe(new CustomJSON(lokaliseTransform))
|
.pipe(new CustomJSON(lokaliseTransform))
|
||||||
.pipe(new MergeJSON("en"))
|
.pipe(new MergeJSON("en"))
|
||||||
.pipe(gulp.dest(workDir));
|
.pipe(gulp.dest(workDir));
|
||||||
|
|||||||
@@ -44,18 +44,24 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
power: [
|
||||||
|
{ stat_rate: "sensor.power_grid" },
|
||||||
|
{ stat_rate: "sensor.power_grid_return" },
|
||||||
|
],
|
||||||
cost_adjustment_day: 0,
|
cost_adjustment_day: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "solar",
|
type: "solar",
|
||||||
stat_energy_from: "sensor.solar_production",
|
stat_energy_from: "sensor.solar_production",
|
||||||
|
stat_rate: "sensor.power_solar",
|
||||||
config_entry_solar_forecast: ["solar_forecast"],
|
config_entry_solar_forecast: ["solar_forecast"],
|
||||||
},
|
},
|
||||||
/* {
|
{
|
||||||
type: "battery",
|
type: "battery",
|
||||||
stat_energy_from: "sensor.battery_output",
|
stat_energy_from: "sensor.battery_output",
|
||||||
stat_energy_to: "sensor.battery_input",
|
stat_energy_to: "sensor.battery_input",
|
||||||
}, */
|
stat_rate: "sensor.power_battery",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "gas",
|
type: "gas",
|
||||||
stat_energy_from: "sensor.energy_gas",
|
stat_energy_from: "sensor.energy_gas",
|
||||||
@@ -63,28 +69,48 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "water",
|
||||||
|
stat_energy_from: "sensor.energy_water",
|
||||||
|
stat_cost: "sensor.energy_water_cost",
|
||||||
|
entity_energy_price: null,
|
||||||
|
number_energy_price: null,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
device_consumption: [
|
device_consumption: [
|
||||||
{
|
{
|
||||||
stat_consumption: "sensor.energy_car",
|
stat_consumption: "sensor.energy_car",
|
||||||
|
stat_rate: "sensor.power_car",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_consumption: "sensor.energy_ac",
|
stat_consumption: "sensor.energy_ac",
|
||||||
|
stat_rate: "sensor.power_ac",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_consumption: "sensor.energy_washing_machine",
|
stat_consumption: "sensor.energy_washing_machine",
|
||||||
|
stat_rate: "sensor.power_washing_machine",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_consumption: "sensor.energy_dryer",
|
stat_consumption: "sensor.energy_dryer",
|
||||||
|
stat_rate: "sensor.power_dryer",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_consumption: "sensor.energy_heat_pump",
|
stat_consumption: "sensor.energy_heat_pump",
|
||||||
|
stat_rate: "sensor.power_heat_pump",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_consumption: "sensor.energy_boiler",
|
stat_consumption: "sensor.energy_boiler",
|
||||||
|
stat_rate: "sensor.power_boiler",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
device_consumption_water: [
|
||||||
|
{
|
||||||
|
stat_consumption: "sensor.water_kitchen",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
stat_consumption: "sensor.water_garden",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
device_consumption_water: [],
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
hass.mockWS(
|
hass.mockWS(
|
||||||
|
|||||||
@@ -154,6 +154,38 @@ export const energyEntities = () =>
|
|||||||
unit_of_measurement: "EUR",
|
unit_of_measurement: "EUR",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"sensor.power_grid": {
|
||||||
|
entity_id: "sensor.power_grid",
|
||||||
|
state: "500",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_grid_return": {
|
||||||
|
entity_id: "sensor.power_grid_return",
|
||||||
|
state: "-100",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_solar": {
|
||||||
|
entity_id: "sensor.power_solar",
|
||||||
|
state: "200",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_battery": {
|
||||||
|
entity_id: "sensor.power_battery",
|
||||||
|
state: "100",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
"sensor.energy_gas_cost": {
|
"sensor.energy_gas_cost": {
|
||||||
entity_id: "sensor.energy_gas_cost",
|
entity_id: "sensor.energy_gas_cost",
|
||||||
state: "2",
|
state: "2",
|
||||||
@@ -171,6 +203,15 @@ export const energyEntities = () =>
|
|||||||
unit_of_measurement: "m³",
|
unit_of_measurement: "m³",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"sensor.energy_water": {
|
||||||
|
entity_id: "sensor.energy_water",
|
||||||
|
state: "4000",
|
||||||
|
attributes: {
|
||||||
|
last_reset: "1970-01-01T00:00:00:00+00",
|
||||||
|
friendly_name: "Water",
|
||||||
|
unit_of_measurement: "L",
|
||||||
|
},
|
||||||
|
},
|
||||||
"sensor.energy_car": {
|
"sensor.energy_car": {
|
||||||
entity_id: "sensor.energy_car",
|
entity_id: "sensor.energy_car",
|
||||||
state: "4",
|
state: "4",
|
||||||
@@ -225,4 +266,58 @@ export const energyEntities = () =>
|
|||||||
unit_of_measurement: "kWh",
|
unit_of_measurement: "kWh",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"sensor.power_car": {
|
||||||
|
entity_id: "sensor.power_car",
|
||||||
|
state: "40",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
friendly_name: "Electric car",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_ac": {
|
||||||
|
entity_id: "sensor.power_ac",
|
||||||
|
state: "30",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
friendly_name: "Air conditioning",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_washing_machine": {
|
||||||
|
entity_id: "sensor.power_washing_machine",
|
||||||
|
state: "60",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
friendly_name: "Washing machine",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_dryer": {
|
||||||
|
entity_id: "sensor.power_dryer",
|
||||||
|
state: "55",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
friendly_name: "Dryer",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_heat_pump": {
|
||||||
|
entity_id: "sensor.power_heat_pump",
|
||||||
|
state: "60",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
friendly_name: "Heat pump",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sensor.power_boiler": {
|
||||||
|
entity_id: "sensor.power_boiler",
|
||||||
|
state: "70",
|
||||||
|
attributes: {
|
||||||
|
state_class: "measurement",
|
||||||
|
friendly_name: "Boiler",
|
||||||
|
unit_of_measurement: "W",
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,17 +17,15 @@ const generateMeanStatistics = (
|
|||||||
end: Date,
|
end: Date,
|
||||||
// eslint-disable-next-line default-param-last
|
// eslint-disable-next-line default-param-last
|
||||||
period: "5minute" | "hour" | "day" | "month" = "hour",
|
period: "5minute" | "hour" | "day" | "month" = "hour",
|
||||||
initValue: number,
|
|
||||||
maxDiff: number
|
maxDiff: number
|
||||||
): StatisticValue[] => {
|
): StatisticValue[] => {
|
||||||
const statistics: StatisticValue[] = [];
|
const statistics: StatisticValue[] = [];
|
||||||
let currentDate = new Date(start);
|
let currentDate = new Date(start);
|
||||||
currentDate.setMinutes(0, 0, 0);
|
currentDate.setMinutes(0, 0, 0);
|
||||||
let lastVal = initValue;
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
while (end > currentDate && currentDate < now) {
|
while (end > currentDate && currentDate < now) {
|
||||||
const delta = Math.random() * maxDiff;
|
const delta = Math.random() * maxDiff;
|
||||||
const mean = lastVal + delta;
|
const mean = delta;
|
||||||
statistics.push({
|
statistics.push({
|
||||||
start: currentDate.getTime(),
|
start: currentDate.getTime(),
|
||||||
end: currentDate.getTime(),
|
end: currentDate.getTime(),
|
||||||
@@ -38,7 +36,6 @@ const generateMeanStatistics = (
|
|||||||
state: mean,
|
state: mean,
|
||||||
sum: null,
|
sum: null,
|
||||||
});
|
});
|
||||||
lastVal = mean;
|
|
||||||
currentDate =
|
currentDate =
|
||||||
period === "day"
|
period === "day"
|
||||||
? addDays(currentDate, 1)
|
? addDays(currentDate, 1)
|
||||||
@@ -336,7 +333,6 @@ export const mockRecorder = (mockHass: MockHomeAssistant) => {
|
|||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
period,
|
period,
|
||||||
state,
|
|
||||||
state * (state > 80 ? 0.05 : 0.1)
|
state * (state > 80 ? 0.05 : 0.1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user