-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.py
More file actions
47 lines (38 loc) · 1.95 KB
/
context.py
File metadata and controls
47 lines (38 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Dashboard context type shared by keys, routes, and the app factory."""
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
from pathlib import Path
from span_panel_simulator.history import HistoryProvider
async def _noop_modeling_data(
_hours: int, _config_filename: str | None = None
) -> dict[str, Any] | None:
return None
@dataclass
class DashboardContext:
"""Clean interface boundary between the dashboard and SimulatorApp."""
config_dir: Path
config_filter: str | None
get_panel_configs: Callable[[], dict[Path, str]] # path -> serial
get_panel_ports: Callable[[], dict[str, int]] # serial -> port
request_reload: Callable[[], None]
get_panel_start_errors: Callable[[], dict[str, str]] = lambda: {} # filename -> error message
set_config_filter: Callable[[str | None], None] = lambda _: None
start_panel: Callable[[str], None] = lambda _: None
stop_panel: Callable[[str], None] = lambda _: None
restart_panel: Callable[[str], None] = lambda _: None
get_power_summary: Callable[[], dict[str, Any] | None] = lambda: None
set_simulation_time: Callable[[str], None] = lambda _: None
set_time_acceleration: Callable[[float], None] = lambda _: None
set_grid_online: Callable[[bool], None] = lambda _: None
set_grid_islandable: Callable[[bool], None] = lambda _: None
set_circuit_priority: Callable[[str, str], None] = lambda _id, _pri: None
set_circuit_relay: Callable[[str, str], None] = lambda _id, _state: None
get_modeling_data: Callable[[int, str | None], Awaitable[dict[str, Any] | None]] = (
_noop_modeling_data
)
ha_client: Any = None # HAClient | None — optional, set when HA API is available
history_provider: HistoryProvider | None = None
panel_browser: Any = None # PanelBrowser | None — mDNS discovery for standalone mode