From 8b0eb67121e73df1972a142b5cdb861d6e076ee9 Mon Sep 17 00:00:00 2001 From: Shaun Tarves Date: Wed, 12 May 2021 11:54:21 -0400 Subject: [PATCH] Improved device parsing to use `None` when finding empty strings --- wyze_sdk/models/__init__.py | 3 ++- wyze_sdk/models/devices/base.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wyze_sdk/models/__init__.py b/wyze_sdk/models/__init__.py index f0df152..af04342 100644 --- a/wyze_sdk/models/__init__.py +++ b/wyze_sdk/models/__init__.py @@ -67,7 +67,8 @@ def _extract_attribute(self, name: str, others: dict) -> Any: Extracts a single value by name from a variety of locations in an object. """ if name in others: - return others.pop(name) + value = others.pop(name) + return value if value is not None and value != "" else None if 'property_list' in others: for property in others['property_list']: diff --git a/wyze_sdk/models/devices/base.py b/wyze_sdk/models/devices/base.py index 8b95564..c603eba 100644 --- a/wyze_sdk/models/devices/base.py +++ b/wyze_sdk/models/devices/base.py @@ -123,10 +123,16 @@ def __init__( else: self._ts = None if value is not None and not isinstance(value, self._definition.type): - try: - value = bool(distutils.util.strtobool(str(value))) if self._definition.type == bool else self._definition._type(value) - except ValueError: - self.logger.warning(f"could not cast value `{value}` into expected type {self._definition.type}") + if value == "": + value = None + else: + try: + value = bool(distutils.util.strtobool(str(value))) if self._definition.type == bool else self._definition._type(value) + except ValueError: + self.logger.warning(f"def {self._definition.pid}") + self.logger.warning(f"could not cast value `{value}` into expected type {self._definition.type}") + if value == "": + value = None self._value = value @property