mirror of
https://github.com/home-assistant/core
synced 2024-08-28 03:36:46 +02:00
Enable strict typing for counter (#106906)
This commit is contained in:
parent
32b6e4d5de
commit
b3f997156a
@ -121,6 +121,7 @@ homeassistant.components.cloud.*
|
||||
homeassistant.components.co2signal.*
|
||||
homeassistant.components.command_line.*
|
||||
homeassistant.components.configurator.*
|
||||
homeassistant.components.counter.*
|
||||
homeassistant.components.cover.*
|
||||
homeassistant.components.cpuspeed.*
|
||||
homeassistant.components.crownstone.*
|
||||
|
@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Self
|
||||
from typing import Any, Self, TypeVar
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -22,6 +22,8 @@ from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_INITIAL = "initial"
|
||||
@ -59,7 +61,7 @@ STORAGE_FIELDS = {
|
||||
}
|
||||
|
||||
|
||||
def _none_to_empty_dict(value):
|
||||
def _none_to_empty_dict(value: _T | None) -> _T | dict[str, Any]:
|
||||
if value is None:
|
||||
return {}
|
||||
return value
|
||||
@ -140,12 +142,12 @@ class CounterStorageCollection(collection.DictStorageCollection):
|
||||
|
||||
async def _process_create_data(self, data: dict) -> dict:
|
||||
"""Validate the config is valid."""
|
||||
return self.CREATE_UPDATE_SCHEMA(data)
|
||||
return self.CREATE_UPDATE_SCHEMA(data) # type: ignore[no-any-return]
|
||||
|
||||
@callback
|
||||
def _get_suggested_id(self, info: dict) -> str:
|
||||
"""Suggest an ID based on the config."""
|
||||
return info[CONF_NAME]
|
||||
return info[CONF_NAME] # type: ignore[no-any-return]
|
||||
|
||||
async def _update_data(self, item: dict, update_data: dict) -> dict:
|
||||
"""Return a new updated data object."""
|
||||
@ -211,9 +213,9 @@ class Counter(collection.CollectionEntity, RestoreEntity):
|
||||
@property
|
||||
def unique_id(self) -> str | None:
|
||||
"""Return unique id of the entity."""
|
||||
return self._config[CONF_ID]
|
||||
return self._config[CONF_ID] # type: ignore[no-any-return]
|
||||
|
||||
def compute_next_state(self, state) -> int:
|
||||
def compute_next_state(self, state: int | None) -> int | None:
|
||||
"""Keep the state within the range of min/max values."""
|
||||
if self._config[CONF_MINIMUM] is not None:
|
||||
state = max(self._config[CONF_MINIMUM], state)
|
||||
|
10
mypy.ini
10
mypy.ini
@ -970,6 +970,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.counter.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.cover.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
Loading…
Reference in New Issue
Block a user