mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Make nested get() statements safe (#37965)
This commit is contained in:
parent
650d61e4f3
commit
619707e0e3
@ -99,7 +99,7 @@ class ECWeather(WeatherEntity):
|
||||
@property
|
||||
def temperature(self):
|
||||
"""Return the temperature."""
|
||||
if self.ec_data.conditions.get("temperature").get("value"):
|
||||
if self.ec_data.conditions.get("temperature", {}).get("value"):
|
||||
return float(self.ec_data.conditions["temperature"]["value"])
|
||||
if self.ec_data.hourly_forecasts[0].get("temperature"):
|
||||
return float(self.ec_data.hourly_forecasts[0]["temperature"])
|
||||
@ -113,35 +113,35 @@ class ECWeather(WeatherEntity):
|
||||
@property
|
||||
def humidity(self):
|
||||
"""Return the humidity."""
|
||||
if self.ec_data.conditions.get("humidity").get("value"):
|
||||
if self.ec_data.conditions.get("humidity", {}).get("value"):
|
||||
return float(self.ec_data.conditions["humidity"]["value"])
|
||||
return None
|
||||
|
||||
@property
|
||||
def wind_speed(self):
|
||||
"""Return the wind speed."""
|
||||
if self.ec_data.conditions.get("wind_speed").get("value"):
|
||||
if self.ec_data.conditions.get("wind_speed", {}).get("value"):
|
||||
return float(self.ec_data.conditions["wind_speed"]["value"])
|
||||
return None
|
||||
|
||||
@property
|
||||
def wind_bearing(self):
|
||||
"""Return the wind bearing."""
|
||||
if self.ec_data.conditions.get("wind_bearing").get("value"):
|
||||
if self.ec_data.conditions.get("wind_bearing", {}).get("value"):
|
||||
return float(self.ec_data.conditions["wind_bearing"]["value"])
|
||||
return None
|
||||
|
||||
@property
|
||||
def pressure(self):
|
||||
"""Return the pressure."""
|
||||
if self.ec_data.conditions.get("pressure").get("value"):
|
||||
if self.ec_data.conditions.get("pressure", {}).get("value"):
|
||||
return 10 * float(self.ec_data.conditions["pressure"]["value"])
|
||||
return None
|
||||
|
||||
@property
|
||||
def visibility(self):
|
||||
"""Return the visibility."""
|
||||
if self.ec_data.conditions.get("visibility").get("value"):
|
||||
if self.ec_data.conditions.get("visibility", {}).get("value"):
|
||||
return float(self.ec_data.conditions["visibility"]["value"])
|
||||
return None
|
||||
|
||||
@ -150,7 +150,7 @@ class ECWeather(WeatherEntity):
|
||||
"""Return the weather condition."""
|
||||
icon_code = None
|
||||
|
||||
if self.ec_data.conditions.get("icon_code").get("value"):
|
||||
if self.ec_data.conditions.get("icon_code", {}).get("value"):
|
||||
icon_code = self.ec_data.conditions["icon_code"]["value"]
|
||||
elif self.ec_data.hourly_forecasts[0].get("icon_code"):
|
||||
icon_code = self.ec_data.hourly_forecasts[0]["icon_code"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user