mirror of
https://github.com/mx42/home-assistant-ecocito.git
synced 2026-01-14 13:59:50 +01:00
feat: add a method to dynamically fetch available collection type ids
This commit is contained in:
@@ -12,6 +12,7 @@ from bs4 import BeautifulSoup as bs # noqa: N813
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ECOCITO_COLLECTION_ENDPOINT,
|
ECOCITO_COLLECTION_ENDPOINT,
|
||||||
|
ECOCITO_COLLECTION_TYPE_ENDPOINT,
|
||||||
ECOCITO_DEFAULT_COLLECTION_TYPE,
|
ECOCITO_DEFAULT_COLLECTION_TYPE,
|
||||||
ECOCITO_GARBAGE_COLLECTION_TYPE,
|
ECOCITO_GARBAGE_COLLECTION_TYPE,
|
||||||
ECOCITO_LOGIN_ENDPOINT,
|
ECOCITO_LOGIN_ENDPOINT,
|
||||||
@@ -79,6 +80,28 @@ class EcocitoClient:
|
|||||||
except aiohttp.ClientError as e:
|
except aiohttp.ClientError as e:
|
||||||
raise EcocitoError(f"Authentication error: {e}") from e
|
raise EcocitoError(f"Authentication error: {e}") from e
|
||||||
|
|
||||||
|
async def get_collection_types(self) -> dict:
|
||||||
|
"""Return the mapping of collection type ID with their label."""
|
||||||
|
async with aiohttp.ClientSession(cookie_jar=self._cookies) as session:
|
||||||
|
try:
|
||||||
|
async with session.get(
|
||||||
|
ECOCITO_COLLECTION_TYPE_ENDPOINT.format(self._domain),
|
||||||
|
raise_for_status=True,
|
||||||
|
) as response:
|
||||||
|
content = await response.text()
|
||||||
|
html = bs(content, "html.parser")
|
||||||
|
try:
|
||||||
|
select = html.find("select", {"id": "Filtres_IdMatiere"})
|
||||||
|
return {
|
||||||
|
item.attrs["value"]: item.text
|
||||||
|
for item in select.find_all("option")
|
||||||
|
if "value" in item.attrs
|
||||||
|
}
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
await self._handle_error(content, e)
|
||||||
|
except aiohttp.ClientError as e:
|
||||||
|
raise EcocitoError(f"Unable to get collection types: {e}") from e
|
||||||
|
|
||||||
async def get_collection_events(
|
async def get_collection_events(
|
||||||
self, event_type: str, year: int
|
self, event_type: str, year: int
|
||||||
) -> list[CollectionEvent]:
|
) -> list[CollectionEvent]:
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ ECOCITO_RECYCLING_COLLECTION_TYPE = 16
|
|||||||
|
|
||||||
# Ecocito - Collection endpoint
|
# Ecocito - Collection endpoint
|
||||||
ECOCITO_COLLECTION_ENDPOINT = f"https://{ECOCITO_DOMAIN}/Usager/Collecte/GetCollecte"
|
ECOCITO_COLLECTION_ENDPOINT = f"https://{ECOCITO_DOMAIN}/Usager/Collecte/GetCollecte"
|
||||||
|
ECOCITO_COLLECTION_TYPE_ENDPOINT = f"https://{ECOCITO_DOMAIN}/Usager/Collecte"
|
||||||
|
|
||||||
# Ecocito - Waste deposit visits
|
# Ecocito - Waste deposit visits
|
||||||
ECOCITO_WASTE_DEPOSIT_ENDPOINT = f"https://{ECOCITO_DOMAIN}/Usager/Apport/GetApport"
|
ECOCITO_WASTE_DEPOSIT_ENDPOINT = f"https://{ECOCITO_DOMAIN}/Usager/Apport/GetApport"
|
||||||
|
|||||||
Reference in New Issue
Block a user