From 84a865b76a17c5fdd86e5264614c030b328f12f3 Mon Sep 17 00:00:00 2001 From: virtualdj Date: Sat, 2 Nov 2024 10:44:49 +0000 Subject: [PATCH] Fix errori mypy (compatibili con ruff) --- custom_components/pun_sensor/__init__.py | 2 +- custom_components/pun_sensor/config_flow.py | 2 +- custom_components/pun_sensor/sensor.py | 3 ++- custom_components/pun_sensor/utils.py | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/custom_components/pun_sensor/__init__.py b/custom_components/pun_sensor/__init__.py index 4a11abc..fdc93e0 100644 --- a/custom_components/pun_sensor/__init__.py +++ b/custom_components/pun_sensor/__init__.py @@ -32,7 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: # Carica le dipendenze di holidays in background per evitare errori nel log if AwesomeVersion(HA_VERSION) >= AwesomeVersion("2024.5.0"): with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES): - await hass.async_add_import_executor_job(holidays.IT) + await hass.async_add_import_executor_job(holidays.IT) # type: ignore[attr-defined] # Salva il coordinator nella configurazione coordinator = PUNDataUpdateCoordinator(hass, config) diff --git a/custom_components/pun_sensor/config_flow.py b/custom_components/pun_sensor/config_flow.py index 7a831a6..68654a3 100644 --- a/custom_components/pun_sensor/config_flow.py +++ b/custom_components/pun_sensor/config_flow.py @@ -19,7 +19,7 @@ def __init__(self, entry: config_entries.ConfigEntry) -> None: async def async_step_init(self, user_input=None) -> FlowResult: """Gestisce le opzioni.""" - errors = {} + errors: dict[str, str] | None = {} if user_input is not None: # Configurazione valida (validazione integrata nello schema) return self.async_create_entry(title="PUN", data=user_input) diff --git a/custom_components/pun_sensor/sensor.py b/custom_components/pun_sensor/sensor.py index 0e11bce..2da7b65 100644 --- a/custom_components/pun_sensor/sensor.py +++ b/custom_components/pun_sensor/sensor.py @@ -1,5 +1,6 @@ """Implementazione sensori di pun_sensor.""" +# pylint: disable=global-variable-undefined,overridden-final-method from typing import Any from awesomeversion.awesomeversion import AwesomeVersion @@ -47,7 +48,7 @@ async def async_setup_entry( ) # Crea i sensori dei valori del pun (legati al coordinator) - entities = [] + entities: list[SensorEntity] = [] entities.extend( PUNSensorEntity(coordinator, fascia) for fascia in PunValues().value ) diff --git a/custom_components/pun_sensor/utils.py b/custom_components/pun_sensor/utils.py index 202b913..bac1a88 100644 --- a/custom_components/pun_sensor/utils.py +++ b/custom_components/pun_sensor/utils.py @@ -4,7 +4,7 @@ import logging from zipfile import ZipFile -import defusedxml.ElementTree as et +import defusedxml.ElementTree as et # type: ignore[import-untyped] import holidays from .interfaces import Fascia, PunData @@ -41,7 +41,7 @@ def get_fascia(dataora: datetime) -> tuple[Fascia, datetime]: """Restituisce la fascia della data/ora indicata e la data del prossimo cambiamento.""" # Verifica se la data corrente è un giorno con festività - festivo = dataora in holidays.IT() + festivo = dataora in holidays.IT() # type: ignore[attr-defined] # Identifica la fascia corrente # F1 = lu-ve 8-19 @@ -135,7 +135,7 @@ def get_next_date( ) if feriale: - while (prossima in holidays.IT()) or (prossima.weekday() == 6): + while (prossima in holidays.IT()) or (prossima.weekday() == 6): # type: ignore[attr-defined] prossima += timedelta(days=1) return prossima @@ -149,7 +149,7 @@ def extract_xml(archive: ZipFile, pun_data: PunData) -> PunData: """ # Carica le festività - it_holidays = holidays.IT() + it_holidays = holidays.IT() # type: ignore[attr-defined] # Esamina ogni file XML nello ZIP (ordinandoli prima) for fn in sorted(archive.namelist()):