diff --git a/homeassistant/components/automation/logbook.py b/homeassistant/components/automation/logbook.py index 901972595e4ddf068136bc453ac6b34aea677188..86fb797ea311bd3eee981429bcd551584046a406 100644 --- a/homeassistant/components/automation/logbook.py +++ b/homeassistant/components/automation/logbook.py @@ -8,11 +8,11 @@ from .const import DOMAIN @callback -def async_describe_events(hass: HomeAssistant, async_describe_event): # type: ignore +def async_describe_events(hass: HomeAssistant, async_describe_event): # type: ignore[no-untyped-def] """Describe logbook events.""" @callback - def async_describe_logbook_event(event: LazyEventPartialState): # type: ignore + def async_describe_logbook_event(event: LazyEventPartialState): # type: ignore[no-untyped-def] """Describe a logbook event.""" data = event.data message = "has been triggered" diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index f374ebaeb38126cdcd48b8cd5d7a9e19a931c5e8..3414f13268ff6780ad7690ac82f73719b90591ea 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -397,7 +397,10 @@ class SensorEntity(Entity): # Received a date value if value is not None and device_class == DEVICE_CLASS_DATE: try: - return value.isoformat() # type: ignore + # We cast the value, to avoid using isinstance, but satisfy + # typechecking. The errors are guarded in this try. + value = cast(date, value) + return value.isoformat() except (AttributeError, TypeError) as err: raise ValueError( f"Invalid date: {self.entity_id} has a date device class " @@ -434,7 +437,7 @@ class SensorEntity(Entity): prec = len(value_s) - value_s.index(".") - 1 if "." in value_s else 0 # Suppress ValueError (Could not convert sensor_value to float) with suppress(ValueError): - temp = units.temperature(float(value), unit_of_measurement) # type: ignore + temp = units.temperature(float(value), unit_of_measurement) # type: ignore[arg-type] value = round(temp) if prec == 0 else round(temp, prec) return value diff --git a/homeassistant/helpers/collection.py b/homeassistant/helpers/collection.py index f6f9c968f104b2367ad9969ad914b715d041378b..9017c60c23fabb29ca228abd9d0f0b743c9301a9 100644 --- a/homeassistant/helpers/collection.py +++ b/homeassistant/helpers/collection.py @@ -330,7 +330,7 @@ def sync_entity_lifecycle( create_entity: Callable[[dict], Entity], ) -> None: """Map a collection to an entity component.""" - entities = {} + entities: dict[str, Entity] = {} ent_reg = entity_registry.async_get(hass) async def _add_entity(change_set: CollectionChangeSet) -> Entity: @@ -348,7 +348,7 @@ def sync_entity_lifecycle( entities.pop(change_set.item_id) async def _update_entity(change_set: CollectionChangeSet) -> None: - await entities[change_set.item_id].async_update_config(change_set.item) # type: ignore + await entities[change_set.item_id].async_update_config(change_set.item) # type: ignore[attr-defined] _func_map: dict[ str, Callable[[CollectionChangeSet], Coroutine[Any, Any, Entity | None]] diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index bb600556991bd1c7e6bea2b628b8c615e10294d1..8e4f6bc8b58856f5a45b3a385bc8d42ee721044b 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -707,10 +707,11 @@ class Entity(ABC): await self.parallel_updates.acquire() try: + task: asyncio.Future[None] if hasattr(self, "async_update"): - task = self.hass.async_create_task(self.async_update()) # type: ignore + task = self.hass.async_create_task(self.async_update()) # type: ignore[attr-defined] elif hasattr(self, "update"): - task = self.hass.async_add_executor_job(self.update) # type: ignore + task = self.hass.async_add_executor_job(self.update) # type: ignore[attr-defined] else: return diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 799b209f16e3c5f74548269ffdd6ed63591cda0d..cc252f827821715774cd4f2546f10c0c5e3705c4 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -172,7 +172,7 @@ class EntityPlatform: def async_create_setup_task() -> Coroutine: """Get task to set up platform.""" if getattr(platform, "async_setup_platform", None): - return platform.async_setup_platform( # type: ignore + return platform.async_setup_platform( # type: ignore[no-any-return,union-attr] hass, platform_config, self._async_schedule_add_entities, @@ -183,7 +183,7 @@ class EntityPlatform: # we don't want to track this task in case it blocks startup. return hass.loop.run_in_executor( # type: ignore[return-value] None, - platform.setup_platform, # type: ignore + platform.setup_platform, # type: ignore[union-attr] hass, platform_config, self._schedule_add_entities, diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index cbafd2e7e959cf9924fc23496ec0336c79c052b9..71b2cf1a5857221730fe2da3034c6e252d023cf7 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -1328,8 +1328,8 @@ def async_track_time_interval( interval: timedelta, ) -> CALLBACK_TYPE: """Add a listener that fires repetitively at every timedelta interval.""" - remove = None - interval_listener_job = None + remove: CALLBACK_TYPE + interval_listener_job: HassJob[None] job = HassJob(action) @@ -1344,7 +1344,7 @@ def async_track_time_interval( nonlocal interval_listener_job remove = async_track_point_in_utc_time( - hass, interval_listener_job, next_interval() # type: ignore + hass, interval_listener_job, next_interval() ) hass.async_run_hass_job(job, now) @@ -1353,7 +1353,7 @@ def async_track_time_interval( def remove_listener() -> None: """Remove interval listener.""" - remove() # type: ignore + remove() return remove_listener diff --git a/homeassistant/helpers/state.py b/homeassistant/helpers/state.py index 38647792b7a0cacc502d5079f4faf06731959169..75ca96ea2468f48659e15f99007a17517bcbf672 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -102,12 +102,12 @@ async def async_reproduce_state( return try: - platform: ModuleType | None = integration.get_platform("reproduce_state") + platform: ModuleType = integration.get_platform("reproduce_state") except ImportError: _LOGGER.warning("Integration %s does not support reproduce state", domain) return - await platform.async_reproduce_states( # type: ignore + await platform.async_reproduce_states( hass, states_by_domain, context=context, reproduce_options=reproduce_options ) diff --git a/homeassistant/helpers/sun.py b/homeassistant/helpers/sun.py index 3c18dcc32784a57f1813167fbeb04a88a63fac30..09a329cd2752ba6c7d3954753f96b13f6084cf36 100644 --- a/homeassistant/helpers/sun.py +++ b/homeassistant/helpers/sun.py @@ -116,7 +116,7 @@ def get_astral_event_date( kwargs["observer_elevation"] = elevation try: - return getattr(location, event)(date, **kwargs) # type: ignore + return getattr(location, event)(date, **kwargs) # type: ignore[no-any-return] except ValueError: # Event never occurs for specified date. return None diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index 175a29fcc5da1fcec3e6008154f9e14f623065c5..0b18ad9aa421d4e57322d7c56bcb088e72733ffe 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -83,7 +83,7 @@ async def async_initialize_triggers( triggers.append(platform.async_attach_trigger(hass, conf, action, info)) attach_results = await asyncio.gather(*triggers, return_exceptions=True) - removes = [] + removes: list[Callable[[], None]] = [] for result in attach_results: if isinstance(result, HomeAssistantError): @@ -103,7 +103,7 @@ async def async_initialize_triggers( log_cb(logging.INFO, "Initialized trigger") @callback - def remove_triggers(): # type: ignore + def remove_triggers() -> None: """Remove triggers.""" for remove in removes: remove() diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 7b2f963102e5285a59839a1a68aec8970a45e72c..36292989dce9b22869c99d055015f0262e2db18d 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -66,10 +66,10 @@ async def async_setup_component( if domain in hass.config.components: return True - setup_tasks = hass.data.setdefault(DATA_SETUP, {}) + setup_tasks: dict[str, asyncio.Task[bool]] = hass.data.setdefault(DATA_SETUP, {}) if domain in setup_tasks: - return await setup_tasks[domain] # type: ignore + return await setup_tasks[domain] task = setup_tasks[domain] = hass.async_create_task( _async_setup_component(hass, domain, config) diff --git a/homeassistant/util/logging.py b/homeassistant/util/logging.py index 8dba52ebe9dd16c7737cb1d0e9ea213754bdb844..d09feec52379ba0ce697809897534dd00e350bc7 100644 --- a/homeassistant/util/logging.py +++ b/homeassistant/util/logging.py @@ -69,11 +69,11 @@ def async_activate_log_queue_handler(hass: HomeAssistant) -> None: This allows us to avoid blocking I/O and formatting messages in the event loop as log messages are written in another thread. """ - simple_queue = queue.SimpleQueue() # type: ignore + simple_queue: queue.SimpleQueue[logging.Handler] = queue.SimpleQueue() queue_handler = HomeAssistantQueueHandler(simple_queue) logging.root.addHandler(queue_handler) - migrated_handlers = [] + migrated_handlers: list[logging.Handler] = [] for handler in logging.root.handlers[:]: if handler is queue_handler: continue