Skip to content

Commit

Permalink
Improved device parsing to use None when finding empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Tarves committed May 12, 2021
1 parent bc11bce commit 8b0eb67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion wyze_sdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
14 changes: 10 additions & 4 deletions wyze_sdk/models/devices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b0eb67

Please sign in to comment.