1
0
mirror of https://github.com/home-assistant/core synced 2024-07-03 08:18:59 +00:00

Add strict typing to command_line (#106889)

* Add strict typing to command_line

* Code review
This commit is contained in:
Marc Mueller 2024-01-02 20:04:28 +01:00 committed by GitHub
parent 943fb2791e
commit dcee8e67c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 18 deletions

View File

@ -116,6 +116,7 @@ homeassistant.components.clickatell.*
homeassistant.components.clicksend.*
homeassistant.components.climate.*
homeassistant.components.cloud.*
homeassistant.components.command_line.*
homeassistant.components.configurator.*
homeassistant.components.cover.*
homeassistant.components.cpuspeed.*

View File

@ -200,7 +200,7 @@ async def async_load_platforms(
load_coroutines: list[Coroutine[Any, Any, None]] = []
platforms: list[Platform] = []
reload_configs: list[tuple] = []
reload_configs: list[tuple[Platform, dict[str, Any]]] = []
for platform_config in command_line_config:
for platform, _config in platform_config.items():
if (mapped_platform := PLATFORM_MAPPING[platform]) not in platforms:

View File

@ -2,7 +2,7 @@
from __future__ import annotations
import asyncio
from datetime import timedelta
from datetime import datetime, timedelta
from typing import cast
from homeassistant.components.binary_sensor import (
@ -115,7 +115,7 @@ class CommandBinarySensor(ManualTriggerEntity, BinarySensorEntity):
async def async_added_to_hass(self) -> None:
"""Call when entity about to be added to hass."""
await super().async_added_to_hass()
await self._update_entity_state(None)
await self._update_entity_state()
self.async_on_remove(
async_track_time_interval(
self.hass,
@ -126,7 +126,7 @@ class CommandBinarySensor(ManualTriggerEntity, BinarySensorEntity):
),
)
async def _update_entity_state(self, now) -> None:
async def _update_entity_state(self, now: datetime | None = None) -> None:
"""Update the state of the entity."""
if self._process_updates is None:
self._process_updates = asyncio.Lock()

View File

@ -2,7 +2,7 @@
from __future__ import annotations
import asyncio
from datetime import timedelta
from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Any, cast
from homeassistant.components.cover import CoverEntity
@ -147,7 +147,7 @@ class CommandCover(ManualTriggerEntity, CoverEntity):
if TYPE_CHECKING:
return None
async def _update_entity_state(self, now) -> None:
async def _update_entity_state(self, now: datetime | None = None) -> None:
"""Update the state of the entity."""
if self._process_updates is None:
self._process_updates = asyncio.Lock()
@ -186,14 +186,14 @@ class CommandCover(ManualTriggerEntity, CoverEntity):
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self.hass.async_add_executor_job(self._move_cover, self._command_open)
await self._update_entity_state(None)
await self._update_entity_state()
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
await self.hass.async_add_executor_job(self._move_cover, self._command_close)
await self._update_entity_state(None)
await self._update_entity_state()
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
await self.hass.async_add_executor_job(self._move_cover, self._command_stop)
await self._update_entity_state(None)
await self._update_entity_state()

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import asyncio
from collections.abc import Mapping
from datetime import timedelta
from datetime import datetime, timedelta
import json
from typing import Any, cast
@ -108,7 +108,7 @@ class CommandSensor(ManualTriggerSensorEntity):
"""Initialize the sensor."""
super().__init__(self.hass, config)
self.data = data
self._attr_extra_state_attributes = {}
self._attr_extra_state_attributes: dict[str, Any] = {}
self._json_attributes = json_attributes
self._attr_native_value = None
self._value_template = value_template
@ -118,12 +118,12 @@ class CommandSensor(ManualTriggerSensorEntity):
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return extra state attributes."""
return cast(dict, self._attr_extra_state_attributes)
return self._attr_extra_state_attributes
async def async_added_to_hass(self) -> None:
"""Call when entity about to be added to hass."""
await super().async_added_to_hass()
await self._update_entity_state(None)
await self._update_entity_state()
self.async_on_remove(
async_track_time_interval(
self.hass,
@ -134,7 +134,7 @@ class CommandSensor(ManualTriggerSensorEntity):
),
)
async def _update_entity_state(self, now) -> None:
async def _update_entity_state(self, now: datetime | None = None) -> None:
"""Update the state of the entity."""
if self._process_updates is None:
self._process_updates = asyncio.Lock()

View File

@ -2,7 +2,7 @@
from __future__ import annotations
import asyncio
from datetime import timedelta
from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Any, cast
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
@ -155,7 +155,7 @@ class CommandSwitch(ManualTriggerEntity, SwitchEntity):
if TYPE_CHECKING:
return None
async def _update_entity_state(self, now) -> None:
async def _update_entity_state(self, now: datetime | None = None) -> None:
"""Update the state of the entity."""
if self._process_updates is None:
self._process_updates = asyncio.Lock()
@ -197,11 +197,11 @@ class CommandSwitch(ManualTriggerEntity, SwitchEntity):
if await self._switch(self._command_on) and not self._command_state:
self._attr_is_on = True
self.async_schedule_update_ha_state()
await self._update_entity_state(None)
await self._update_entity_state()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the device off."""
if await self._switch(self._command_off) and not self._command_state:
self._attr_is_on = False
self.async_schedule_update_ha_state()
await self._update_entity_state(None)
await self._update_entity_state()

View File

@ -920,6 +920,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.command_line.*]
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.configurator.*]
check_untyped_defs = true
disallow_incomplete_defs = true