mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Add Self typing (3) [mypy 1.0] (#87600)
This commit is contained in:
parent
342b406dc0
commit
f7b39aa4a8
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -171,14 +172,14 @@ class Counter(collection.CollectionEntity, RestoreEntity):
|
|||||||
self._state: int | None = config[CONF_INITIAL]
|
self._state: int | None = config[CONF_INITIAL]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> Counter:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Create counter instance from storage."""
|
"""Create counter instance from storage."""
|
||||||
counter = cls(config)
|
counter = cls(config)
|
||||||
counter.editable = True
|
counter.editable = True
|
||||||
return counter
|
return counter
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> Counter:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Create counter instance from yaml config."""
|
"""Create counter instance from yaml config."""
|
||||||
counter = cls(config)
|
counter = cls(config)
|
||||||
counter.editable = False
|
counter.editable = False
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -167,14 +168,14 @@ class InputBoolean(collection.CollectionEntity, ToggleEntity, RestoreEntity):
|
|||||||
self._attr_unique_id = config[CONF_ID]
|
self._attr_unique_id = config[CONF_ID]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> InputBoolean:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from storage."""
|
"""Return entity instance initialized from storage."""
|
||||||
input_bool = cls(config)
|
input_bool = cls(config)
|
||||||
input_bool.editable = True
|
input_bool.editable = True
|
||||||
return input_bool
|
return input_bool
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> InputBoolean:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from yaml."""
|
"""Return entity instance initialized from yaml."""
|
||||||
input_bool = cls(config)
|
input_bool = cls(config)
|
||||||
input_bool.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
input_bool.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.button import SERVICE_PRESS, ButtonEntity
|
from homeassistant.components.button import SERVICE_PRESS, ButtonEntity
|
||||||
@ -147,14 +148,14 @@ class InputButton(collection.CollectionEntity, ButtonEntity, RestoreEntity):
|
|||||||
self._attr_unique_id = config[CONF_ID]
|
self._attr_unique_id = config[CONF_ID]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> InputButton:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from storage."""
|
"""Return entity instance initialized from storage."""
|
||||||
button = cls(config)
|
button = cls(config)
|
||||||
button.editable = True
|
button.editable = True
|
||||||
return button
|
return button
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> InputButton:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from yaml."""
|
"""Return entity instance initialized from yaml."""
|
||||||
button = cls(config)
|
button = cls(config)
|
||||||
button.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
button.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||||
|
@ -5,6 +5,7 @@ import datetime as py_datetime
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -250,14 +251,14 @@ class InputDatetime(collection.CollectionEntity, RestoreEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> InputDatetime:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from storage."""
|
"""Return entity instance initialized from storage."""
|
||||||
input_dt = cls(config)
|
input_dt = cls(config)
|
||||||
input_dt.editable = True
|
input_dt.editable = True
|
||||||
return input_dt
|
return input_dt
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> InputDatetime:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from yaml."""
|
"""Return entity instance initialized from yaml."""
|
||||||
input_dt = cls(config)
|
input_dt = cls(config)
|
||||||
input_dt.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
input_dt.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -218,14 +219,14 @@ class InputNumber(collection.CollectionEntity, RestoreEntity):
|
|||||||
self._current_value: float | None = config.get(CONF_INITIAL)
|
self._current_value: float | None = config.get(CONF_INITIAL)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> InputNumber:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from storage."""
|
"""Return entity instance initialized from storage."""
|
||||||
input_num = cls(config)
|
input_num = cls(config)
|
||||||
input_num.editable = True
|
input_num.editable = True
|
||||||
return input_num
|
return input_num
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> InputNumber:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from yaml."""
|
"""Return entity instance initialized from yaml."""
|
||||||
input_num = cls(config)
|
input_num = cls(config)
|
||||||
input_num.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
input_num.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.select import (
|
from homeassistant.components.select import (
|
||||||
@ -268,14 +269,14 @@ class InputSelect(collection.CollectionEntity, SelectEntity, RestoreEntity):
|
|||||||
self._attr_unique_id = config[CONF_ID]
|
self._attr_unique_id = config[CONF_ID]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> InputSelect:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from storage."""
|
"""Return entity instance initialized from storage."""
|
||||||
input_select = cls(config)
|
input_select = cls(config)
|
||||||
input_select.editable = True
|
input_select.editable = True
|
||||||
return input_select
|
return input_select
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> InputSelect:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from yaml."""
|
"""Return entity instance initialized from yaml."""
|
||||||
input_select = cls(config)
|
input_select = cls(config)
|
||||||
input_select.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
input_select.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -196,14 +197,14 @@ class InputText(collection.CollectionEntity, RestoreEntity):
|
|||||||
self._current_value = config.get(CONF_INITIAL)
|
self._current_value = config.get(CONF_INITIAL)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_storage(cls, config: ConfigType) -> InputText:
|
def from_storage(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from storage."""
|
"""Return entity instance initialized from storage."""
|
||||||
input_text = cls(config)
|
input_text = cls(config)
|
||||||
input_text.editable = True
|
input_text.editable = True
|
||||||
return input_text
|
return input_text
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, config: ConfigType) -> InputText:
|
def from_yaml(cls, config: ConfigType) -> Self:
|
||||||
"""Return entity instance initialized from yaml."""
|
"""Return entity instance initialized from yaml."""
|
||||||
input_text = cls(config)
|
input_text = cls(config)
|
||||||
input_text.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
input_text.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||||
|
@ -10,6 +10,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from typing import Any, cast, final
|
from typing import Any, cast, final
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.backports.enum import StrEnum
|
from homeassistant.backports.enum import StrEnum
|
||||||
@ -679,7 +680,7 @@ class Profile:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@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."""
|
"""Create profile from a CSV row tuple."""
|
||||||
return cls(*cls.SCHEMA(csv_row))
|
return cls(*cls.SCHEMA(csv_row))
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from types import MappingProxyType
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import metno
|
import metno
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -181,7 +182,7 @@ class MetWeatherData:
|
|||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def fetch_data(self) -> MetWeatherData:
|
async def fetch_data(self) -> Self:
|
||||||
"""Fetch data from API - (current weather and forecast)."""
|
"""Fetch data from API - (current weather and forecast)."""
|
||||||
resp = await self._weather_data.fetching_data()
|
resp = await self._weather_data.fetching_data()
|
||||||
if not resp:
|
if not resp:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Minio helper methods."""
|
"""Minio helper methods."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Iterable, Iterator
|
from collections.abc import Iterable
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
@ -11,6 +11,7 @@ import time
|
|||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
from minio import Minio
|
from minio import Minio
|
||||||
|
from typing_extensions import Self
|
||||||
from urllib3.exceptions import HTTPError
|
from urllib3.exceptions import HTTPError
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -53,7 +54,7 @@ def get_minio_notification_response(
|
|||||||
class MinioEventStreamIterator(Iterable):
|
class MinioEventStreamIterator(Iterable):
|
||||||
"""Iterator wrapper over notification http response stream."""
|
"""Iterator wrapper over notification http response stream."""
|
||||||
|
|
||||||
def __iter__(self) -> Iterator:
|
def __iter__(self) -> Self:
|
||||||
"""Return self."""
|
"""Return self."""
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import logging
|
|||||||
from math import ceil, floor
|
from math import ceil, floor
|
||||||
from typing import Any, final
|
from typing import Any, final
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -540,7 +541,7 @@ class NumberExtraStoredData(ExtraStoredData):
|
|||||||
return dataclasses.asdict(self)
|
return dataclasses.asdict(self)
|
||||||
|
|
||||||
@classmethod
|
@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."""
|
"""Initialize a stored number state from a dict."""
|
||||||
try:
|
try:
|
||||||
return cls(
|
return cls(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user