Skip to content

Commit

Permalink
✨ Support latest version of vigieau api
Browse files Browse the repository at this point in the history
- url has changed
- returned data is an array of a 0,1 element instead of a hash

Fix #78
  • Loading branch information
kamaradclimber committed Jan 25, 2025
1 parent 7161db1 commit 05b1f00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions custom_components/vigieau/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ async def get_data(
and re.match("Aucune zone.+en vigueur", (await resp.json())["message"])
):
_LOGGER.debug(f"Vigieau replied with no restriction, faking data")
data = {"niveauGravite": "vigilance", "usages": [], "arrete": {}}
elif resp.status == 200 and (await resp.text()) == "":
data = [{"niveauGravite": "vigilance", "usages": [], "arrete": {}}]
elif resp.status == 200 and (await resp.json()) == []:
_LOGGER.debug(f"Vigieau replied with no data at all, faking data")
data = {"niveauGravite": "vigilance", "usages": [], "arrete": {}}
data = [{"niveauGravite": "vigilance", "usages": [], "arrete": {}}]
elif resp.status in range(200, 300):
data = await resp.json()
else:
raise VigieauAPIError(f"Failed fetching vigieau data", resp.text)
_LOGGER.debug(f"Data fetched from vigieau: {data}")
# enriching with numeric state value
data = data[0]
data["_numeric_state_value"] = {
"vigilance": 0,
"alerte": 1,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vigieau/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

NAME = "Vigieau"

VIGIEAU_API_URL = "https://api.vigieau.gouv.fr"
VIGIEAU_API_URL = "https://api.vigieau.beta.gouv.fr"

ZONE_TYPES = {
"SUP": "Eaux de surface",
Expand Down

0 comments on commit 05b1f00

Please sign in to comment.