ics allow custom howtos per ICS source

This commit is contained in:
5ila5
2024-07-29 16:07:04 +02:00
committed by 5ila5
parent f8eb7d551f
commit edd226b0fc
5 changed files with 3467 additions and 1773 deletions

View File

@@ -285,6 +285,7 @@ class SourceDict(TypedDict):
title: str
module: str
default_params: dict[str, Any]
id: str
class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
@@ -302,21 +303,24 @@ class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call
super().__init__(*args, **kwargs)
self._sources = self._get_source_list()
self._options: dict = {}
for _, sources in self._sources.items():
async def args_method(args_input):
return await self.async_step_args(args_input)
async def reconfigure_method(args_input):
return await self.async_step_reconfigure(args_input)
for sources in self._sources.values():
for source in sources:
async def args_method(args_input):
return await self.async_step_args(args_input)
setattr(
self,
f"async_step_args_{source['module']}",
f"async_step_args_{source['id']}",
args_method,
)
setattr(
self,
f"async_step_reconfigure_{source['module']}",
args_method,
f"async_step_reconfigure_{source['id']}",
reconfigure_method,
)
# Get source list from JSON
@@ -355,7 +359,7 @@ class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call
sources = self._sources[self._country]
sources_options = [SelectOptionDict(value="", label="")] + [
SelectOptionDict(
value=f"{x['module']}\t({x['title']})",
value=f"{x['module']}\t({x['title']})\t{x['id']}",
label=f"{x['title']} ({x['module']})",
)
for x in sources
@@ -385,11 +389,14 @@ class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call
errors[CONF_SOURCE_NAME] = "invalid_source"
else:
self._source = info[CONF_SOURCE_NAME].split("\t")[0]
self._id = info[CONF_SOURCE_NAME].split("\t")[2]
self._extra_info_default_params = next(
(
x["default_params"]
for x in self._sources[self._country]
if f"{x['module']}\t({x['title']})" == info[CONF_SOURCE_NAME]
if info[CONF_SOURCE_NAME].startswith(
f"{x['module']}\t({x['title']})"
)
),
{},
)
@@ -656,7 +663,7 @@ class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call
setattr(
self,
f"async_step_args_{self._source}",
f"async_step_args_{self._id}",
args_method,
)
return await self.async_step_args()
@@ -692,7 +699,7 @@ class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call
self.async_show_form(step_id="options")
return await self.async_step_flow_type()
return self.async_show_form(
step_id=f"args_{self._source}",
step_id=f"args_{self._id}",
data_schema=schema,
errors=errors,
description_placeholders=description_placeholders,

File diff suppressed because it is too large Load Diff

View File

@@ -9922,32 +9922,6 @@
},
"data_description": {}
},
"args_awg_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Für Details siehe die Quellen Dokumentation.",
"data": {
"calendar_title": "Kalender Titel",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_awg_de": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Für Details siehe die Quellen Dokumentation.",
"data": {
"calendar_title": "Kalender Titel",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {}
},
"args_sammelkalender_ch": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Für Details siehe die Quellen Dokumentation.",
@@ -9974,6 +9948,32 @@
},
"data_description": {}
},
"args_awg_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Für Details siehe die Quellen Dokumentation.",
"data": {
"calendar_title": "Kalender Titel",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_awg_de": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Für Details siehe die Quellen Dokumentation.",
"data": {
"calendar_title": "Kalender Titel",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {}
},
"args_winterthur_ch": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Für Details siehe die Quellen Dokumentation.",

View File

@@ -9922,32 +9922,6 @@
},
"data_description": {}
},
"args_awg_de": {
"title": "Configure Source",
"description": "Configure your service provider. For details see the source documentation.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used."
}
},
"reconfigure_awg_de": {
"title": "Reconfigure Source",
"description": "Configure your service provider. For details see the source documentation.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {}
},
"args_sammelkalender_ch": {
"title": "Configure Source",
"description": "Configure your service provider. For details see the source documentation.",
@@ -9974,6 +9948,32 @@
},
"data_description": {}
},
"args_awg_de": {
"title": "Configure Source",
"description": "Configure your service provider. For details see the source documentation.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used."
}
},
"reconfigure_awg_de": {
"title": "Reconfigure Source",
"description": "Configure your service provider. For details see the source documentation.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"street": "Street",
"hnr": "Hnr",
"addition": "Addition"
},
"data_description": {}
},
"args_winterthur_ch": {
"title": "Configure Source",
"description": "Configure your service provider. For details see the source documentation.",

View File

@@ -156,7 +156,6 @@ class ExtraInfoDict(TypedDict):
url: NotRequired[str]
country: NotRequired[str]
default_params: NotRequired[dict[str, Any]]
how_to_get_arguments_description: NotRequired[dict[str, str]]
class IcsSourceData(TypedDict):
@@ -293,7 +292,7 @@ def browse_sources() -> list[SourceInfo]:
country=e.get("country", country),
params=params,
extra_info_default_params=e.get("default_params", {}),
custom_howto=e.get("how_to_get_arguments_description", howto),
custom_howto=howto,
)
)
@@ -361,9 +360,7 @@ def browse_ics_yaml() -> list[SourceInfo]:
country=e.get("country", country),
params=[],
extra_info_default_params=data.get("default_params", {}),
custom_howto=e.get(
"how_to_get_arguments_description", howto
),
custom_howto=howto,
)
)
@@ -461,21 +458,17 @@ def update_sources_json(countries: dict[str, list[SourceInfo]]) -> None:
countries[country],
key=lambda e: (e.title.lower(), beautify_url(e.url), e.filename),
):
if e.module is None: # ICS source
output[country].append(
{
"title": e.title,
"module": "ics",
"default_params": e.extra_info_default_params,
}
)
continue
module = e.module if e.module is not None else "ics"
id = e.filename.split("/")[-1].removesuffix(".md")
if id != module:
id = f"{module}_{id}"
output[country].append(
{
"title": e.title,
"module": e.module,
"module": module,
"default_params": e.extra_info_default_params,
"id": id,
}
)
with open(