Skip to content

Commit

Permalink
Fixed module and test precip_intensity
Browse files Browse the repository at this point in the history
  • Loading branch information
briis committed Dec 3, 2023
1 parent 78a6db9 commit cf9c200
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 50 deletions.
80 changes: 39 additions & 41 deletions async_test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,53 +44,51 @@ async def main() -> None:
except Exception as err:
print(err)

cnt = 1
while cnt < 2:
try:
sensor_data: WeatherFlowSensorData = await weatherflow.async_fetch_sensor_data()
print("###########################################")
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("BEAUFORT: ", sensor_data.beaufort_description)
print("FREEZING ALT: ", sensor_data.freezing_altitude)
print("VOLTAGE: ", sensor_data.voltage)
print("BATTERY: ", sensor_data.battery)
print("POWER SAVE MODE: ", sensor_data.power_save_mode)
print("IS FREEZING: ", sensor_data.is_freezing)
print("IS LIGHTNING: ", sensor_data.is_lightning)
print("IS RAINING: ", sensor_data.is_raining)
print("UV INDEX: ", sensor_data.uv)
print("UV DESCRIPTION: ", sensor_data.uv_description)
print("STATION NAME: ", sensor_data.station_name)

cnt += 1

except Exception as err:
print(err)


try:
data: WeatherFlowForecastData = await weatherflow.async_get_forecast()
print("TEMPERATURE: ", data.temperature)
print("***** DAILY DATA *****")
for item in data.forecast_daily:
print(item.temperature, item.temp_low, item.icon, item.condition, item.precipitation_probability, item.precipitation, item.wind_bearing, item.wind_speed)
print("***** HOURLY DATA *****")
for item in data.forecast_hourly:
print(item.datetime, item.temperature, item.apparent_temperature, item.icon, item.condition, item.precipitation, item.precipitation_probability)
sensor_data: WeatherFlowSensorData = await weatherflow.async_fetch_sensor_data()
print("###########################################")
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("BEAUFORT: ", sensor_data.beaufort_description)
print("FREEZING ALT: ", sensor_data.freezing_altitude)
print("VOLTAGE: ", sensor_data.voltage)
print("BATTERY: ", sensor_data.battery)
print("POWER SAVE MODE: ", sensor_data.power_save_mode)
print("IS FREEZING: ", sensor_data.is_freezing)
print("IS LIGHTNING: ", sensor_data.is_lightning)
print("IS RAINING: ", sensor_data.is_raining)
print("UV INDEX: ", sensor_data.uv)
print("UV DESCRIPTION: ", sensor_data.uv_description)
print("STATION NAME: ", sensor_data.station_name)
print("PRECIP INTENSITY: ", sensor_data.precip_intensity)
print("PRECIP: ", sensor_data.precip)

except Exception as err:
print(err)


# try:
# data: WeatherFlowForecastData = await weatherflow.async_get_forecast()
# print("TEMPERATURE: ", data.temperature)
# print("***** DAILY DATA *****")
# for item in data.forecast_daily:
# print(item.temperature, item.temp_low, item.icon, item.condition, item.precipitation_probability, item.precipitation, item.wind_bearing, item.wind_speed)
# print("***** HOURLY DATA *****")
# for item in data.forecast_hourly:
# print(item.datetime, item.temperature, item.apparent_temperature, item.icon, item.condition, item.precipitation, item.precipitation_probability)

# except Exception as err:
# print(err)


if session is not None:
await session.close()

Expand Down
19 changes: 10 additions & 9 deletions pyweatherflow_forecast/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from __future__ import annotations
from datetime import datetime
import math
import logging
_LOGGER = logging.getLogger(__name__)

class WeatherFlowForecastData:
"""Class to hold forecast data."""
Expand Down Expand Up @@ -754,22 +756,21 @@ def precip_accum_local_yesterday(self) -> float:
@property
def precip_intensity(self) -> str:
"""Return a string with precipitation intensity."""
if self._precip in None:
if self._precip is None:
return None
_rain_rate = self._precip * 60

mapping_text = {
"1000": "extreme",
"50": "very_heavy",
"16": "heavy",
"4": "moderate",
"1": "light",
"0.01": "no_rain",
"0.25": "very_light",
"0.01": "none",
"1": "light",
"4": "moderate",
"16": "heavy",
"50": "very_heavy",
"1000": "extreme",
}

for key, value in mapping_text.items():
if _rain_rate < float(key):
if (self._precip * 60) < float(key):
return value
return None

Expand Down

0 comments on commit cf9c200

Please sign in to comment.