mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 09:35:20 +02:00
add check for metar attributes
This commit is contained in:
@@ -210,7 +210,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
def temperature(self):
|
def temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
temp_c = self._observation['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 and self._metar_obs.temp:
|
||||||
temp_c = self._metar_obs.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)
|
||||||
@@ -221,7 +221,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
"""Return the current pressure."""
|
"""Return the current pressure."""
|
||||||
pressure_pa = self._observation['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 and self._metar_obs.press:
|
||||||
pressure_hpa = self._metar_obs.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
|
||||||
@@ -246,9 +246,8 @@ class NWSWeather(WeatherEntity):
|
|||||||
def wind_speed(self):
|
def wind_speed(self):
|
||||||
"""Return the current windspeed."""
|
"""Return the current windspeed."""
|
||||||
wind_m_s = self._observation['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 and self._metar_obs.wind_speed:
|
||||||
wind_m_s = self._metar_obs.wind_speed.value(units='MPS')
|
wind_m_s = self._metar_obs.wind_speed.value(units='MPS')
|
||||||
print(wind_m_s)
|
|
||||||
if wind_m_s is None:
|
if wind_m_s is None:
|
||||||
return None
|
return None
|
||||||
wind_m_hr = wind_m_s * 3600
|
wind_m_hr = wind_m_s * 3600
|
||||||
@@ -264,7 +263,8 @@ class NWSWeather(WeatherEntity):
|
|||||||
def wind_bearing(self):
|
def wind_bearing(self):
|
||||||
"""Return the current wind bearing (degrees)."""
|
"""Return the current wind bearing (degrees)."""
|
||||||
wind_bearing = self._observation['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
|
||||||
|
and self._metar_obs.wind_dir):
|
||||||
wind_bearing = self._metar_obs.wind_dir.value()
|
wind_bearing = self._metar_obs.wind_dir.value()
|
||||||
return wind_bearing
|
return wind_bearing
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
def visibility(self):
|
def visibility(self):
|
||||||
"""Return visibility."""
|
"""Return visibility."""
|
||||||
vis_m = self._observation['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 and self._metar_obs.vis:
|
||||||
vis_m = self._metar_obs.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
|
||||||
|
Reference in New Issue
Block a user