Skip to content

Commit 0c76c4f

Browse files
authored
Merge pull request #37 from andrewsayre/dev
Do not require any device attributes and version bump
2 parents d7ffd3e + 2fca0d8 commit 0c76c4f

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

pysmartthings/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Define consts for the pysmartthings package."""
22

33
__title__ = "pysmartthings"
4-
__version__ = "0.7.2"
4+
__version__ = "0.7.3"

pysmartthings/device.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,31 @@ def __init__(self):
121121

122122
def apply_data(self, data: dict):
123123
"""Apply the given data dictionary."""
124-
self._device_id = data["deviceId"]
125-
self._name = data["name"]
126-
self._label = data["label"]
127-
self._location_id = data["locationId"]
124+
self._device_id = data.get("deviceId")
125+
self._name = data.get("name")
126+
self._label = data.get("label")
127+
self._location_id = data.get("locationId")
128128
self._room_id = data.get("roomId")
129-
self._type = data["type"]
129+
self._type = data.get("type")
130130
self._components.clear()
131131
self._capabilities.clear()
132-
for component in data["components"]:
133-
capabilities = [c["id"] for c in component["capabilities"]]
134-
component_id = component["id"]
135-
if component_id == "main":
136-
self._capabilities.extend(capabilities)
137-
else:
138-
self._components[component_id] = capabilities
132+
133+
components = data.get("components")
134+
if components:
135+
for component in components:
136+
capabilities = [c["id"] for c in component["capabilities"]]
137+
component_id = component["id"]
138+
if component_id == "main":
139+
self._capabilities.extend(capabilities)
140+
else:
141+
self._components[component_id] = capabilities
142+
139143
if self._type == DEVICE_TYPE_DTH:
140-
dth = data["dth"]
141-
self._device_type_id = dth["deviceTypeId"]
142-
self._device_type_name = dth["deviceTypeName"]
143-
self._device_type_network = dth["deviceNetworkType"]
144+
dth = data.get("dth")
145+
if dth:
146+
self._device_type_id = dth.get("deviceTypeId")
147+
self._device_type_name = dth.get("deviceTypeName")
148+
self._device_type_network = dth.get("deviceNetworkType")
144149

145150
def get_capability(self, *capabilities) -> Optional[str]:
146151
"""Return the first capability held by the device."""

0 commit comments

Comments
 (0)