Skip to content

Commit 7244eea

Browse files
committed
Handle NaN weather codes
1 parent 2ee99f8 commit 7244eea

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:3.23.2
22

33
LABEL maintainer="Michael Oberdorf <info@oberdorf-itc.de>"
4-
LABEL site.local.program.version="1.3.1"
4+
LABEL site.local.program.version="1.3.2"
55

66
ENV TZ="UTC" \
77
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Container image: [DockerHub](https://hub.docker.com/r/oitc/weather2mqtt)
2626

2727
# Supported tags and respective `Dockerfile` links
2828

29-
* [`latest`, `1.3.1`](https://github.com/cybcon/docker.weather2mqtt/blob/v1.3.1/Dockerfile)
29+
* [`latest`, `1.3.2`](https://github.com/cybcon/docker.weather2mqtt/blob/v1.3.2/Dockerfile)
30+
* [`1.3.1`](https://github.com/cybcon/docker.weather2mqtt/blob/v1.3.1/Dockerfile)
3031
* [`1.3.0`](https://github.com/cybcon/docker.weather2mqtt/blob/v1.3.0/Dockerfile)
3132
* [`1.2.0`](https://github.com/cybcon/docker.weather2mqtt/blob/v1.2.0/Dockerfile)
3233
* [`1.1.1`](https://github.com/cybcon/docker.weather2mqtt/blob/v1.1.1/Dockerfile)

src/app/bin/lib/weather_codes/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
__author__ = "Michael Oberdorf <info@oberdorf-itc.de>"
1414
__status__ = "production"
1515
__date__ = "2026-01-11"
16-
__version_info__ = ("1", "0", "0")
16+
__version_info__ = ("1", "0", "1")
1717
__version__ = ".".join(__version_info__)
1818

1919
__all__ = ["WeatherCodes"]
2020

2121
import json
2222
import logging
23+
import math
2324
import os
2425

2526

@@ -53,7 +54,15 @@ def translate(self, code: int) -> str:
5354
:return: Human readable description
5455
"""
5556
# transform the code to int and str to fit to the json keys
56-
code = str(int(code))
57+
58+
# Avoid "cannot convert float NaN to integer"
59+
if math.isnan(code):
60+
self.logger.debug(f"Weather code {code} is NaN, returning 'Unknown weather code'")
61+
return "Unknown weather code"
62+
if isinstance(code, float):
63+
self.logger.debug(f"Weather code {code} is float, converting to int")
64+
code = int(code)
65+
code = str(code)
5766
self.logger.debug(f"Translating weather code {code}")
5867
translation = self.weather_codes.get(code, "Unknown weather code")
5968
self.logger.debug(f"Weather code {code} translated to '{translation}'")

src/app/bin/weather2mqtt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from lib.weather_codes import WeatherCodes
3030
from retry_requests import retry # seeAlso: https://pypi.org/project/retry-requests/
3131

32-
__version__ = "1.3.1"
32+
__version__ = "1.3.2"
3333
__script_path__ = os.path.dirname(__file__)
3434
__config_path__ = os.path.join(os.path.dirname(__script_path__), "etc")
3535
__local_tz__ = pytz.timezone("UTC")

0 commit comments

Comments
 (0)