Skip to content

Commit

Permalink
Adding a error condition and a fix for missing lightning epoch values
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor committed Aug 16, 2024
1 parent 24680b7 commit 6d21831
Show file tree
Hide file tree
Showing 5 changed files with 958 additions and 1 deletion.
4 changes: 3 additions & 1 deletion homeassistant/components/weatherflow_cloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class WeatherFlowCloudSensorEntityDescription(
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda data: datetime.fromtimestamp(
data.lightning_strike_last_epoch, tz=UTC
),
)
if data.lightning_strike_last_epoch is not None
else None,
),
)

Expand Down
35 changes: 35 additions & 0 deletions tests/components/weatherflow_cloud/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,38 @@ def mock_api():
mock_api_class.return_value = mock_api

yield mock_api


@pytest.fixture
def mock_api_with_lightning_error():
"""Fixture for Mock WeatherFlowRestAPI."""
get_stations_response_data = StationsResponseREST.from_json(
load_fixture("stations.json", DOMAIN)
)
get_forecast_response_data = WeatherDataForecastREST.from_json(
load_fixture("forecast.json", DOMAIN)
)
get_observation_response_data = ObservationStationREST.from_json(
load_fixture("station_observation_error.json", DOMAIN)
)

data = {
24432: WeatherFlowDataREST(
weather=get_forecast_response_data,
observation=get_observation_response_data,
station=get_stations_response_data.stations[0],
device_observations=None,
)
}

with patch(
"homeassistant.components.weatherflow_cloud.coordinator.WeatherFlowRestAPI",
autospec=True,
) as mock_api_class:
# Create an instance of AsyncMock for the API
mock_api = AsyncMock()
mock_api.get_all_data.return_value = data
# Patch the class to return our mock_api instance
mock_api_class.return_value = mock_api

yield mock_api
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"elevation": 2063.150146484375,
"is_public": true,
"latitude": 43.94962,
"longitude": -102.86831,
"obs": [
{
"air_density": 0.96139,
"air_temperature": 10.5,
"barometric_pressure": 782.8,
"brightness": 757,
"delta_t": 8.4,
"dew_point": -10.4,
"feels_like": 10.5,
"heat_index": 10.5,
"lightning_strike_count": 0,
"lightning_strike_count_last_1hr": 0,
"lightning_strike_count_last_3hr": 0,
"lightning_strike_last_distance": 26,
"precip": 0.0,
"precip_accum_last_1hr": 0.0,
"precip_accum_local_day": 0.0,
"precip_accum_local_day_final": 0.0,
"precip_accum_local_yesterday": 0.0,
"precip_accum_local_yesterday_final": 0.0,
"precip_analysis_type_yesterday": 0,
"precip_minutes_local_day": 0,
"precip_minutes_local_yesterday": 0,
"precip_minutes_local_yesterday_final": 0,
"pressure_trend": "steady",
"relative_humidity": 22,
"sea_level_pressure": 1006.2,
"solar_radiation": 6,
"station_pressure": 782.8,
"timestamp": 1708994629,
"uv": 0.03,
"wet_bulb_globe_temperature": 4.6,
"wet_bulb_temperature": 2.1,
"wind_avg": 1.4,
"wind_chill": 10.5,
"wind_direction": 203,
"wind_gust": 3.2,
"wind_lull": 0.3
}
],
"outdoor_keys": [
"timestamp",
"air_temperature",
"barometric_pressure",
"station_pressure",
"pressure_trend",
"sea_level_pressure",
"relative_humidity",
"precip",
"precip_accum_last_1hr",
"precip_accum_local_day",
"precip_accum_local_day_final",
"precip_accum_local_yesterday_final",
"precip_minutes_local_day",
"precip_minutes_local_yesterday_final",
"wind_avg",
"wind_direction",
"wind_gust",
"wind_lull",
"solar_radiation",
"uv",
"brightness",
"lightning_strike_last_epoch",
"lightning_strike_last_distance",
"lightning_strike_count",
"lightning_strike_count_last_1hr",
"lightning_strike_count_last_3hr",
"feels_like",
"heat_index",
"wind_chill",
"dew_point",
"wet_bulb_temperature",
"wet_bulb_globe_temperature",
"delta_t",
"air_density"
],
"public_name": "My Home Station",
"station_id": 24432,
"station_name": "My Home Station",
"station_units": {
"units_direction": "degrees",
"units_distance": "mi",
"units_other": "metric",
"units_precip": "in",
"units_pressure": "hpa",
"units_temp": "f",
"units_wind": "bft"
},
"status": {
"status_code": 0,
"status_message": "SUCCESS"
},
"timezone": "America/Denver"
}
Loading

0 comments on commit 6d21831

Please sign in to comment.