mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix Ruuvi Gateway data being ignored when system is not using UTC time (#87384)
This commit is contained in:
parent
f6c76372ce
commit
72cb58e850
@ -2,12 +2,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import datetime
|
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
from home_assistant_bluetooth import BluetoothServiceInfoBleak
|
from home_assistant_bluetooth import BluetoothServiceInfoBleak
|
||||||
|
|
||||||
from homeassistant.components.bluetooth import (
|
from homeassistant.components.bluetooth import (
|
||||||
|
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS,
|
||||||
BaseHaRemoteScanner,
|
BaseHaRemoteScanner,
|
||||||
async_get_advertisement_callback,
|
async_get_advertisement_callback,
|
||||||
async_register_scanner,
|
async_register_scanner,
|
||||||
@ -15,7 +16,6 @@ from homeassistant.components.bluetooth import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||||
|
|
||||||
from .const import OLD_ADVERTISEMENT_CUTOFF
|
|
||||||
from .coordinator import RuuviGatewayUpdateCoordinator
|
from .coordinator import RuuviGatewayUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -46,10 +46,11 @@ class RuuviGatewayScanner(BaseHaRemoteScanner):
|
|||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_handle_new_data(self) -> None:
|
def _async_handle_new_data(self) -> None:
|
||||||
now = datetime.datetime.now()
|
now = time.time()
|
||||||
for tag_data in self.coordinator.data:
|
for tag_data in self.coordinator.data:
|
||||||
if now - tag_data.datetime > OLD_ADVERTISEMENT_CUTOFF:
|
data_age_seconds = now - tag_data.timestamp # Both are Unix time
|
||||||
# Don't process data that is older than 10 minutes
|
if data_age_seconds > FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS:
|
||||||
|
# Don't process stale data at all
|
||||||
continue
|
continue
|
||||||
anno = tag_data.parse_announcement()
|
anno = tag_data.parse_announcement()
|
||||||
self._async_on_advertisement(
|
self._async_on_advertisement(
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
"""Constants for the Ruuvi Gateway integration."""
|
"""Constants for the Ruuvi Gateway integration."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.bluetooth import (
|
|
||||||
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS,
|
|
||||||
)
|
|
||||||
|
|
||||||
DOMAIN = "ruuvi_gateway"
|
DOMAIN = "ruuvi_gateway"
|
||||||
SCAN_INTERVAL = timedelta(seconds=5)
|
SCAN_INTERVAL = timedelta(seconds=5)
|
||||||
OLD_ADVERTISEMENT_CUTOFF = timedelta(
|
|
||||||
seconds=FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user