Add Self typing (3) [mypy 1.0] (#87600)
parent
342b406dc0
commit
f7b39aa4a8
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
|
||||
from typing_extensions import Self
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -171,14 +172,14 @@ class Counter(collection.CollectionEntity, RestoreEntity):
|
|||
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
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from typing_extensions import Self
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -167,14 +168,14 @@ class InputBoolean(collection.CollectionEntity, ToggleEntity, RestoreEntity):
|
|||
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]}"
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
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 @@ class InputButton(collection.CollectionEntity, ButtonEntity, RestoreEntity):
|
|||
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]}"
|
||||
|
|
|
@ -5,6 +5,7 @@ import datetime as py_datetime
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from typing_extensions import Self
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -250,14 +251,14 @@ class InputDatetime(collection.CollectionEntity, RestoreEntity):
|
|||
)
|
||||
|
||||
@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]}"
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
from contextlib import suppress
|
||||
import logging
|
||||
|
||||
from typing_extensions import Self
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -218,14 +219,14 @@ class InputNumber(collection.CollectionEntity, RestoreEntity):
|
|||
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]}"
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
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 @@ class InputSelect(collection.CollectionEntity, SelectEntity, RestoreEntity):
|
|||
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]}"
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
|
||||
from typing_extensions import Self
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -196,14 +197,14 @@ class InputText(collection.CollectionEntity, RestoreEntity):
|
|||
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]}"
|
||||
|
|
|
@ -10,6 +10,7 @@ import logging
|
|||
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 @@ class Profile:
|
|||
)
|
||||
|
||||
@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))
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ from types import MappingProxyType
|
|||
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 @@ class MetWeatherData:
|
|||
)
|
||||
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:
|
||||
|
|
|
@ -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 @@ import time
|
|||
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
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import logging
|
|||
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 @@ class NumberExtraStoredData(ExtraStoredData):
|
|||
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(
|
||||
|
|
Loading…
Reference in New Issue