Skip to content

Commit

Permalink
rename sensor to station; add an update timestamp to station
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw committed May 30, 2024
1 parent c95d0bf commit adaf289
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion aiocloudweather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


from .server import CloudWeatherListener
from .sensor import WeatherStation, Sensor
from .station import WeatherStation, Sensor
2 changes: 1 addition & 1 deletion aiocloudweather/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from types import NoneType

from aiocloudweather import CloudWeatherListener, WeatherStation
from aiocloudweather.sensor import Sensor
from aiocloudweather.station import Sensor

_LOGGER = logging.getLogger(__name__)

Expand Down
7 changes: 6 additions & 1 deletion aiocloudweather/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from __future__ import annotations

import logging
import time
from typing import Callable
from copy import deepcopy
from dataclasses import fields

from aiohttp import web

from aiocloudweather.sensor import WundergroundRawSensor, WeathercloudRawSensor, WeatherStation
from aiocloudweather.station import WundergroundRawSensor, WeathercloudRawSensor, WeatherStation

_LOGGER = logging.getLogger(__name__)
_CLOUDWEATHER_LISTEN_PORT = 49199
Expand All @@ -30,6 +31,7 @@ def __init__(self, port: int = _CLOUDWEATHER_LISTEN_PORT):

# internal data
self.last_values: dict[str, WeatherStation] = {}
self.last_updates: dict[str, float] = {}
self.new_dataset_cb: list[Callable[[WeatherStation], None]] = []

# storage
Expand Down Expand Up @@ -85,6 +87,9 @@ async def handler(self, request: web.BaseRequest) -> web.Response:
_LOGGER.debug("Found new station: %s", station_id)
self.stations.append(station_id)

self.last_updates[station_id] = time.monotonic()
dataset.last_update = self.last_updates[station_id]

try:
await self._new_dataset_cb(dataset)
except Exception as err: # pylint: disable=broad-except
Expand Down
3 changes: 2 additions & 1 deletion aiocloudweather/sensor.py → aiocloudweather/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from dataclasses import dataclass, field, fields
import logging
from types import NoneType
from typing import Final

from aiocloudweather.conversion import (
Expand Down Expand Up @@ -186,6 +185,8 @@ class WeatherStation:

station_id: str
station_key: str
update_time: float = field(default=None)

date_utc: str = field(default=None)

barometer: Sensor = field(default=None)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aiocloudweather.sensor import WeatherStation, WundergroundRawSensor, WeathercloudRawSensor
from aiocloudweather.station import WeatherStation, WundergroundRawSensor, WeathercloudRawSensor

def test_weather_station_from_wunderground():
raw_sensor_data = WundergroundRawSensor(
Expand Down

0 comments on commit adaf289

Please sign in to comment.