Skip to content

Commit

Permalink
__EN__
Browse files Browse the repository at this point in the history
fix date: start date and end date default
bug fix: in some leagues, for example MSL there are two separate rankings, now it is possible to choose the ranking.

NOTE: the choice must always be made even with only 1 ranking, so it is necessary to reconfigure the ranking tab

__IT__
fix date: ora le date sono piu ampie di defaul
fix bug: in alcuni capionati, esempio MSL ci sono due classifiche separate, ora è possibile scegliere la classifica.

NOTA: la scelta va sempre fatta anche con 1 sola classifica, quindi è necessario riconfigurare la scheda classifica
  • Loading branch information
Bobsilvio committed Feb 21, 2025
1 parent d99d895 commit 5235261
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 42 deletions.
9 changes: 7 additions & 2 deletions custom_components/calcio_live/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import aiohttp
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -246,8 +247,12 @@ async def async_step_init(self, user_input=None):
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

start_date = self.config_entry.options.get("start_date", datetime.now().strftime("%Y-%m-%d"))
end_date = self.config_entry.options.get("end_date", (datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"))
today = datetime.now()

start_date = self.config_entry.options.get("start_date", (today - relativedelta(months=3)).strftime("%Y-%m-%d"))

end_date = self.config_entry.options.get("end_date", (today + relativedelta(months=4)).strftime("%Y-%m-%d"))


return self.async_show_form(
step_id="init",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/calcio_live/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/Bobsilvio/calcio_live/issues",
"requirements": ["arrow", "aiofiles", "pytz==2023.3"],
"version": "2.1.6"
"version": "2.1.7"
}
10 changes: 7 additions & 3 deletions custom_components/calcio_live/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ def __init__(self, hass, name, code, sensor_type=None, scan_interval=timedelta(m
self._attributes = {}
self._config_entry_id = config_entry_id
self._team_name = team_name
self._start_date = datetime.strptime(start_date, "%Y-%m-%d") if start_date else datetime.now()
self._end_date = datetime.strptime(end_date, "%Y-%m-%d") if end_date else datetime.now() + timedelta(days=30)
today = datetime.now()
self._start_date = (today - relativedelta(months=3)).strftime("%Y-%m-%d") if not start_date else start_date
self._end_date = (today + relativedelta(months=4)).strftime("%Y-%m-%d") if not end_date else end_date
self._start_date = datetime.strptime(self._start_date, "%Y-%m-%d")
self._end_date = datetime.strptime(self._end_date, "%Y-%m-%d")

self._request_count = 0
self._last_request_time = None

Expand All @@ -106,7 +110,7 @@ def extra_state_attributes(self):
"request_count": self._request_count,
"last_request_time": self._last_request_time,
"start_date": self._start_date.strftime("%Y-%m-%d"),
"end_date": self._end_date.strftime("%Y-%m-%d")
"end_date": self._end_date.strftime("%Y-%m-%d"),
}

@property
Expand Down
76 changes: 40 additions & 36 deletions custom_components/calcio_live/sensori/classifica.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,61 @@

def classifica_data(data):
try:
standings_data = data.get("children", [])[0].get("standings", {}).get("entries", [])
standings = []

for index, entry in enumerate(standings_data, start=1):
team = entry.get("team", {})
stats = {stat['name']: stat['displayValue'] for stat in entry.get("stats", [])}

rank = entry.get("note", {}).get("rank", index)

team_data = {
"rank": rank,
"team_id": team.get("id"),
"team_name": team.get("displayName"),
"team_logo": team.get("logos", [])[0].get("href"),
"points": stats.get("points", "N/A"),
"games_played": stats.get("gamesPlayed", "N/A"),
"wins": stats.get("wins", "N/A"),
"draws": stats.get("ties", "N/A"),
"losses": stats.get("losses", "N/A"),
"goals_for": stats.get("pointsFor", "N/A"),
"goals_against": stats.get("pointsAgainst", "N/A"),
"goal_difference": stats.get("pointDifferential", "N/A")
}
standings.append(team_data)
standings_list = []

for child in data.get("children", []):
standings_data = child.get("standings", {}).get("entries", [])
standings = []

for index, entry in enumerate(standings_data, start=1):
team = entry.get("team", {})
stats = {stat['name']: stat['displayValue'] for stat in entry.get("stats", [])}

rank = entry.get("note", {}).get("rank", index)

team_data = {
"rank": rank,
"team_id": team.get("id"),
"team_name": team.get("displayName"),
"team_logo": team.get("logos", [])[0].get("href"),
"points": stats.get("points", "N/A"),
"games_played": stats.get("gamesPlayed", "N/A"),
"wins": stats.get("wins", "N/A"),
"draws": stats.get("ties", "N/A"),
"losses": stats.get("losses", "N/A"),
"goals_for": stats.get("pointsFor", "N/A"),
"goals_against": stats.get("pointsAgainst", "N/A"),
"goal_difference": stats.get("pointDifferential", "N/A")
}
standings.append(team_data)

full_table_link = child.get("standings", {}).get("links", [])[0].get("href", "N/A") if child.get("standings", {}).get("links") else "N/A"

standings_list.append({
"name": child.get("name", "Unknown"),
"standings": standings,
"full_table_link": full_table_link
})

seasons_data = data.get("seasons", [])
current_season = None
for season in seasons_data:
if season.get("year") == 2024:
current_season = season
break
current_season = next((s for s in seasons_data if s.get("year") == 2024), None)

season_display_name = current_season.get("displayName", "N/A") if current_season else "N/A"
season_start_raw = current_season.get("startDate", "N/A")
season_end_raw = current_season.get("endDate", "N/A")

season_start = _parse_date(season_start_raw)
season_end = _parse_date(season_end_raw)
season_start = _parse_date(current_season.get("startDate", "N/A")) if current_season else None
season_end = _parse_date(current_season.get("endDate", "N/A")) if current_season else None

return {
"standings": standings,
"season": season_display_name,
"season_start": season_start,
"season_end": season_end,
"full_table_link": data.get("children", [])[0].get("standings", {}).get("links", [])[0].get("href", "N/A")
"standings_groups": standings_list # Mantiene le classifiche separate
}
except Exception as e:
_LOGGER.error(f"Errore nel processare i dati della classifica: {e}")
return {}



def _parse_date(date_str):
try:
parsed_date = parser.isoparse(date_str)
Expand Down

0 comments on commit 5235261

Please sign in to comment.