Fix sensor displaying unknown when getting readings from heat meters in ista EcoTrend (#147741)

This commit is contained in:
Manu 2025-06-30 20:11:46 +02:00 committed by Franck Nijhof
parent c771f5fe1e
commit 3c7c9176d2
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952
5 changed files with 64 additions and 14 deletions

View File

@ -108,22 +108,22 @@ def get_statistics(
if monthly_consumptions := get_consumptions(data, value_type):
return [
{
"value": as_number(
get_values_by_type(
consumptions=consumptions,
consumption_type=consumption_type,
).get(
"additionalValue"
if value_type == IstaValueType.ENERGY
else "value"
)
),
"value": as_number(value),
"date": consumptions["date"],
}
for consumptions in monthly_consumptions
if get_values_by_type(
consumptions=consumptions,
consumption_type=consumption_type,
).get("additionalValue" if value_type == IstaValueType.ENERGY else "value")
if (
value := (
consumption := get_values_by_type(
consumptions=consumptions,
consumption_type=consumption_type,
)
).get(
"additionalValue"
if value_type == IstaValueType.ENERGY
and consumption.get("additionalValue") is not None
else "value"
)
)
]
return None

View File

@ -96,12 +96,16 @@ def get_consumption_data(obj_uuid: str | None = None) -> dict[str, Any]:
{
"type": "heating",
"value": "35",
"unit": "Einheiten",
"additionalValue": "38,0",
"additionalUnit": "kWh",
},
{
"type": "warmwater",
"value": "1,0",
"unit": "",
"additionalValue": "57,0",
"additionalUnit": "kWh",
},
{
"type": "water",
@ -115,16 +119,21 @@ def get_consumption_data(obj_uuid: str | None = None) -> dict[str, Any]:
{
"type": "heating",
"value": "104",
"unit": "Einheiten",
"additionalValue": "113,0",
"additionalUnit": "kWh",
},
{
"type": "warmwater",
"value": "1,1",
"unit": "",
"additionalValue": "61,1",
"additionalUnit": "kWh",
},
{
"type": "water",
"value": "6,8",
"unit": "",
},
],
},
@ -200,16 +209,21 @@ def extend_statistics(obj_uuid: str | None = None) -> dict[str, Any]:
{
"type": "heating",
"value": "9000",
"unit": "Einheiten",
"additionalValue": "9000,0",
"additionalUnit": "kWh",
},
{
"type": "warmwater",
"value": "9999,0",
"unit": "",
"additionalValue": "90000,0",
"additionalUnit": "kWh",
},
{
"type": "water",
"value": "9000,0",
"unit": "",
},
],
},

View File

@ -12,13 +12,17 @@
}),
'readings': list([
dict({
'additionalUnit': 'kWh',
'additionalValue': '38,0',
'type': 'heating',
'unit': 'Einheiten',
'value': '35',
}),
dict({
'additionalUnit': 'kWh',
'additionalValue': '57,0',
'type': 'warmwater',
'unit': 'm³',
'value': '1,0',
}),
dict({
@ -34,17 +38,22 @@
}),
'readings': list([
dict({
'additionalUnit': 'kWh',
'additionalValue': '113,0',
'type': 'heating',
'unit': 'Einheiten',
'value': '104',
}),
dict({
'additionalUnit': 'kWh',
'additionalValue': '61,1',
'type': 'warmwater',
'unit': 'm³',
'value': '1,1',
}),
dict({
'type': 'water',
'unit': 'm³',
'value': '6,8',
}),
]),
@ -103,13 +112,17 @@
}),
'readings': list([
dict({
'additionalUnit': 'kWh',
'additionalValue': '38,0',
'type': 'heating',
'unit': 'Einheiten',
'value': '35',
}),
dict({
'additionalUnit': 'kWh',
'additionalValue': '57,0',
'type': 'warmwater',
'unit': 'm³',
'value': '1,0',
}),
dict({
@ -125,17 +138,22 @@
}),
'readings': list([
dict({
'additionalUnit': 'kWh',
'additionalValue': '113,0',
'type': 'heating',
'unit': 'Einheiten',
'value': '104',
}),
dict({
'additionalUnit': 'kWh',
'additionalValue': '61,1',
'type': 'warmwater',
'unit': 'm³',
'value': '1,1',
}),
dict({
'type': 'water',
'unit': 'm³',
'value': '6,8',
}),
]),

View File

@ -85,6 +85,14 @@
# ---
# name: test_get_statistics.7
list([
dict({
'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc),
'value': 6.8,
}),
dict({
'date': datetime.datetime(2024, 5, 31, 0, 0, tzinfo=datetime.timezone.utc),
'value': 5.0,
}),
])
# ---
# name: test_get_statistics.8
@ -101,21 +109,26 @@
# ---
# name: test_get_values_by_type
dict({
'additionalUnit': 'kWh',
'additionalValue': '38,0',
'type': 'heating',
'unit': 'Einheiten',
'value': '35',
})
# ---
# name: test_get_values_by_type.1
dict({
'additionalUnit': 'kWh',
'additionalValue': '57,0',
'type': 'warmwater',
'unit': 'm³',
'value': '1,0',
})
# ---
# name: test_get_values_by_type.2
dict({
'type': 'water',
'unit': 'm³',
'value': '5,0',
})
# ---

View File

@ -41,16 +41,21 @@ def test_get_values_by_type(snapshot: SnapshotAssertion) -> None:
{
"type": "heating",
"value": "35",
"unit": "Einheiten",
"additionalValue": "38,0",
"additionalUnit": "kWh",
},
{
"type": "warmwater",
"value": "1,0",
"unit": "",
"additionalValue": "57,0",
"additionalUnit": "kWh",
},
{
"type": "water",
"value": "5,0",
"unit": "",
},
],
}