Skip to content

Commit c6d8b5f

Browse files
committed
Refactor config flow type hints and ensure JSON files end with a newline
1 parent d051557 commit c6d8b5f

13 files changed

Lines changed: 35 additions & 25 deletions

custom_components/feedparser/config_flow.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
from collections.abc import Mapping
66
from datetime import timedelta
7-
from typing import Any
7+
from typing import Any, cast
88

99
import requests
1010
import voluptuous as vol
1111
from homeassistant.config_entries import (
1212
ConfigEntry,
1313
ConfigFlow,
14+
FlowResult,
1415
OptionsFlow,
1516
)
1617
from homeassistant.const import CONF_NAME
@@ -173,7 +174,7 @@ def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
173174
async def async_step_user(
174175
self,
175176
user_input: Mapping[str, object] | None = None,
176-
) -> object:
177+
) -> FlowResult:
177178
"""Handle the initial step."""
178179
errors: dict[str, str] = {}
179180

@@ -220,20 +221,26 @@ async def async_step_user(
220221
str(user_input[CONF_EXCLUSIONS]).strip(),
221222
),
222223
}
223-
return self.async_create_entry(
224-
title=data[CONF_NAME],
225-
data=data,
226-
options=options,
224+
return cast(
225+
"FlowResult",
226+
self.async_create_entry(
227+
title=data[CONF_NAME],
228+
data=data,
229+
options=options,
230+
),
227231
)
228232

229233
data_schema = _schema_with_defaults(
230234
include_feed_identity=True,
231235
)
232236

233-
return self.async_show_form(
234-
step_id="user",
235-
data_schema=data_schema,
236-
errors=errors,
237+
return cast(
238+
"FlowResult",
239+
self.async_show_form(
240+
step_id="user",
241+
data_schema=data_schema,
242+
errors=errors,
243+
),
237244
)
238245

239246
@staticmethod
@@ -257,7 +264,7 @@ def __init__(self, config_entry: ConfigEntry) -> None:
257264
async def async_step_init(
258265
self,
259266
user_input: Mapping[str, object] | None = None,
260-
) -> object:
267+
) -> FlowResult:
261268
"""Manage Feedparser options."""
262269
if user_input is not None:
263270
options = {
@@ -269,7 +276,7 @@ async def async_step_init(
269276
CONF_INCLUSIONS: _split_csv(str(user_input[CONF_INCLUSIONS]).strip()),
270277
CONF_EXCLUSIONS: _split_csv(str(user_input[CONF_EXCLUSIONS]).strip()),
271278
}
272-
return self.async_create_entry(title="", data=options)
279+
return cast("FlowResult", self.async_create_entry(title="", data=options))
273280

274281
merged = {**self._config_entry.data, **self._config_entry.options}
275282
data_schema = _schema_with_defaults(
@@ -289,4 +296,7 @@ async def async_step_init(
289296
inclusions=_join_csv(merged.get(CONF_INCLUSIONS, [])),
290297
exclusions=_join_csv(merged.get(CONF_EXCLUSIONS, [])),
291298
)
292-
return self.async_show_form(step_id="init", data_schema=data_schema)
299+
return cast(
300+
"FlowResult",
301+
self.async_show_form(step_id="init", data_schema=data_schema),
302+
)

tests/data/CTK.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
}
1111
},
1212
"download_date": "2024-02-23T21:08:09.183484+00:00"
13-
}
13+
}

tests/data/alle_meldungen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"remove_summary_image": true
1717
},
1818
"download_date": "2024-02-23T21:08:09.183484+00:00"
19-
}
19+
}

tests/data/anp_nieuws.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
]
1515
},
1616
"download_date": "2024-02-23T21:08:09.183484+00:00"
17-
}
17+
}

tests/data/api_met_no_metalerts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
]
1313
},
1414
"download_date": "2024-02-23T21:08:09.183484+00:00"
15-
}
15+
}

tests/data/bbc_europe.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
"date_format": "%a, %d %b %Y %H:%M:%S %z"
1010
},
1111
"download_date": "2024-02-25T21:09:08.348208+00:00"
12-
}
12+
}

tests/data/buienradar_nl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
"date_format": "%Y-%m-%d %H:%M:%S.%f"
1010
},
1111
"download_date": "2024-02-23T21:08:09.183484+00:00"
12-
}
12+
}

tests/data/ct24.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"feed_url": "https://ct24.ceskatelevize.cz/rss/hlavni-zpravy"
66
},
77
"download_date": "2023-07-30T13:48:50.563494"
8-
}
8+
}

tests/data/nu_nl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"feed_url": "https://www.nu.nl/rss"
66
},
77
"download_date": "2023-07-30T13:48:50.563494"
8-
}
8+
}

tests/data/nu_nl_algemeen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"feed_url": "https://www.nu.nl/rss/Algemeen"
66
},
77
"download_date": "2023-07-30T13:48:50.563494"
8-
}
8+
}

0 commit comments

Comments
 (0)