Skip to content

Commit

Permalink
Merge pull request #5 from briis/0.6.1-branch
Browse files Browse the repository at this point in the history
0.6.1 branch
  • Loading branch information
briis authored Oct 16, 2023
2 parents fe774e1 + 4d89d72 commit c4b19ef
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Release 0.6.1

**Date**: `2023-10-15`

### Changes

- Optimizing the *Fetch Sensor Data* by removing 1 call to the API per cycle.

## Release 0.6.0

**Date**: `2023-10-14`
Expand Down
40 changes: 22 additions & 18 deletions async_test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,28 @@ async def main() -> None:
except Exception as err:
print(err)

try:
sensor_data: WeatherFlowSensorData = await weatherflow.async_fetch_sensor_data()
print("TEMPERATURE:", sensor_data.air_temperature)
print("APPARENT:", sensor_data.feels_like)
print("WIND GUST:", sensor_data.wind_gust)
print("LAST LIGHTNING:", sensor_data.lightning_strike_last_epoch)
print("WIND DIRECTION: ", sensor_data.wind_direction)
print("WIND CARDINAL: ", sensor_data.wind_cardinal)
print("PRECIP CHECKED: ", sensor_data.precip_accum_local_day_final)
print("ABSOLUTE HUMIDITY: ", sensor_data.absolute_humidity)
print("VISIBILITY: ", sensor_data.visibility)
print("BEAUFORT: ", sensor_data.beaufort)
print("FREEZING ALT: ", sensor_data.freezing_altitude)
print("VOLTAGE: ", sensor_data.voltage)
print("BATTERY: ", sensor_data.battery)

except Exception as err:
print(err)
cnt = 1
while cnt < 3:
try:
sensor_data: WeatherFlowSensorData = await weatherflow.async_fetch_sensor_data()
print("TEMPERATURE:", sensor_data.air_temperature)
print("APPARENT:", sensor_data.feels_like)
print("WIND GUST:", sensor_data.wind_gust)
print("LAST LIGHTNING:", sensor_data.lightning_strike_last_epoch)
print("WIND DIRECTION: ", sensor_data.wind_direction)
print("WIND CARDINAL: ", sensor_data.wind_cardinal)
print("PRECIP CHECKED: ", sensor_data.precip_accum_local_day_final)
print("ABSOLUTE HUMIDITY: ", sensor_data.absolute_humidity)
print("VISIBILITY: ", sensor_data.visibility)
print("BEAUFORT: ", sensor_data.beaufort)
print("FREEZING ALT: ", sensor_data.freezing_altitude)
print("VOLTAGE: ", sensor_data.voltage)
print("BATTERY: ", sensor_data.battery)

cnt += 1

except Exception as err:
print(err)


try:
Expand Down
2 changes: 1 addition & 1 deletion pyweatherflow_forecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
)

__title__ = "pyweatherflow_forecast"
__version__ = "0.6.0"
__version__ = "0.6.1"
__author__ = "briis"
__license__ = "MIT"
28 changes: 17 additions & 11 deletions pyweatherflow_forecast/wffcst_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def api_request(self, url: str) -> dict[str, Any]:
async def async_api_request(self, url: str) -> dict[str, Any]:
"""Get data from WeatherFlow API."""

_LOGGER.debug("URL CALLED: %s", url)

is_new_session = False
if self.session is None:
self.session = aiohttp.ClientSession()
Expand Down Expand Up @@ -138,6 +140,7 @@ def __init__(
self._api_token = api_token
self._elevation = elevation
self._api = api
self._device_id = None
self._json_data = None
self._station_data: WeatherFlowStationData = None
self._device_data: WeatherFlowDeviceData = None
Expand Down Expand Up @@ -166,11 +169,13 @@ def fetch_sensor_data(self, voltage: float = None) -> list[WeatherFlowSensorData
device_data = None
sensor_data = None

station_url = f"{WEATHERFLOW_STATION_URL}{self._station_id}?token={self._api_token}"
json_station_data = self._api.api_request(station_url)
station_data: WeatherFlowStationData = _get_station(json_station_data)
if self._device_id is None:
station_url = f"{WEATHERFLOW_STATION_URL}{self._station_id}?token={self._api_token}"
json_station_data = self._api.api_request(station_url)
station_data: WeatherFlowStationData = _get_station(json_station_data)
self._device_id = station_data.device_id

if station_data is not None:
if self._device_id is not None:
_device_id = station_data.device_id
device_url = f"{WEATHERFLOW_DEVICE_URL}{_device_id}?token={self._api_token}"
json_device_data = self._api.api_request(device_url)
Expand All @@ -189,15 +194,16 @@ async def async_fetch_sensor_data(self) -> list[WeatherFlowSensorData]:
device_data = None
sensor_data = None

station_url = f"{WEATHERFLOW_STATION_URL}{self._station_id}?token={self._api_token}"
json_station_data = await self._api.async_api_request(station_url)
station_data: WeatherFlowStationData = _get_station(json_station_data)
if self._device_id is None:
station_url = f"{WEATHERFLOW_STATION_URL}{self._station_id}?token={self._api_token}"
json_station_data = await self._api.async_api_request(station_url)
station_data: WeatherFlowStationData = _get_station(json_station_data)
self._device_id = station_data.device_id

if station_data is not None:
_device_id = station_data.device_id
device_url = f"{WEATHERFLOW_DEVICE_URL}{_device_id}?token={self._api_token}"
if self._device_id is not None:
device_url = f"{WEATHERFLOW_DEVICE_URL}{self._device_id}?token={self._api_token}"
json_device_data = await self._api.async_api_request(device_url)
device_data: WeatherFlowDeviceData = _get_device_data(json_device_data, _device_id)
device_data: WeatherFlowDeviceData = _get_device_data(json_device_data, self._device_id)

if device_data is not None:
_voltage = device_data.voltage
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="pyweatherflow-forecast",
version="0.6.0",
version="0.6.1",
author="briis",
author_email="[email protected]",
description="Gets the weather forecast data from WeatherFlow",
Expand Down

0 comments on commit c4b19ef

Please sign in to comment.