Skip to content

Commit

Permalink
Merge pull request #55 from BottlecapDave/develop
Browse files Browse the repository at this point in the history
diagnostic information
  • Loading branch information
BottlecapDave authored Jul 23, 2022
2 parents 61a6b8a + 576c93d commit 7edaef8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/octopus_energy/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ async def async_get_account(self, account_id):
headers = { "Authorization": f"JWT {token}" }
async with client.post(url, json=payload, headers=headers) as account_response:
account_response_body = await self.__async_read_response(account_response, url, None)

_LOGGER.debug(account_response_body)

if (account_response_body != None and "data" in account_response_body):
return {
"electricity_meter_points": list(map(lambda mp: {
Expand Down
42 changes: 42 additions & 0 deletions custom_components/octopus_energy/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Diagnostics support."""
import logging

from homeassistant.components.diagnostics import async_redact_data

from .const import (
DOMAIN,

DATA_ACCOUNT_ID,
DATA_CLIENT
)

_LOGGER = logging.getLogger(__name__)

async def async_get_device_diagnostics(hass, config_entry, device):
"""Return diagnostics for a device."""

client = hass.data[DOMAIN][DATA_CLIENT]

_LOGGER.info('Retrieving account details for diagnostics...')

account_info = await client.async_get_account(hass.data[DOMAIN][DATA_ACCOUNT_ID])

points_length = len(account_info["electricity_meter_points"])
if points_length > 0:
for point_index in range(points_length):
account_info["electricity_meter_points"][point_index] = async_redact_data(account_info["electricity_meter_points"][point_index], { "mpan" })
meters_length = len(account_info["electricity_meter_points"][point_index]["meters"])
for meter_index in range(meters_length):
account_info["electricity_meter_points"][point_index]["meters"][meter_index] = async_redact_data(account_info["electricity_meter_points"][point_index]["meters"][meter_index], { "serial_number" })

points_length = len(account_info["gas_meter_points"])
if points_length > 0:
for point_index in range(points_length):
account_info["gas_meter_points"][point_index] = async_redact_data(account_info["gas_meter_points"][point_index], { "mprn" })
meters_length = len(account_info["gas_meter_points"][point_index]["meters"])
for meter_index in range(meters_length):
account_info["gas_meter_points"][point_index]["meters"][meter_index] = async_redact_data(account_info["gas_meter_points"][point_index]["meters"][meter_index], { "serial_number" })

_LOGGER.info(f'Returning diagnostic details; {len(account_info["electricity_meter_points"])} electricity meter point(s), {len(account_info["gas_meter_points"])} gas meter point(s)')

return account_info

0 comments on commit 7edaef8

Please sign in to comment.