diff --git a/homeassistant/components/zamg/weather.py b/homeassistant/components/zamg/weather.py index 46913e90516..f94f9ca8a3a 100644 --- a/homeassistant/components/zamg/weather.py +++ b/homeassistant/components/zamg/weather.py @@ -64,8 +64,16 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity): def native_temperature(self) -> float | None: """Return the platform temperature.""" try: - return float(self.coordinator.data[self.station_id]["TL"]["data"]) - except (KeyError, ValueError): + if ( + 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 @property @@ -73,7 +81,7 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity): """Return the pressure.""" try: return float(self.coordinator.data[self.station_id]["P"]["data"]) - except (KeyError, ValueError): + except (KeyError, ValueError, TypeError): return None @property @@ -81,21 +89,37 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity): """Return the humidity.""" try: return float(self.coordinator.data[self.station_id]["RFAM"]["data"]) - except (KeyError, ValueError): + except (KeyError, ValueError, TypeError): return None @property def native_wind_speed(self) -> float | None: """Return the wind speed.""" try: - return float(self.coordinator.data[self.station_id]["FFAM"]["data"]) - except (KeyError, ValueError): + if ( + 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 @property - def wind_bearing(self) -> float | str | None: + def wind_bearing(self) -> float | None: """Return the wind bearing.""" try: - return self.coordinator.data[self.station_id]["DD"]["data"] - except (KeyError, ValueError): + if ( + 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