1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 08:26:41 +01:00

Redact utility account id in Opower diagnostics (#165145)

This commit is contained in:
tronikos
2026-03-15 11:56:36 -07:00
committed by GitHub
parent a433a163a3
commit cc45201f2d
2 changed files with 47 additions and 43 deletions

View File

@@ -18,6 +18,7 @@ TO_REDACT = {
CONF_TOTP_SECRET,
# Title contains the username/email
"title",
"utility_account_id",
}
@@ -27,43 +28,46 @@ async def async_get_config_entry_diagnostics(
"""Return diagnostics for a config entry."""
coordinator = entry.runtime_data
return {
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
"data": {
account_id: {
"account": {
"utility_account_id": account.utility_account_id,
"meter_type": account.meter_type.name,
"read_resolution": (
account.read_resolution.name
if account.read_resolution
return async_redact_data(
{
"entry": entry.as_dict(),
"data": [
{
"account": {
"utility_account_id": account.utility_account_id,
"meter_type": account.meter_type.name,
"read_resolution": (
account.read_resolution.name
if account.read_resolution
else None
),
},
"forecast": (
{
"usage_to_date": forecast.usage_to_date,
"cost_to_date": forecast.cost_to_date,
"forecasted_usage": forecast.forecasted_usage,
"forecasted_cost": forecast.forecasted_cost,
"typical_usage": forecast.typical_usage,
"typical_cost": forecast.typical_cost,
"unit_of_measure": forecast.unit_of_measure.name,
"start_date": forecast.start_date.isoformat(),
"end_date": forecast.end_date.isoformat(),
"current_date": forecast.current_date.isoformat(),
}
if (forecast := data.forecast)
else None
),
},
"forecast": (
{
"usage_to_date": forecast.usage_to_date,
"cost_to_date": forecast.cost_to_date,
"forecasted_usage": forecast.forecasted_usage,
"forecasted_cost": forecast.forecasted_cost,
"typical_usage": forecast.typical_usage,
"typical_cost": forecast.typical_cost,
"unit_of_measure": forecast.unit_of_measure.name,
"start_date": forecast.start_date.isoformat(),
"end_date": forecast.end_date.isoformat(),
"current_date": forecast.current_date.isoformat(),
}
if (forecast := data.forecast)
else None
),
"last_changed": (
data.last_changed.isoformat() if data.last_changed else None
),
"last_updated": (
data.last_updated.isoformat() if data.last_updated else None
),
}
for account_id, data in coordinator.data.items()
for account in (data.account,)
"last_changed": (
data.last_changed.isoformat() if data.last_changed else None
),
"last_updated": (
data.last_updated.isoformat() if data.last_updated else None
),
}
for data in coordinator.data.values()
for account in (data.account,)
],
},
}
TO_REDACT,
)

View File

@@ -1,12 +1,12 @@
# serializer version: 1
# name: test_diagnostics
dict({
'data': dict({
'111111': dict({
'data': list([
dict({
'account': dict({
'meter_type': 'ELEC',
'read_resolution': 'HOUR',
'utility_account_id': '111111',
'utility_account_id': '**REDACTED**',
}),
'forecast': dict({
'cost_to_date': 20.0,
@@ -23,11 +23,11 @@
'last_changed': None,
'last_updated': '2026-03-07T23:00:00+00:00',
}),
'222222': dict({
dict({
'account': dict({
'meter_type': 'GAS',
'read_resolution': 'DAY',
'utility_account_id': '222222',
'utility_account_id': '**REDACTED**',
}),
'forecast': dict({
'cost_to_date': 15.0,
@@ -44,7 +44,7 @@
'last_changed': None,
'last_updated': '2026-03-07T23:00:00+00:00',
}),
}),
]),
'entry': dict({
'created_at': '2026-03-07T23:00:00+00:00',
'data': dict({