only get 1 observation - we dont use more than 1

This commit is contained in:
ktdad
2019-05-19 20:05:46 -04:00
parent 1e8bae264a
commit d2867844f4
2 changed files with 22 additions and 20 deletions

View File

@@ -180,12 +180,14 @@ class NWSWeather(WeatherEntity):
with async_timeout.timeout(10, loop=self.hass.loop): with async_timeout.timeout(10, loop=self.hass.loop):
_LOGGER.debug("Updating station observations %s", _LOGGER.debug("Updating station observations %s",
self._nws.station) self._nws.station)
self._observation = await self._nws.observations()
self._metar_obs = [ obs = await self._nws.observations(limit=1)
self._metar(obs['rawMessage']) self._observation = obs[0]
for obs in self._observation if 'rawMessage' in self._observation.keys():
if 'rawMessage' in obs.keys() self._metar_obs = self._metar(self._observation['rawMessage'])
] else:
self._metar_obs = None
_LOGGER.debug("Updating forecast") _LOGGER.debug("Updating forecast")
if self._mode == 'daynight': if self._mode == 'daynight':
self._forecast = await self._nws.forecast() self._forecast = await self._nws.forecast()
@@ -207,9 +209,9 @@ class NWSWeather(WeatherEntity):
@property @property
def temperature(self): def temperature(self):
"""Return the current temperature.""" """Return the current temperature."""
temp_c = self._observation[0]['temperature']['value'] temp_c = self._observation['temperature']['value']
if temp_c is None and self._metar_obs: if temp_c is None and self._metar_obs:
temp_c = self._metar_obs[0].temp.value(units='C') temp_c = self._metar_obs.temp.value(units='C')
if temp_c is not None: if temp_c is not None:
return convert_temperature(temp_c, TEMP_CELSIUS, TEMP_FAHRENHEIT) return convert_temperature(temp_c, TEMP_CELSIUS, TEMP_FAHRENHEIT)
return None return None
@@ -217,10 +219,10 @@ class NWSWeather(WeatherEntity):
@property @property
def pressure(self): def pressure(self):
"""Return the current pressure.""" """Return the current pressure."""
pressure_pa = self._observation[0]['seaLevelPressure']['value'] pressure_pa = self._observation['seaLevelPressure']['value']
if pressure_pa is None and self._metar_obs: if pressure_pa is None and self._metar_obs:
pressure_hpa = self._metar_obs[0].press.value(units='HPA') pressure_hpa = self._metar_obs.press.value(units='HPA')
if pressure_hpa is None: if pressure_hpa is None:
return None return None
pressure_pa = convert_pressure(pressure_hpa, PRESSURE_HPA, pressure_pa = convert_pressure(pressure_hpa, PRESSURE_HPA,
@@ -238,14 +240,14 @@ class NWSWeather(WeatherEntity):
@property @property
def humidity(self): def humidity(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return self._observation[0]['relativeHumidity']['value'] return self._observation['relativeHumidity']['value']
@property @property
def wind_speed(self): def wind_speed(self):
"""Return the current windspeed.""" """Return the current windspeed."""
wind_m_s = self._observation[0]['windSpeed']['value'] wind_m_s = self._observation['windSpeed']['value']
if wind_m_s is None and self._metar_obs: if wind_m_s is None and self._metar_obs:
wind_m_s = self._metar_obs[0].wind_speed.value(units='MPS') wind_m_s = self._metar_obs.wind_speed.value(units='MPS')
print(wind_m_s) print(wind_m_s)
if wind_m_s is None: if wind_m_s is None:
return None return None
@@ -261,9 +263,9 @@ class NWSWeather(WeatherEntity):
@property @property
def wind_bearing(self): def wind_bearing(self):
"""Return the current wind bearing (degrees).""" """Return the current wind bearing (degrees)."""
wind_bearing = self._observation[0]['windDirection']['value'] wind_bearing = self._observation['windDirection']['value']
if wind_bearing is None and self._metar_obs: if wind_bearing is None and self._metar_obs:
wind_bearing = self._metar_obs[0].wind_dir.value() wind_bearing = self._metar_obs.wind_dir.value()
return wind_bearing return wind_bearing
@property @property
@@ -274,16 +276,16 @@ class NWSWeather(WeatherEntity):
@property @property
def condition(self): def condition(self):
"""Return current condition.""" """Return current condition."""
time, weather = parse_icon(self._observation[0]['icon']) time, weather = parse_icon(self._observation['icon'])
cond, _ = convert_condition(time, weather) cond, _ = convert_condition(time, weather)
return cond return cond
@property @property
def visibility(self): def visibility(self):
"""Return visibility.""" """Return visibility."""
vis_m = self._observation[0]['visibility']['value'] vis_m = self._observation['visibility']['value']
if vis_m is None and self._metar_obs: if vis_m is None and self._metar_obs:
vis_m = self._metar_obs[0].vis.value(units='M') vis_m = self._metar_obs.vis.value(units='M')
if vis_m is None: if vis_m is None:
return None return None

View File

@@ -95,7 +95,7 @@ class MockNws():
"""Init mock nws.""" """Init mock nws."""
pass pass
async def observations(self): async def observations(self, limit):
"""Mock Observation.""" """Mock Observation."""
return OBS return OBS
@@ -330,7 +330,7 @@ class MockNws_Metar():
"""Init mock nws.""" """Init mock nws."""
pass pass
async def observations(self): async def observations(self, limit):
"""Mock Observation.""" """Mock Observation."""
return OBS_METAR return OBS_METAR