Normalize to kWh when handling WS energy/fossil_energy_consumption (#79649)

* Normalize to kWh when handling WS energy/fossil_energy_consumption

* Improve test
This commit is contained in:
Erik Montnemery 2022-10-05 16:27:08 +02:00 committed by GitHub
parent 312770dbac
commit 5d7756885b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -13,6 +13,7 @@ from typing import Any, cast
import voluptuous as vol
from homeassistant.components import recorder, websocket_api
from homeassistant.const import ENERGY_KILO_WATT_HOUR
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.integration_platform import (
async_process_integration_platforms,
@ -268,6 +269,7 @@ async def ws_get_fossil_energy_consumption(
statistic_ids,
"hour",
True,
{"energy": ENERGY_KILO_WATT_HOUR},
)
def _combine_sum_statistics(

View File

@ -814,25 +814,25 @@ async def test_fossil_energy_consumption(hass, hass_ws_client, recorder_mock):
"start": period1,
"last_reset": None,
"state": 0,
"sum": 20,
"sum": 20000,
},
{
"start": period2,
"last_reset": None,
"state": 1,
"sum": 30,
"sum": 30000,
},
{
"start": period3,
"last_reset": None,
"state": 2,
"sum": 40,
"sum": 40000,
},
{
"start": period4,
"last_reset": None,
"state": 3,
"sum": 50,
"sum": 50000,
},
)
external_energy_metadata_2 = {
@ -841,7 +841,7 @@ async def test_fossil_energy_consumption(hass, hass_ws_client, recorder_mock):
"name": "Total imported energy",
"source": "test",
"statistic_id": "test:total_energy_import_tariff_2",
"unit_of_measurement": "kWh",
"unit_of_measurement": "Wh",
}
external_co2_statistics = (
{