Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ruuvi Gateway data being ignored when system is not using UTC time #87384

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)