Skip to content

Fall back to daily granularity when the quarter-hour feed is empty (#361)#362

Open
Sgoettschkes wants to merge 1 commit into
DarwinsBuddy:mainfrom
Sgoettschkes:fallback-daily-when-quarter-hour-empty
Open

Fall back to daily granularity when the quarter-hour feed is empty (#361)#362
Sgoettschkes wants to merge 1 commit into
DarwinsBuddy:mainfrom
Sgoettschkes:fallback-daily-when-quarter-hour-empty

Conversation

@Sgoettschkes

Copy link
Copy Markdown

Problem

Fixes #361.

When a meter is opted into 15-minute values (Viertelstundenwerte), its role flips from V001 (daily) to V002 (quarter-hour), and WNSMSensor.granularity() follows the account into QUARTER_HOUR. WienerNetze can return an empty response for the V002 feed (einheit: null, values: []) even while the daily V001 feed is still populated. The importer then hits:

Unit of measurement is None! Aborting import...

and writes nothing, so the energy dashboard stops updating.

Change

Importer._import_statistics now fetches through a small helper _get_bewegungsdaten() that:

  1. requests the configured granularity (unchanged default behaviour), and
  2. if the quarter-hour response has no unit of measurement, retries once at daily (ValueType.DAY / V001).

So 15-minute data is used whenever WienerNetze serves it, and daily is used as a fallback otherwise. The existing unitOfMeasurement is None guard remains as a final backstop — if even the daily feed is empty, it aborts cleanly as before. Downstream aggregation is unchanged, since values are bucketed hourly regardless of source granularity.

The fallback only triggers when the requested granularity isn't already daily and the response has no unit, so a normal incremental cycle with no newly-finalised readings doesn't cause an extra API call.

Testing

Verified on a live Home Assistant instance whose meter was opted into 15-minute values and hitting #361: after the change the integration imports again — using quarter-hour data when WienerNetze serves it, and falling back to daily when the V002 feed comes back empty.

When a meter is opted into 15-minute values, the integration requests
quarter-hour (V002) bewegungsdaten. WienerNetze intermittently returns
an empty response (einheit: null) for V002 even though the daily (V001)
feed is populated, causing the importer to abort with
"Unit of measurement is None! Aborting import..." (DarwinsBuddy#361).

Try the configured granularity first and fall back to daily (V001) when
the quarter-hour response has no unit of measurement, so 15-minute data
is used when available and daily otherwise.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit of measurement is None

1 participant