mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Switch to fnv-hash-fast from fnvhash (#90761)
* Switch to fnv-hash-fast from fnvhash Replaces the pure python implemention with a fast cpp one when available (with fallback to pure python) changelog: https://github.com/bdraco/fnv-hash-fast/releases/tag/v0.3.1 source: https://github.com/bdraco/fnv-hash-fast/tree/main/src/fnv_hash_fast * Apply suggestions from code review * lint
This commit is contained in:
parent
a8f1d033a0
commit
b4fec762bc
@ -13,7 +13,7 @@ from __future__ import annotations
|
||||
from collections.abc import Generator
|
||||
import random
|
||||
|
||||
from fnvhash import fnv1a_32
|
||||
from fnv_hash_fast import fnv1a_32
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
@ -10,7 +10,7 @@
|
||||
"loggers": ["pyhap"],
|
||||
"requirements": [
|
||||
"HAP-python==4.6.0",
|
||||
"fnvhash==0.1.0",
|
||||
"fnv-hash-fast==0.3.1",
|
||||
"PyQRCode==1.2.1",
|
||||
"base36==0.1.1"
|
||||
],
|
||||
|
@ -3,13 +3,12 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timedelta
|
||||
from functools import lru_cache
|
||||
import logging
|
||||
import time
|
||||
from typing import Any, cast
|
||||
|
||||
import ciso8601
|
||||
from fnvhash import fnv1a_32
|
||||
from fnv_hash_fast import fnv1a_32
|
||||
from sqlalchemy import (
|
||||
JSON,
|
||||
BigInteger,
|
||||
@ -343,10 +342,9 @@ class EventData(Base):
|
||||
return bytes_result
|
||||
|
||||
@staticmethod
|
||||
@lru_cache
|
||||
def hash_shared_data_bytes(shared_data_bytes: bytes) -> int:
|
||||
"""Return the hash of json encoded shared data."""
|
||||
return cast(int, fnv1a_32(shared_data_bytes))
|
||||
return fnv1a_32(shared_data_bytes)
|
||||
|
||||
def to_native(self) -> dict[str, Any]:
|
||||
"""Convert to an event data dictionary."""
|
||||
@ -592,10 +590,9 @@ class StateAttributes(Base):
|
||||
return bytes_result
|
||||
|
||||
@staticmethod
|
||||
@lru_cache(maxsize=2048)
|
||||
def hash_shared_attrs_bytes(shared_attrs_bytes: bytes) -> int:
|
||||
"""Return the hash of json encoded shared attributes."""
|
||||
return cast(int, fnv1a_32(shared_attrs_bytes))
|
||||
return fnv1a_32(shared_attrs_bytes)
|
||||
|
||||
def to_native(self) -> dict[str, Any]:
|
||||
"""Convert to a state attributes dictionary."""
|
||||
|
@ -6,5 +6,5 @@
|
||||
"integration_type": "system",
|
||||
"iot_class": "local_push",
|
||||
"quality_scale": "internal",
|
||||
"requirements": ["sqlalchemy==2.0.8", "fnvhash==0.1.0"]
|
||||
"requirements": ["sqlalchemy==2.0.8", "fnv-hash-fast==0.3.1"]
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ certifi>=2021.5.30
|
||||
ciso8601==2.3.0
|
||||
cryptography==40.0.1
|
||||
dbus-fast==1.84.2
|
||||
fnvhash==0.1.0
|
||||
fnv-hash-fast==0.3.1
|
||||
ha-av==10.0.0
|
||||
hass-nabucasa==0.63.1
|
||||
hassil==1.0.6
|
||||
|
@ -729,7 +729,7 @@ flux_led==0.28.36
|
||||
|
||||
# homeassistant.components.homekit
|
||||
# homeassistant.components.recorder
|
||||
fnvhash==0.1.0
|
||||
fnv-hash-fast==0.3.1
|
||||
|
||||
# homeassistant.components.foobot
|
||||
foobot_async==1.0.0
|
||||
|
@ -557,7 +557,7 @@ flux_led==0.28.36
|
||||
|
||||
# homeassistant.components.homekit
|
||||
# homeassistant.components.recorder
|
||||
fnvhash==0.1.0
|
||||
fnv-hash-fast==0.3.1
|
||||
|
||||
# homeassistant.components.foobot
|
||||
foobot_async==1.0.0
|
||||
|
@ -2,7 +2,7 @@
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from fnvhash import fnv1a_32
|
||||
from fnv_hash_fast import fnv1a_32
|
||||
|
||||
from homeassistant.components.homekit.aidmanager import (
|
||||
AccessoryAidStorage,
|
||||
@ -386,7 +386,7 @@ async def test_aid_generation_no_unique_ids_handles_collision(
|
||||
await aid_storage.async_save()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch("fnvhash.fnv1a_32", side_effect=Exception):
|
||||
with patch("fnv_hash_fast.fnv1a_32", side_effect=Exception):
|
||||
aid_storage = AccessoryAidStorage(hass, config_entry)
|
||||
await aid_storage.async_initialize()
|
||||
|
||||
|
@ -6,7 +6,7 @@ import json
|
||||
import logging
|
||||
from typing import Any, TypedDict, cast, overload
|
||||
|
||||
from fnvhash import fnv1a_32
|
||||
from fnv_hash_fast import fnv1a_32
|
||||
from sqlalchemy import (
|
||||
BigInteger,
|
||||
Boolean,
|
||||
|
@ -11,7 +11,7 @@ import logging
|
||||
import time
|
||||
from typing import Any, TypedDict, cast, overload
|
||||
|
||||
from fnvhash import fnv1a_32
|
||||
from fnv_hash_fast import fnv1a_32
|
||||
from sqlalchemy import (
|
||||
BigInteger,
|
||||
Boolean,
|
||||
|
@ -12,7 +12,7 @@ import time
|
||||
from typing import Any, TypedDict, cast, overload
|
||||
|
||||
import ciso8601
|
||||
from fnvhash import fnv1a_32
|
||||
from fnv_hash_fast import fnv1a_32
|
||||
from sqlalchemy import (
|
||||
JSON,
|
||||
BigInteger,
|
||||
|
Loading…
x
Reference in New Issue
Block a user