diff --git a/CHANGELOG.md b/CHANGELOG.md index bbe737a..96e1d2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.1 (2021-12-10) + +- Better handling of missing data points when parsing messages which may occure when the firmware revision changes + # 1.1.0 (2021-12-10) - Deprecated rain_amount_previous_minute due to name/units inconsistency diff --git a/pyproject.toml b/pyproject.toml index f3c9c2d..0c4fce1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyweatherflowudp" -version = "1.1.0" +version = "1.1.1" description = "An event-based asynchronous library to read UDP packets from Weatherflow weather systems on a local network without any reliance on the cloud." license = "MIT" authors = ["Nathan Spencer "] diff --git a/pyweatherflowudp/__init__.py b/pyweatherflowudp/__init__.py index e20f019..247ddea 100644 --- a/pyweatherflowudp/__init__.py +++ b/pyweatherflowudp/__init__.py @@ -1,2 +1,2 @@ """Asynchronous library to read UDP Packets from Weatherflow weather systems.""" -__version__ = "1.1.0" +__version__ = "1.1.1" diff --git a/pyweatherflowudp/device.py b/pyweatherflowudp/device.py index a332c98..72c90d9 100644 --- a/pyweatherflowudp/device.py +++ b/pyweatherflowudp/device.py @@ -27,10 +27,8 @@ DATA_DEBUG = "debug" DATA_EVENT = "evt" DATA_FIRMWARE_REVISION = "firmware_revision" -DATA_FS = "fs" DATA_HUB_RSSI = "hub_rssi" DATA_HUB_SN = "hub_sn" -DATA_MQTT_STATS = "mqtt_stats" DATA_OBSERVATION = "ob" DATA_OBSERVATIONS = "obs" DATA_RADIO_STATS = "radio_stats" @@ -143,10 +141,12 @@ def register_parse_handlers( @final def parse_message(self, data: dict[str, Any]) -> None: """Parse a device message.""" - if handler := self._parse_message_map.get(message_type := data[DATA_TYPE]): + if handler := self._parse_message_map.get( + message_type := data.get(DATA_TYPE, "") + ): if isinstance(handler, tuple): handler, field = handler - data = data[field] + data = data.get(field, {}) handler(data) else: _LOGGER.warning("Unhandled %s message: %s", message_type, data) @@ -163,9 +163,7 @@ def __init__(self, serial_number: str, data: dict[str, Any] | None = None) -> No self._reset_flags: str = "" self._seq: int = 0 - self._fs: list[int] = [] self._radio_stats: list[int] = [] - self._mqtt_stats: list[int] = [] self.register_parse_handlers({EVENT_STATUS_HUB: self.parse_hub_status}) @@ -184,15 +182,13 @@ def reset_flags(self) -> list[str] | None: def parse_hub_status(self, data: dict[str, Any]) -> None: """Parse hub status.""" - self._firmware_revision = data[DATA_FIRMWARE_REVISION] - self._uptime = data[DATA_UPTIME] - self._rssi = data[DATA_RSSI] - self._timestamp = data[DATA_TIMESTAMP] - self._reset_flags = data[DATA_RESET_FLAGS] - self._seq = data[DATA_SEQ] - self._fs = data[DATA_FS] - self._radio_stats = data[DATA_RADIO_STATS] - self._mqtt_stats = data[DATA_MQTT_STATS] + self._firmware_revision = data.get(DATA_FIRMWARE_REVISION) + self._uptime = data.get(DATA_UPTIME, 0) + self._rssi = data.get(DATA_RSSI, 0) + self._timestamp = data.get(DATA_TIMESTAMP) + self._reset_flags = data.get(DATA_RESET_FLAGS, "") + self._seq = data.get(DATA_SEQ, 0) + self._radio_stats = data.get(DATA_RADIO_STATS, []) assert self._timestamp @@ -282,14 +278,14 @@ def sensor_status(self) -> list[str]: def parse_device_status(self, data: dict[str, Any]) -> None: """Parse the device status.""" - self._timestamp = data[DATA_TIMESTAMP] - self._uptime = data[DATA_UPTIME] - self._voltage = data[DATA_VOLTAGE] - self._firmware_revision = data[DATA_FIRMWARE_REVISION] - self._rssi = data[DATA_RSSI] - self._hub_rssi = data[DATA_HUB_RSSI] - self._sensor_status = data[DATA_SENSOR_STATUS] - self._debug = truebool(data[DATA_DEBUG]) + self._timestamp = data.get(DATA_TIMESTAMP) + self._uptime = data.get(DATA_UPTIME, 0) + self._voltage = data.get(DATA_VOLTAGE, 0) + self._firmware_revision = data.get(DATA_FIRMWARE_REVISION) + self._rssi = data.get(DATA_RSSI, 0) + self._hub_rssi = data.get(DATA_HUB_RSSI, 0) + self._sensor_status = data.get(DATA_SENSOR_STATUS, 0) + self._debug = truebool(data.get(DATA_DEBUG)) if not self._initial_status: self._initial_status = True diff --git a/test/test_version.py b/test/test_version.py index 2edcba0..c60893e 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -4,4 +4,4 @@ def test_version() -> None: """Test version.""" - assert __version__ == "1.1.0" + assert __version__ == "1.1.1"