Use coordinator setup method in filesize (#123139)

This commit is contained in:
G Johansson 2024-08-04 23:03:40 +02:00 committed by GitHub
parent a9d8e47979
commit ccd157dc26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,14 +46,15 @@ class FileSizeCoordinator(DataUpdateCoordinator[dict[str, int | float | datetime
def _update(self) -> os.stat_result:
"""Fetch file information."""
if not hasattr(self, "path"):
self.path = self._get_full_path()
try:
return self.path.stat()
except OSError as error:
raise UpdateFailed(f"Can not retrieve file statistics {error}") from error
async def _async_setup(self) -> None:
"""Set up path."""
self.path = await self.hass.async_add_executor_job(self._get_full_path)
async def _async_update_data(self) -> dict[str, float | int | datetime]:
"""Fetch file information."""
statinfo = await self.hass.async_add_executor_job(self._update)