Skip to content

Commit

Permalink
Fix Ruuvi Gateway data being ignored when system is not using UTC time (
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Feb 4, 2023
1 parent f6c7637 commit 72cb58e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 6 additions & 5 deletions homeassistant/components/ruuvi_gateway/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
from __future__ import annotations

from collections.abc import Callable
import datetime
import logging
import time

from home_assistant_bluetooth import BluetoothServiceInfoBleak

from homeassistant.components.bluetooth import (
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS,
BaseHaRemoteScanner,
async_get_advertisement_callback,
async_register_scanner,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback

from .const import OLD_ADVERTISEMENT_CUTOFF
from .coordinator import RuuviGatewayUpdateCoordinator

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,10 +46,11 @@ def __init__(

@callback
def _async_handle_new_data(self) -> None:
now = datetime.datetime.now()
now = time.time()
for tag_data in self.coordinator.data:
if now - tag_data.datetime > OLD_ADVERTISEMENT_CUTOFF:
# Don't process data that is older than 10 minutes
data_age_seconds = now - tag_data.timestamp # Both are Unix time
if data_age_seconds > FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS:
# Don't process stale data at all
continue
anno = tag_data.parse_announcement()
self._async_on_advertisement(
Expand Down
7 changes: 0 additions & 7 deletions homeassistant/components/ruuvi_gateway/const.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
"""Constants for the Ruuvi Gateway integration."""
from datetime import timedelta

from homeassistant.components.bluetooth import (
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS,
)

DOMAIN = "ruuvi_gateway"
SCAN_INTERVAL = timedelta(seconds=5)
OLD_ADVERTISEMENT_CUTOFF = timedelta(
seconds=FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
)

0 comments on commit 72cb58e

Please sign in to comment.