mirror of https://github.com/home-assistant/core
Enable strict typing for trace (#107945)
This commit is contained in:
parent
88d7fc87c9
commit
ec708811d0
|
@ -412,6 +412,7 @@ homeassistant.components.todo.*
|
|||
homeassistant.components.tolo.*
|
||||
homeassistant.components.tplink.*
|
||||
homeassistant.components.tplink_omada.*
|
||||
homeassistant.components.trace.*
|
||||
homeassistant.components.tractive.*
|
||||
homeassistant.components.tradfri.*
|
||||
homeassistant.components.trafikverket_camera.*
|
||||
|
|
|
@ -44,7 +44,7 @@ TraceData = dict[str, LimitedSizeDict[str, BaseTrace]]
|
|||
|
||||
@callback
|
||||
def _get_data(hass: HomeAssistant) -> TraceData:
|
||||
return hass.data[DATA_TRACE]
|
||||
return hass.data[DATA_TRACE] # type: ignore[no-any-return]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
|
|
@ -163,8 +163,8 @@ class RestoredTrace(BaseTrace):
|
|||
|
||||
def as_extended_dict(self) -> dict[str, Any]:
|
||||
"""Return an extended dictionary version of this RestoredTrace."""
|
||||
return self._dict
|
||||
return self._dict # type: ignore[no-any-return]
|
||||
|
||||
def as_short_dict(self) -> dict[str, Any]:
|
||||
"""Return a brief dictionary version of this RestoredTrace."""
|
||||
return self._short_dict
|
||||
return self._short_dict # type: ignore[no-any-return]
|
||||
|
|
|
@ -142,8 +142,8 @@ def websocket_breakpoint_set(
|
|||
) -> None:
|
||||
"""Set breakpoint."""
|
||||
key = f"{msg['domain']}.{msg['item_id']}"
|
||||
node = msg["node"]
|
||||
run_id = msg.get("run_id")
|
||||
node: str = msg["node"]
|
||||
run_id: str | None = msg.get("run_id")
|
||||
|
||||
if (
|
||||
SCRIPT_BREAKPOINT_HIT not in hass.data.get(DATA_DISPATCHER, {})
|
||||
|
@ -173,8 +173,8 @@ def websocket_breakpoint_clear(
|
|||
) -> None:
|
||||
"""Clear breakpoint."""
|
||||
key = f"{msg['domain']}.{msg['item_id']}"
|
||||
node = msg["node"]
|
||||
run_id = msg.get("run_id")
|
||||
node: str = msg["node"]
|
||||
run_id: str | None = msg.get("run_id")
|
||||
|
||||
result = breakpoint_clear(hass, key, run_id, node)
|
||||
|
||||
|
@ -211,7 +211,7 @@ def websocket_subscribe_breakpoint_events(
|
|||
"""Subscribe to breakpoint events."""
|
||||
|
||||
@callback
|
||||
def breakpoint_hit(key, run_id, node):
|
||||
def breakpoint_hit(key: str, run_id: str, node: str) -> None:
|
||||
"""Forward events to websocket."""
|
||||
domain, item_id = key.split(".", 1)
|
||||
connection.send_message(
|
||||
|
@ -231,7 +231,7 @@ def websocket_subscribe_breakpoint_events(
|
|||
)
|
||||
|
||||
@callback
|
||||
def unsub():
|
||||
def unsub() -> None:
|
||||
"""Unsubscribe from breakpoint events."""
|
||||
remove_signal()
|
||||
if (
|
||||
|
@ -263,7 +263,7 @@ def websocket_debug_continue(
|
|||
) -> None:
|
||||
"""Resume execution of halted script or automation."""
|
||||
key = f"{msg['domain']}.{msg['item_id']}"
|
||||
run_id = msg["run_id"]
|
||||
run_id: str = msg["run_id"]
|
||||
|
||||
result = debug_continue(hass, key, run_id)
|
||||
|
||||
|
@ -287,7 +287,7 @@ def websocket_debug_step(
|
|||
) -> None:
|
||||
"""Single step a halted script or automation."""
|
||||
key = f"{msg['domain']}.{msg['item_id']}"
|
||||
run_id = msg["run_id"]
|
||||
run_id: str = msg["run_id"]
|
||||
|
||||
result = debug_step(hass, key, run_id)
|
||||
|
||||
|
@ -311,7 +311,7 @@ def websocket_debug_stop(
|
|||
) -> None:
|
||||
"""Stop a halted script or automation."""
|
||||
key = f"{msg['domain']}.{msg['item_id']}"
|
||||
run_id = msg["run_id"]
|
||||
run_id: str = msg["run_id"]
|
||||
|
||||
result = debug_stop(hass, key, run_id)
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ from homeassistant.util.dt import utcnow
|
|||
|
||||
from . import condition, config_validation as cv, service, template
|
||||
from .condition import ConditionCheckerType, trace_condition_function
|
||||
from .dispatcher import async_dispatcher_connect, async_dispatcher_send
|
||||
from .dispatcher import SignalType, async_dispatcher_connect, async_dispatcher_send
|
||||
from .event import async_call_later, async_track_template
|
||||
from .script_variables import ScriptVariables
|
||||
from .trace import (
|
||||
|
@ -142,7 +142,7 @@ _SHUTDOWN_MAX_WAIT = 60
|
|||
|
||||
ACTION_TRACE_NODE_MAX_LEN = 20 # Max length of a trace node for repeated actions
|
||||
|
||||
SCRIPT_BREAKPOINT_HIT = "script_breakpoint_hit"
|
||||
SCRIPT_BREAKPOINT_HIT = SignalType[str, str, str]("script_breakpoint_hit")
|
||||
SCRIPT_DEBUG_CONTINUE_STOP = "script_debug_continue_stop_{}_{}"
|
||||
SCRIPT_DEBUG_CONTINUE_ALL = "script_debug_continue_all"
|
||||
|
||||
|
@ -1793,7 +1793,9 @@ class Script:
|
|||
|
||||
|
||||
@callback
|
||||
def breakpoint_clear(hass, key, run_id, node):
|
||||
def breakpoint_clear(
|
||||
hass: HomeAssistant, key: str, run_id: str | None, node: str
|
||||
) -> None:
|
||||
"""Clear a breakpoint."""
|
||||
run_id = run_id or RUN_ID_ANY
|
||||
breakpoints = hass.data[DATA_SCRIPT_BREAKPOINTS]
|
||||
|
@ -1809,7 +1811,9 @@ def breakpoint_clear_all(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
@callback
|
||||
def breakpoint_set(hass, key, run_id, node):
|
||||
def breakpoint_set(
|
||||
hass: HomeAssistant, key: str, run_id: str | None, node: str
|
||||
) -> None:
|
||||
"""Set a breakpoint."""
|
||||
run_id = run_id or RUN_ID_ANY
|
||||
breakpoints = hass.data[DATA_SCRIPT_BREAKPOINTS]
|
||||
|
@ -1834,7 +1838,7 @@ def breakpoint_list(hass: HomeAssistant) -> list[dict[str, Any]]:
|
|||
|
||||
|
||||
@callback
|
||||
def debug_continue(hass, key, run_id):
|
||||
def debug_continue(hass: HomeAssistant, key: str, run_id: str) -> None:
|
||||
"""Continue execution of a halted script."""
|
||||
# Clear any wildcard breakpoint
|
||||
breakpoint_clear(hass, key, run_id, NODE_ANY)
|
||||
|
@ -1844,7 +1848,7 @@ def debug_continue(hass, key, run_id):
|
|||
|
||||
|
||||
@callback
|
||||
def debug_step(hass, key, run_id):
|
||||
def debug_step(hass: HomeAssistant, key: str, run_id: str) -> None:
|
||||
"""Single step a halted script."""
|
||||
# Set a wildcard breakpoint
|
||||
breakpoint_set(hass, key, run_id, NODE_ANY)
|
||||
|
@ -1854,7 +1858,7 @@ def debug_step(hass, key, run_id):
|
|||
|
||||
|
||||
@callback
|
||||
def debug_stop(hass, key, run_id):
|
||||
def debug_stop(hass: HomeAssistant, key: str, run_id: str) -> None:
|
||||
"""Stop execution of a running or halted script."""
|
||||
signal = SCRIPT_DEBUG_CONTINUE_STOP.format(key, run_id)
|
||||
async_dispatcher_send(hass, signal, "stop")
|
||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -3882,6 +3882,16 @@ disallow_untyped_defs = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.trace.*]
|
||||
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.tractive.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Reference in New Issue