Update typing 09 (#48059)

This commit is contained in:
Marc Mueller 2021-03-18 10:02:00 +01:00 committed by GitHub
parent 2ab640aaef
commit 283b4abe67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 239 additions and 196 deletions

View file

@ -2,7 +2,6 @@
from __future__ import annotations
import logging
import typing
import voluptuous as vol
@ -179,16 +178,16 @@ class NumberStorageCollection(collection.StorageCollection):
CREATE_SCHEMA = vol.Schema(vol.All(CREATE_FIELDS, _cv_input_number))
UPDATE_SCHEMA = vol.Schema(UPDATE_FIELDS)
async def _process_create_data(self, data: typing.Dict) -> typing.Dict:
async def _process_create_data(self, data: dict) -> dict:
"""Validate the config is valid."""
return self.CREATE_SCHEMA(data)
@callback
def _get_suggested_id(self, info: typing.Dict) -> str:
def _get_suggested_id(self, info: dict) -> str:
"""Suggest an ID based on the config."""
return info[CONF_NAME]
async def _update_data(self, data: dict, update_data: typing.Dict) -> typing.Dict:
async def _update_data(self, data: dict, update_data: dict) -> dict:
"""Return a new updated data object."""
update_data = self.UPDATE_SCHEMA(update_data)
return _cv_input_number({**data, **update_data})
@ -197,14 +196,14 @@ class NumberStorageCollection(collection.StorageCollection):
class InputNumber(RestoreEntity):
"""Representation of a slider."""
def __init__(self, config: typing.Dict):
def __init__(self, config: dict):
"""Initialize an input number."""
self._config = config
self.editable = True
self._current_value = config.get(CONF_INITIAL)
@classmethod
def from_yaml(cls, config: typing.Dict) -> InputNumber:
def from_yaml(cls, config: dict) -> InputNumber:
"""Return entity instance initialized from yaml storage."""
input_num = cls(config)
input_num.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
@ -252,7 +251,7 @@ class InputNumber(RestoreEntity):
return self._config.get(CONF_UNIT_OF_MEASUREMENT)
@property
def unique_id(self) -> typing.Optional[str]:
def unique_id(self) -> str | None:
"""Return unique id of the entity."""
return self._config[CONF_ID]
@ -303,7 +302,7 @@ class InputNumber(RestoreEntity):
"""Decrement value."""
await self.async_set_value(max(self._current_value - self._step, self._minimum))
async def async_update_config(self, config: typing.Dict) -> None:
async def async_update_config(self, config: dict) -> None:
"""Handle when the config is updated."""
self._config = config
# just in case min/max values changed

View file

@ -1,7 +1,9 @@
"""Reproduce an Input number state."""
from __future__ import annotations
import asyncio
import logging
from typing import Any, Dict, Iterable, Optional
from typing import Any, Iterable
import voluptuous as vol
@ -18,8 +20,8 @@ async def _async_reproduce_state(
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
context: Context | None = None,
reproduce_options: dict[str, Any] | None = None,
) -> None:
"""Reproduce a single state."""
cur_state = hass.states.get(state.entity_id)
@ -56,8 +58,8 @@ async def async_reproduce_states(
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
context: Context | None = None,
reproduce_options: dict[str, Any] | None = None,
) -> None:
"""Reproduce Input number states."""
# Reproduce states in parallel.