1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-17 02:32:20 +01:00

dashboard: Centralize dashboard entries into DashboardEntries class (#5774)

* Centralize dashboard entries into DashboardEntries class

* preen

* preen

* preen

* preen

* preen
This commit is contained in:
J. Nick Koston
2023-11-15 20:49:56 -06:00
committed by GitHub
parent 5f1d8dfa5b
commit 149d814fab
7 changed files with 209 additions and 133 deletions

View File

@@ -6,7 +6,7 @@ import threading
from typing import TYPE_CHECKING
from ..zeroconf import DiscoveredImport
from .entries import DashboardEntry
from .entries import DashboardEntries
from .settings import DashboardSettings
if TYPE_CHECKING:
@@ -15,15 +15,11 @@ if TYPE_CHECKING:
_LOGGER = logging.getLogger(__name__)
def list_dashboard_entries() -> list[DashboardEntry]:
"""List all dashboard entries."""
return DASHBOARD.settings.entries()
class ESPHomeDashboard:
"""Class that represents the dashboard."""
__slots__ = (
"entries",
"loop",
"ping_result",
"import_result",
@@ -36,6 +32,7 @@ class ESPHomeDashboard:
def __init__(self) -> None:
"""Initialize the ESPHomeDashboard."""
self.entries: DashboardEntries | None = None
self.loop: asyncio.AbstractEventLoop | None = None
self.ping_result: dict[str, bool | None] = {}
self.import_result: dict[str, DiscoveredImport] = {}
@@ -49,12 +46,14 @@ class ESPHomeDashboard:
"""Setup the dashboard."""
self.loop = asyncio.get_running_loop()
self.ping_request = asyncio.Event()
self.entries = DashboardEntries(self.settings.config_dir)
async def async_run(self) -> None:
"""Run the dashboard."""
settings = self.settings
mdns_task: asyncio.Task | None = None
ping_status_task: asyncio.Task | None = None
await self.entries.async_update_entries()
if settings.status_use_ping:
from .status.ping import PingStatus