Fix weather handling in zamg (#85635)
* TypeError handling in weather * Check for None * Use walrus operator as proposedpull/93422/head
parent
1f6a601fc9
commit
5b0d53389c
|
@ -64,8 +64,16 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity):
|
||||||
def native_temperature(self) -> float | None:
|
def native_temperature(self) -> float | None:
|
||||||
"""Return the platform temperature."""
|
"""Return the platform temperature."""
|
||||||
try:
|
try:
|
||||||
return float(self.coordinator.data[self.station_id]["TL"]["data"])
|
if (
|
||||||
except (KeyError, ValueError):
|
value := self.coordinator.data[self.station_id]["TLAM"]["data"]
|
||||||
|
) is not None:
|
||||||
|
return float(value)
|
||||||
|
if (
|
||||||
|
value := self.coordinator.data[self.station_id]["TL"]["data"]
|
||||||
|
) is not None:
|
||||||
|
return float(value)
|
||||||
|
return None
|
||||||
|
except (KeyError, ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -73,7 +81,7 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Return the pressure."""
|
"""Return the pressure."""
|
||||||
try:
|
try:
|
||||||
return float(self.coordinator.data[self.station_id]["P"]["data"])
|
return float(self.coordinator.data[self.station_id]["P"]["data"])
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -81,21 +89,37 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Return the humidity."""
|
"""Return the humidity."""
|
||||||
try:
|
try:
|
||||||
return float(self.coordinator.data[self.station_id]["RFAM"]["data"])
|
return float(self.coordinator.data[self.station_id]["RFAM"]["data"])
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_wind_speed(self) -> float | None:
|
def native_wind_speed(self) -> float | None:
|
||||||
"""Return the wind speed."""
|
"""Return the wind speed."""
|
||||||
try:
|
try:
|
||||||
return float(self.coordinator.data[self.station_id]["FFAM"]["data"])
|
if (
|
||||||
except (KeyError, ValueError):
|
value := self.coordinator.data[self.station_id]["FFAM"]["data"]
|
||||||
|
) is not None:
|
||||||
|
return float(value)
|
||||||
|
if (
|
||||||
|
value := self.coordinator.data[self.station_id]["FFX"]["data"]
|
||||||
|
) is not None:
|
||||||
|
return float(value)
|
||||||
|
return None
|
||||||
|
except (KeyError, ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_bearing(self) -> float | str | None:
|
def wind_bearing(self) -> float | None:
|
||||||
"""Return the wind bearing."""
|
"""Return the wind bearing."""
|
||||||
try:
|
try:
|
||||||
return self.coordinator.data[self.station_id]["DD"]["data"]
|
if (
|
||||||
except (KeyError, ValueError):
|
value := self.coordinator.data[self.station_id]["DD"]["data"]
|
||||||
|
) is not None:
|
||||||
|
return float(value)
|
||||||
|
if (
|
||||||
|
value := self.coordinator.data[self.station_id]["DDX"]["data"]
|
||||||
|
) is not None:
|
||||||
|
return float(value)
|
||||||
|
return None
|
||||||
|
except (KeyError, ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue