diff --git a/homeassistant/components/counter/__init__.py b/homeassistant/components/counter/__init__.py index dedeb428c0c7bf..30238073b16026 100644 --- a/homeassistant/components/counter/__init__.py +++ b/homeassistant/components/counter/__init__.py @@ -3,6 +3,7 @@ import logging +from typing_extensions import Self import voluptuous as vol from homeassistant.const import ( @@ -171,14 +172,14 @@ def __init__(self, config: ConfigType) -> None: self._state: int | None = config[CONF_INITIAL] @classmethod - def from_storage(cls, config: ConfigType) -> Counter: + def from_storage(cls, config: ConfigType) -> Self: """Create counter instance from storage.""" counter = cls(config) counter.editable = True return counter @classmethod - def from_yaml(cls, config: ConfigType) -> Counter: + def from_yaml(cls, config: ConfigType) -> Self: """Create counter instance from yaml config.""" counter = cls(config) counter.editable = False diff --git a/homeassistant/components/input_boolean/__init__.py b/homeassistant/components/input_boolean/__init__.py index d1d1924712185e..a8b221e49394d8 100644 --- a/homeassistant/components/input_boolean/__init__.py +++ b/homeassistant/components/input_boolean/__init__.py @@ -4,6 +4,7 @@ import logging from typing import Any +from typing_extensions import Self import voluptuous as vol from homeassistant.const import ( @@ -167,14 +168,14 @@ def __init__(self, config: ConfigType) -> None: self._attr_unique_id = config[CONF_ID] @classmethod - def from_storage(cls, config: ConfigType) -> InputBoolean: + def from_storage(cls, config: ConfigType) -> Self: """Return entity instance initialized from storage.""" input_bool = cls(config) input_bool.editable = True return input_bool @classmethod - def from_yaml(cls, config: ConfigType) -> InputBoolean: + def from_yaml(cls, config: ConfigType) -> Self: """Return entity instance initialized from yaml.""" input_bool = cls(config) input_bool.entity_id = f"{DOMAIN}.{config[CONF_ID]}" diff --git a/homeassistant/components/input_button/__init__.py b/homeassistant/components/input_button/__init__.py index f425c8e3da2bb2..f8ff9164214a13 100644 --- a/homeassistant/components/input_button/__init__.py +++ b/homeassistant/components/input_button/__init__.py @@ -4,6 +4,7 @@ import logging from typing import cast +from typing_extensions import Self import voluptuous as vol from homeassistant.components.button import SERVICE_PRESS, ButtonEntity @@ -147,14 +148,14 @@ def __init__(self, config: ConfigType) -> None: self._attr_unique_id = config[CONF_ID] @classmethod - def from_storage(cls, config: ConfigType) -> InputButton: + def from_storage(cls, config: ConfigType) -> Self: """Return entity instance initialized from storage.""" button = cls(config) button.editable = True return button @classmethod - def from_yaml(cls, config: ConfigType) -> InputButton: + def from_yaml(cls, config: ConfigType) -> Self: """Return entity instance initialized from yaml.""" button = cls(config) button.entity_id = f"{DOMAIN}.{config[CONF_ID]}" diff --git a/homeassistant/components/input_datetime/__init__.py b/homeassistant/components/input_datetime/__init__.py index 5913789d53fa1b..34ded40d5837e4 100644 --- a/homeassistant/components/input_datetime/__init__.py +++ b/homeassistant/components/input_datetime/__init__.py @@ -5,6 +5,7 @@ import logging from typing import Any +from typing_extensions import Self import voluptuous as vol from homeassistant.const import ( @@ -250,14 +251,14 @@ def __init__(self, config: ConfigType) -> None: ) @classmethod - def from_storage(cls, config: ConfigType) -> InputDatetime: + def from_storage(cls, config: ConfigType) -> Self: """Return entity instance initialized from storage.""" input_dt = cls(config) input_dt.editable = True return input_dt @classmethod - def from_yaml(cls, config: ConfigType) -> InputDatetime: + def from_yaml(cls, config: ConfigType) -> Self: """Return entity instance initialized from yaml.""" input_dt = cls(config) input_dt.entity_id = f"{DOMAIN}.{config[CONF_ID]}" diff --git a/homeassistant/components/input_number/__init__.py b/homeassistant/components/input_number/__init__.py index d81ec581bc8408..05d4a4f8b95704 100644 --- a/homeassistant/components/input_number/__init__.py +++ b/homeassistant/components/input_number/__init__.py @@ -4,6 +4,7 @@ from contextlib import suppress import logging +from typing_extensions import Self import voluptuous as vol from homeassistant.const import ( @@ -218,14 +219,14 @@ def __init__(self, config: ConfigType) -> None: self._current_value: float | None = config.get(CONF_INITIAL) @classmethod - def from_storage(cls, config: ConfigType) -> InputNumber: + def from_storage(cls, config: ConfigType) -> Self: """Return entity instance initialized from storage.""" input_num = cls(config) input_num.editable = True return input_num @classmethod - def from_yaml(cls, config: ConfigType) -> InputNumber: + def from_yaml(cls, config: ConfigType) -> Self: """Return entity instance initialized from yaml.""" input_num = cls(config) input_num.entity_id = f"{DOMAIN}.{config[CONF_ID]}" diff --git a/homeassistant/components/input_select/__init__.py b/homeassistant/components/input_select/__init__.py index 1891ba42319fdc..9e4833954d6d1b 100644 --- a/homeassistant/components/input_select/__init__.py +++ b/homeassistant/components/input_select/__init__.py @@ -4,6 +4,7 @@ import logging from typing import Any, cast +from typing_extensions import Self import voluptuous as vol from homeassistant.components.select import ( @@ -268,14 +269,14 @@ def __init__(self, config: ConfigType) -> None: self._attr_unique_id = config[CONF_ID] @classmethod - def from_storage(cls, config: ConfigType) -> InputSelect: + def from_storage(cls, config: ConfigType) -> Self: """Return entity instance initialized from storage.""" input_select = cls(config) input_select.editable = True return input_select @classmethod - def from_yaml(cls, config: ConfigType) -> InputSelect: + def from_yaml(cls, config: ConfigType) -> Self: """Return entity instance initialized from yaml.""" input_select = cls(config) input_select.entity_id = f"{DOMAIN}.{config[CONF_ID]}" diff --git a/homeassistant/components/input_text/__init__.py b/homeassistant/components/input_text/__init__.py index 6069ae8143ac6c..6ebfdcd70dcdbe 100644 --- a/homeassistant/components/input_text/__init__.py +++ b/homeassistant/components/input_text/__init__.py @@ -3,6 +3,7 @@ import logging +from typing_extensions import Self import voluptuous as vol from homeassistant.const import ( @@ -196,14 +197,14 @@ def __init__(self, config: ConfigType) -> None: self._current_value = config.get(CONF_INITIAL) @classmethod - def from_storage(cls, config: ConfigType) -> InputText: + def from_storage(cls, config: ConfigType) -> Self: """Return entity instance initialized from storage.""" input_text = cls(config) input_text.editable = True return input_text @classmethod - def from_yaml(cls, config: ConfigType) -> InputText: + def from_yaml(cls, config: ConfigType) -> Self: """Return entity instance initialized from yaml.""" input_text = cls(config) input_text.entity_id = f"{DOMAIN}.{config[CONF_ID]}" diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 61582976bc027d..d8543946df71de 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -10,6 +10,7 @@ import os from typing import Any, cast, final +from typing_extensions import Self import voluptuous as vol from homeassistant.backports.enum import StrEnum @@ -679,7 +680,7 @@ def __post_init__(self) -> None: ) @classmethod - def from_csv_row(cls, csv_row: list[str]) -> Profile: + def from_csv_row(cls, csv_row: list[str]) -> Self: """Create profile from a CSV row tuple.""" return cls(*cls.SCHEMA(csv_row)) diff --git a/homeassistant/components/met/__init__.py b/homeassistant/components/met/__init__.py index 64734d5faaff0f..5c7738f0de3f78 100644 --- a/homeassistant/components/met/__init__.py +++ b/homeassistant/components/met/__init__.py @@ -9,6 +9,7 @@ from typing import Any import metno +from typing_extensions import Self from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -181,7 +182,7 @@ def set_coordinates(self) -> bool: ) return True - async def fetch_data(self) -> MetWeatherData: + async def fetch_data(self) -> Self: """Fetch data from API - (current weather and forecast).""" resp = await self._weather_data.fetching_data() if not resp: diff --git a/homeassistant/components/minio/minio_helper.py b/homeassistant/components/minio/minio_helper.py index 6a4c93108531d3..a5068e1a47bd79 100644 --- a/homeassistant/components/minio/minio_helper.py +++ b/homeassistant/components/minio/minio_helper.py @@ -1,7 +1,7 @@ """Minio helper methods.""" from __future__ import annotations -from collections.abc import Iterable, Iterator +from collections.abc import Iterable import json import logging from queue import Queue @@ -11,6 +11,7 @@ from urllib.parse import unquote from minio import Minio +from typing_extensions import Self from urllib3.exceptions import HTTPError _LOGGER = logging.getLogger(__name__) @@ -53,7 +54,7 @@ def get_minio_notification_response( class MinioEventStreamIterator(Iterable): """Iterator wrapper over notification http response stream.""" - def __iter__(self) -> Iterator: + def __iter__(self) -> Self: """Return self.""" return self diff --git a/homeassistant/components/number/__init__.py b/homeassistant/components/number/__init__.py index 488c555e21ef88..e73014fc2091cf 100644 --- a/homeassistant/components/number/__init__.py +++ b/homeassistant/components/number/__init__.py @@ -10,6 +10,7 @@ from math import ceil, floor from typing import Any, final +from typing_extensions import Self import voluptuous as vol from homeassistant.config_entries import ConfigEntry @@ -540,7 +541,7 @@ def as_dict(self) -> dict[str, Any]: return dataclasses.asdict(self) @classmethod - def from_dict(cls, restored: dict[str, Any]) -> NumberExtraStoredData | None: + def from_dict(cls, restored: dict[str, Any]) -> Self | None: """Initialize a stored number state from a dict.""" try: return cls(