Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mostra i risultati dei calcoli PUN nel log #68

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions custom_components/pun_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ async def update_listener(hass: HomeAssistant, config: ConfigEntry) -> None:
coordinator = hass.data[DOMAIN][config.entry_id]

# Aggiorna le impostazioni del coordinator dalle opzioni
if config.options[CONF_SCAN_HOUR] != coordinator.scan_hour:
if (CONF_SCAN_HOUR in config.options) and (
config.options[CONF_SCAN_HOUR] != coordinator.scan_hour
):
# Modificata l'ora di scansione nelle opzioni
coordinator.scan_hour = config.options[CONF_SCAN_HOUR]

Expand Down Expand Up @@ -107,7 +109,9 @@ async def update_listener(hass: HomeAssistant, config: ConfigEntry) -> None:
next_update_pun.strftime("%d/%m/%Y %H:%M:%S %z"),
)

if config.options[CONF_ACTUAL_DATA_ONLY] != coordinator.actual_data_only:
if (CONF_ACTUAL_DATA_ONLY in config.options) and (
config.options[CONF_ACTUAL_DATA_ONLY] != coordinator.actual_data_only
):
# Modificata impostazione 'Usa dati reali'
coordinator.actual_data_only = config.options[CONF_ACTUAL_DATA_ONLY]
_LOGGER.debug(
Expand Down
18 changes: 14 additions & 4 deletions custom_components/pun_sensor/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ def __init__(self, hass: HomeAssistant, config: ConfigEntry) -> None:

# Inizializza i valori di configurazione (dalle opzioni o dalla configurazione iniziale)
self.actual_data_only = config.options.get(
CONF_ACTUAL_DATA_ONLY, config.data[CONF_ACTUAL_DATA_ONLY]
CONF_ACTUAL_DATA_ONLY, config.data.get(CONF_ACTUAL_DATA_ONLY, False)
)
self.scan_hour = config.options.get(
CONF_SCAN_HOUR, config.data.get(CONF_SCAN_HOUR, 1)
)
self.scan_hour = config.options.get(CONF_SCAN_HOUR, config.data[CONF_SCAN_HOUR])

# Carica il minuto di esecuzione dalla configurazione (o lo crea se non esiste)
self.scan_minute = 0
Expand Down Expand Up @@ -211,10 +213,18 @@ async def _async_update_data(self):
# Logga i dati
_LOGGER.debug(
"Numero di dati: %s",
", ".join(str(len(i)) for i in self.pun_data.pun.values()),
", ".join(
str(f"{len(dati)} ({fascia.value})")
for fascia, dati in self.pun_data.pun.items()
if fascia != Fascia.F23
),
)
_LOGGER.debug(
"Valori PUN: %s", ", ".join(str(f) for f in self.pun_values.value.values())
"Valori PUN: %s",
", ".join(
f"{prezzo} ({fascia.value})"
for fascia, prezzo in self.pun_values.value.items()
),
)

async def update_fascia(self, now=None):
Expand Down