-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement etag support for category files
- Loading branch information
Showing
5 changed files
with
97 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ repos: | |
- id: mixed-line-ending | ||
stages: [manual] | ||
args: | ||
- --fix=lf | ||
- --fix=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member | ||
import os | ||
|
||
from custom_components.hacs.share import get_hacs | ||
from fnvhash import fnv1a_32 | ||
from pathlib import Path | ||
|
||
|
||
def get_etag(path) -> bool: | ||
file_path = Path(path) | ||
if not file_path.exists(): | ||
return None | ||
return fnv1a_32(file_path.read_bytes()) | ||
|
||
|
||
async def async_get_etag(path) -> bool: | ||
hass = get_hacs().hass | ||
fnv = await hass.async_add_executor_job(get_etag, path) | ||
if fnv is None: | ||
return None | ||
return str(hex(fnv)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters