OptionsFlowHandler (Config Flow) No text labels?

I have successfully added an optional boolean setting. It even changes the associated setting correctly. However, I can’t see the respective text label. I only see the checkbox (see below screenshot). I already created a respective /translations/en.json file identical to strings.py (code below). I’m stumped. I don’t know what else to try.

image

config_flow.py:

import logging
import re

import aiohttp
import voluptuous as vol

from homeassistant import config_entries, core
from homeassistant.core import callback

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)
PROFILE_ID_URL = "https://store.steampowered.com/wishlist/profiles/{steam_profile_id}/"
WISHLIST_URL = "https://store.steampowered.com/wishlist/id/{username}/"
WISHLIST_JSON_URL = (
    "https://store.steampowered.com/wishlist/profiles/{user_id}/wishlistdata/"
)

ONE_PROFILE_ERROR_MSG = "Enter either a steam account name or a steam profile id."
DATA_SCHEMA = vol.Schema(
    {vol.Optional("steam_account_name"): str, vol.Optional("steam_profile_id"): str}
)


async def async_get_user_url(steam_account_name: str):
    """Get URL for a user's wishlist.

    :raises ValueError: If the steam account name appears to be invalid.
    """
    url = WISHLIST_URL.format(username=steam_account_name)
    async with aiohttp.ClientSession() as session:
        async with (session.get(url)) as resp:
            html = await resp.text()
            matches = re.findall(r"wishlist\\\/profiles\\\/([0-9]+)", html)
            if not matches:
                _LOGGER.error(
                    "Error setting up steam-wishlist component.  Did not find user id."
                )
                raise ValueError
            user_id = matches[0]
            return WISHLIST_JSON_URL.format(user_id=user_id)


async def async_check_profile_id_valid(steam_profile_id: str) -> bool:
    url = PROFILE_ID_URL.format(steam_profile_id=steam_profile_id)
    async with aiohttp.ClientSession() as session:
        async with (session.get(url)) as resp:
            if resp.status > 200:
                return False
    return True


class SteamWishlistConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Steam wishlist config flow."""

    async def async_step_user(self, user_input):
        """Handle a flow initialized by the user interface."""
        errors = {}
        if user_input is not None:
            if not user_input.get("steam_account_name") and not user_input.get(
                "steam_profile_id"
            ):
                errors["base"] = "missing"
            if user_input.get("steam_account_name"):
                # Validate the account name is valid.
                try:
                    user_url = await async_get_user_url(
                        user_input["steam_account_name"]
                    )
                except ValueError:
                    errors["base"] = "invalid_user"
            elif user_input.get("steam_profile_id"):
                # Validate the profile id is valid.
                if await async_check_profile_id_valid(user_input["steam_profile_id"]):
                    user_url = WISHLIST_JSON_URL.format(
                        user_id=user_input["steam_profile_id"]
                    )
                else:
                    errors["base"] = "invalid_profile_id"

            if not errors:
                return self.async_create_entry(
                    title="Steam Wishlist", data={"url": user_url}
                )

        return self.async_show_form(
            step_id="user", data_schema=DATA_SCHEMA, errors=errors,
        )

    @staticmethod
    @callback
    def async_get_options_flow(config_entry):
        return OptionsFlowHandler(config_entry)


class OptionsFlowHandler(config_entries.OptionsFlow):
    def __init__(self, config_entry):
        self.config_entry = config_entry

    async def async_step_init(self, user_input=None):
        if user_input is not None:
            return self.async_create_entry(title="", data=user_input)
        return self.async_show_form(
            step_id="init",
            data_schema=vol.Schema({
                vol.Required("show_all_wishlist_items", default=self.config_entry.options.get("show_all_wishlist_items", False)): bool
            }),
        )

strings.json:
en.json:

{
  "config": {
    "error": {
      "invalid_profile_id": "Could not find a Steam profile with the provided ID.",
      "invalid_user": "Could not find a steam account associated with the provided name or your profile is not public, see https://github.com/boralyl/steam-wishlist#pre-installation",
      "missing": "Enter your Steam account name or Steam profile ID."
    },
    "step": {
      "user": {
        "data": {
          "steam_account_name": "Steam account name",
          "steam_profile_id": "Steam profile id (e.g. 7656119383323351)"
        },
        "description": "Enter EITHER your Steam account name OR your Steam profile ID.",
        "title": "Setup"
      }
    }
  },
  "options": {
    "step": {
      "init": {
        "title": "Options",
        "description": "Configure your preferences."
      }
    },
    "data": {
      "show_all_wishlist_items": "Show all wishlist items"
    }
  }
}

data for the options needs to be inside the init step.
So your strings file are not as it’s supposed to be.

Edit: I also see more flaws e.g. Options are outside so I would perhaps recommend you to get a strings.json file somewhere from core repository and replace in it to ensure you get the syntax right.

1 Like

@gjohansson Thank you so much!!! You were right! The only issue was I had to move data for the options inside the init step. The rest was okay. I also had to make sure these changes were also replicated in the respective translations files.

{
  "config": {
    "error": {
      "invalid_profile_id": "Could not find a Steam profile with the provided ID.",
      "invalid_user": "Could not find a steam account associated with the provided name or your profile is not public, see https://github.com/boralyl/steam-wishlist#pre-installation",
      "missing": "Enter your Steam account name or Steam profile ID."
    },
    "step": {
      "user": {
        "title": "Setup",
        "description": "Enter EITHER your Steam account name OR your Steam profile ID.",
        "data": {
          "steam_account_name": "Steam account name",
          "steam_profile_id": "Steam profile id (e.g. 7656119383323351)"
        }
      }
    }
  },
  "options": {
    "step": {
      "init": {
        "title": "Options",
        "description": "Configure your preferences.",
        "data": {
          "show_all_wishlist_items": "Show all wishlist items"
        }
      }
    }
  }
}