Skip to content

Commit 765179b

Browse files
bug fix
1 parent 8bc2223 commit 765179b

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

custom_components/precoscombustiveis/__init__.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .dgeg import DGEG
1111
from .const import DOMAIN
1212

13-
__version__ = "1.1.0"
13+
__version__ = "2.0.0"
1414
_LOGGER = logging.getLogger(__name__)
1515
_LOGGER.setLevel(logging.DEBUG)
1616

@@ -38,21 +38,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
3838
return True
3939

4040

41-
# async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
42-
# """Unload a config entry."""
43-
# unload_ok = await hass.config_entries.async_forward_entry_unload(
44-
# entry, DOMAIN)
45-
46-
# if unload_ok:
47-
# for unsub in hass.data[DOMAIN].listeners:
48-
# unsub()
49-
# hass.data.pop(DOMAIN)
50-
51-
# return True
52-
53-
# return False
54-
55-
5641
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
5742
"""Reload config entry."""
5843
# await async_unload_entry(hass, entry)

custom_components/precoscombustiveis/config_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Config flow for PrecosCombustiveis integration."""
2+
from __future__ import annotations
23
from typing import Any, Dict, Optional
34
import voluptuous as vol
4-
from __future__ import annotations
55

66
import logging
77
import async_timeout
@@ -56,7 +56,7 @@ async def async_step_user(
5656

5757
# Create selection list
5858
stations_list = {
59-
str(station["Id"]): f"{station['Nome']} - {station['Marca']} ({station['Morada']})"
59+
str(station["Id"]): f"{station['Distrito']}/{station['Localidade']}: {station['Marca']} - {station['Nome']}"
6060
for station in self._stations
6161
}
6262

custom_components/precoscombustiveis/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
CONF_STATION_ADDRESS = "station_address"
1515

1616
# API endpoints
17-
API_STATIONS_LIST = "https://precoscombustiveis.dgeg.gov.pt/api/PrecoComb/ListarDadosPostos"
17+
API_STATIONS_LIST = "https://precoscombustiveis.dgeg.gov.pt/api/PrecoComb/PesquisarPostos?qtdPorPagina=99999&pagina=1"
1818
API_URI_TEMPLATE = "https://precoscombustiveis.dgeg.gov.pt/api/PrecoComb/GetDadosPosto?id={}"

custom_components/precoscombustiveis/dgeg.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""API to DGEG."""
2-
from typing import List, Optional, Dict
2+
from typing import Dict, Optional
3+
from datetime import datetime
34
from aiohttp import ClientSession
45
import logging
56

@@ -82,16 +83,24 @@ class DGEG:
8283
def __init__(self, websession):
8384
self.websession = websession
8485

85-
async def list_stations(self) -> List[Dict]:
86+
async def list_stations(self) -> list[Dict]:
8687
"""Get list of all stations."""
8788
try:
88-
async with self._session.get(API_STATIONS_LIST) as response:
89-
if response.status == 200:
90-
stations = await response.json()
89+
async with self.websession.get(API_STATIONS_LIST) as res:
90+
if res.status == 200:
91+
json = await res.json()
9192
# Sort stations by name for better display
92-
return sorted(stations, key=lambda x: x.get('Nome', '').lower())
93+
return sorted(
94+
json['resultado'],
95+
key=lambda x: (
96+
x.get('Distrito', '').lower(),
97+
x.get('Localidade', '').lower(),
98+
x.get('Marca', '').lower(),
99+
x.get('Nome', '').lower()
100+
)
101+
)
93102
else:
94-
_LOGGER.error("Failed to fetch stations list. Status: %s", response.status)
103+
_LOGGER.error("Failed to fetch stations list. Status: %s", res.status)
95104
return []
96105
except Exception as ex:
97106
_LOGGER.error("Error fetching stations list: %s", str(ex))

custom_components/precoscombustiveis/strings.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
"config": {
44
"step": {
55
"user": {
6-
"title": "Add Credentials (user)",
7-
"description": "Some description (user)",
6+
"title": "Select Gas Station",
7+
"description": "Found {stations_count} stations. Please select your station from the list.",
88
"data": {
9-
"stationId": "StationId"
10-
},
11-
"data_description": {
12-
"stationId": "Identificador da Estação de Combustível"
9+
"station_select": "Gas Station"
1310
}
11+
},
12+
"confirm": {
13+
"title": "Confirm Station Selection",
14+
"description": "Do you want to add the following station?\n\nName: {name}\nBrand: {brand}\nAddress: {address}"
1415
}
1516
},
1617
"error": {
17-
"invalid_station": "Invalid StationId or gas station not found."
18+
"cannot_connect": "Failed to connect",
19+
"invalid_station": "Invalid station ID",
20+
"unknown": "Unexpected error"
1821
},
1922
"abort": {
20-
"already_configured": "Integration is already configured"
23+
"no_stations": "No stations found. Please try again later.",
24+
"station_not_found": "Selected station not found",
25+
"already_configured": "This station is already configured"
2126
}
2227
}
2328
}

0 commit comments

Comments
 (0)