Update typing 09 (#48059)
This commit is contained in:
parent
2ab640aaef
commit
283b4abe67
39 changed files with 239 additions and 196 deletions
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import datetime as py_datetime
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -178,16 +177,16 @@ class DateTimeStorageCollection(collection.StorageCollection):
|
|||
CREATE_SCHEMA = vol.Schema(vol.All(CREATE_FIELDS, has_date_or_time))
|
||||
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 has_date_or_time({**data, **update_data})
|
||||
|
@ -196,7 +195,7 @@ class DateTimeStorageCollection(collection.StorageCollection):
|
|||
class InputDatetime(RestoreEntity):
|
||||
"""Representation of a datetime input."""
|
||||
|
||||
def __init__(self, config: typing.Dict) -> None:
|
||||
def __init__(self, config: dict) -> None:
|
||||
"""Initialize a select input."""
|
||||
self._config = config
|
||||
self.editable = True
|
||||
|
@ -230,7 +229,7 @@ class InputDatetime(RestoreEntity):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def from_yaml(cls, config: typing.Dict) -> InputDatetime:
|
||||
def from_yaml(cls, config: dict) -> InputDatetime:
|
||||
"""Return entity instance initialized from yaml storage."""
|
||||
input_dt = cls(config)
|
||||
input_dt.entity_id = f"{DOMAIN}.{config[CONF_ID]}"
|
||||
|
@ -360,7 +359,7 @@ class InputDatetime(RestoreEntity):
|
|||
return attrs
|
||||
|
||||
@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]
|
||||
|
||||
|
@ -394,7 +393,7 @@ class InputDatetime(RestoreEntity):
|
|||
)
|
||||
self.async_write_ha_state()
|
||||
|
||||
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
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""Reproduce an Input datetime state."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Any, Dict, Iterable, Optional
|
||||
from typing import Any, Iterable
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import Context, State
|
||||
|
@ -35,8 +37,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)
|
||||
|
@ -80,8 +82,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 datetime states."""
|
||||
await asyncio.gather(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue