Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type hints in growatt_server config flow #124901

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions homeassistant/components/growatt_server/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class GrowattServerConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

api: growattServer.GrowattApi

def __init__(self) -> None:
"""Initialise growatt server flow."""
self.api: growattServer.GrowattApi | None = None
self.user_id = None
self.data: dict[str, Any] = {}

Expand Down Expand Up @@ -70,7 +71,9 @@ async def async_step_user(
self.data = user_input
return await self.async_step_plant()

async def async_step_plant(self, user_input=None):
async def async_step_plant(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle adding a "plant" to Home Assistant."""
plant_info = await self.hass.async_add_executor_job(
self.api.plant_list, self.user_id
Expand All @@ -86,7 +89,8 @@ async def async_step_plant(self, user_input=None):

return self.async_show_form(step_id="plant", data_schema=data_schema)

if user_input is None and len(plant_info["data"]) == 1:
if user_input is None:
# single plant => mark it as selected
Comment on lines +92 to +93
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous logic confused mypy, as it felt that user_input could still be None.
Since there are two guards above for empty data and for multiple data, I think we can remove the check here.

user_input = {CONF_PLANT_ID: plant_info["data"][0]["plantId"]}

user_input[CONF_NAME] = plants[user_input[CONF_PLANT_ID]]
Expand Down