Skip to content

Commit

Permalink
Merge pull request #527 from uvjim/tidy-redact-in-config-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
uvjim authored Nov 30, 2024
2 parents 467fa2a + 60a1aff commit 27f10b8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions custom_components/linksys_velop/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
import asyncio
import contextlib
import logging
from collections.abc import Mapping
from enum import StrEnum, auto
from typing import Any

from homeassistant.components.diagnostics import async_redact_data
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant import config_entries, data_entry_flow
from homeassistant.components import ssdp
from homeassistant.components.device_tracker import CONF_CONSIDER_HOME
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.components.ssdp import SsdpServiceInfo
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -100,6 +101,13 @@ def _is_mesh_by_host(hass: HomeAssistant, host: str) -> LinksysVelopConfigEntry
return None


def _redact_for_display(data: Mapping) -> dict:
"""Redact information for display purposes."""

to_redact: set[str] = {'password'}
return async_redact_data(data, to_redact)


async def _async_build_schema_with_user_input(
step: str, user_input: dict, **kwargs
) -> vol.Schema:
Expand Down Expand Up @@ -343,8 +351,7 @@ async def _async_task_gather_details(self) -> None:

async def _async_task_login(self, details) -> None:
"""Test the credentials for the Mesh."""
display_details: dict[str, Any] = async_redact_data(details, ["password"])
_LOGGER.debug(self._log_formatter.format("entered, details: %s"), display_details)
_LOGGER.debug(self._log_formatter.format("entered, details: %s"), _redact_for_display(details))

_mesh = Mesh(**details, session=async_get_clientsession(hass=self.hass))
try:
Expand Down Expand Up @@ -427,8 +434,7 @@ async def async_step_gather_details(

async def async_step_login(self, user_input=None) -> data_entry_flow.FlowResult:
"""Initiate the credential test."""
display_details: dict[str, Any] = async_redact_data(user_input, ["password"])
_LOGGER.debug(self._log_formatter.format("entered, user_input: %s"), display_details)
_LOGGER.debug(self._log_formatter.format("entered, user_input: %s"), _redact_for_display(user_input))

if self.task_login is None:
_LOGGER.debug(self._log_formatter.format("creating credential test task"))
Expand Down Expand Up @@ -647,8 +653,7 @@ async def async_step_unignore(self, user_input=None) -> data_entry_flow.FlowResu

async def async_step_user(self, user_input=None) -> data_entry_flow.FlowResult:
"""Handle a flow initiated by the user."""
display_details: dict[str, Any] = async_redact_data(user_input, ["password"])
_LOGGER.debug(self._log_formatter.format("entered, user_input: %s"), display_details)
_LOGGER.debug(self._log_formatter.format("entered, user_input: %s"), _redact_for_display(user_input))

if user_input is not None:
self.task_login = None
Expand Down

0 comments on commit 27f10b8

Please sign in to comment.