1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-13 14:18:14 +00:00

Merge branch 'dev' into integration

This commit is contained in:
J. Nick Koston 2023-11-15 21:02:32 -06:00
commit 787af6b622
No known key found for this signature in database
5 changed files with 16 additions and 21 deletions

View File

@ -53,7 +53,7 @@ class ESPHomeDashboard:
settings = self.settings
mdns_task: asyncio.Task | None = None
ping_status_task: asyncio.Task | None = None
await DASHBOARD.entries.async_update_entries()
await self.entries.async_update_entries()
if settings.status_use_ping:
from .status.ping import PingStatus

View File

@ -46,12 +46,6 @@ class DashboardEntries:
"""Return all entries."""
return list(self._entries.values())
def update_entries(self) -> list[DashboardEntry]:
"""Update the dashboard entries from disk."""
return asyncio.run_coroutine_threadsafe(
self.async_update_entries, self._loop
).result()
async def async_request_update_entries(self) -> None:
"""Request an update of the dashboard entries from disk.
@ -131,12 +125,6 @@ class DashboardEntries:
# file which is much faster than reading the file
# for the cache hit case which is the common case.
#
# Because there is no lock the cache may
# get built more than once but that's fine as its still
# thread-safe and results in orders of magnitude less
# reads from disk than if we did not cache at all and
# does not have a lock contention issue.
#
for file in util.list_yaml_files([self._config_dir]):
try:
# Prefer the json storage path if it exists
@ -164,7 +152,7 @@ class DashboardEntry:
This class is thread-safe and read-only.
"""
__slots__ = ("path", "filename", "_storage_path", "cache_key", "storage", "loaded")
__slots__ = ("path", "filename", "_storage_path", "cache_key", "storage")
def __init__(self, path: str, cache_key: DashboardCacheKeyType) -> None:
"""Initialize the DashboardEntry."""
@ -173,7 +161,6 @@ class DashboardEntry:
self._storage_path = ext_storage_path(self.filename)
self.cache_key = cache_key
self.storage: StorageJSON | None = None
self.loaded = False
def __repr__(self):
"""Return the representation of this entry."""
@ -188,9 +175,19 @@ class DashboardEntry:
def load_from_disk(self, cache_key: DashboardCacheKeyType | None = None) -> None:
"""Load this entry from disk."""
self.storage = StorageJSON.load(self._storage_path)
if self.cache_key:
#
# Currently StorageJSON.load() will return None if the file does not exist
#
# StorageJSON currently does not provide an updated cache key so we use the
# one that is passed in.
#
# The cache key was read from the disk moments ago and may be stale but
# it does not matter since we are polling anyways, and the next call to
# async_update_entries() will load it again in the extremely rare case that
# it changed between the two calls.
#
if cache_key:
self.cache_key = cache_key
self.loaded = bool(self.storage)
@property
def address(self) -> str | None:

View File

@ -47,7 +47,7 @@ class MDNSStatus:
host_mdns_state = self.host_mdns_state
host_name_to_filename = self.host_name_to_filename
filename_to_host_name = self.filename_to_host_name
ping_result = DASHBOARD.ping_result
ping_result = dashboard.ping_result
for entry in entries:
name = entry.name

View File

@ -51,8 +51,6 @@ class MqttStatusThread(threading.Thread):
client.loop_start()
while not dashboard.stop_event.wait(2):
# update entries
dashboard.entries.update_entries()
entries = dashboard.entries.all()
# will be set to true on on_message

View File

@ -11,7 +11,7 @@ esptool==4.6.2
click==8.1.7
esphome-dashboard==20231107.0
aioesphomeapi==18.4.1
zeroconf==0.126.0
zeroconf==0.127.0
# esp-idf requires this, but doesn't bundle it by default
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24