Skip to content

Commit 672d0a2

Browse files
committed
Add unknown devices
1 parent 07d3ace commit 672d0a2

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

example.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async def print_gateways(account: MyQAccount):
133133
"""Print gateways for account
134134
135135
Args:
136-
account (MyQAccount): Account for which to gateways
136+
account (MyQAccount): Account for which to retrieve gateways
137137
"""
138138
print(f" Gateways: {len(account.gateways)}")
139139
print(" ------------")
@@ -144,6 +144,21 @@ async def print_gateways(account: MyQAccount):
144144
print("------------------------------")
145145

146146

147+
async def print_other(account: MyQAccount):
148+
"""Print unknown/other devices for account
149+
150+
Args:
151+
account (MyQAccount): Account for which to retrieve unknown devices
152+
"""
153+
print(f" Other: {len(account.other)}")
154+
print(" ------------")
155+
if len(account.other) != 0:
156+
for idx, device in enumerate(account.other.values()):
157+
print_info(number=idx, device=device)
158+
159+
print("------------------------------")
160+
161+
147162
async def main() -> None:
148163
"""Create the aiohttp session and run the example."""
149164
logging.basicConfig(level=logging.DEBUG)

pymyq/account.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def covers(self) -> Dict[str, MyQGaragedoor]:
6666

6767
@property
6868
def lamps(self) -> Dict[str, MyQLamp]:
69-
"""Return only those devices that are covers."""
69+
"""Return only those devices that are lamps."""
7070
return {
7171
device_id: device
7272
for device_id, device in self.devices.items()
@@ -75,13 +75,23 @@ def lamps(self) -> Dict[str, MyQLamp]:
7575

7676
@property
7777
def gateways(self) -> Dict[str, MyQDevice]:
78-
"""Return only those devices that are covers."""
78+
"""Return only those devices that are gateways."""
7979
return {
8080
device_id: device
8181
for device_id, device in self.devices.items()
8282
if device.device_json["device_family"] == DEVICE_FAMILY_GATEWAY
8383
}
8484

85+
@property
86+
def other(self) -> Dict[str, MyQDevice]:
87+
"""Return only those devices that are covers."""
88+
return {
89+
device_id: device
90+
for device_id, device in self.devices.items()
91+
if type(device) is MyQDevice
92+
and device.device_json["device_family"] != DEVICE_FAMILY_GATEWAY
93+
}
94+
8595
async def _get_devices(self) -> None:
8696

8797
_LOGGER.debug("Retrieving devices for account %s", self.name or self.id)
@@ -136,20 +146,24 @@ async def _get_devices(self) -> None:
136146
device_json=device,
137147
state_update=state_update_timestmp,
138148
)
139-
elif device.get("device_family") == DEVICE_FAMILY_GATEWAY:
140-
_LOGGER.debug(
141-
"Adding new gateway with serial number %s", serial_number
142-
)
149+
else:
150+
if device.get("device_family") == DEVICE_FAMILY_GATEWAY:
151+
_LOGGER.debug(
152+
"Adding new gateway with serial number %s",
153+
serial_number,
154+
)
155+
else:
156+
_LOGGER.debug(
157+
"Adding unknown device family %s with serial number %s",
158+
device.get("device_family"),
159+
serial_number,
160+
)
161+
143162
new_device = MyQDevice(
144163
account=self,
145164
device_json=device,
146165
state_update=state_update_timestmp,
147166
)
148-
else:
149-
_LOGGER.warning(
150-
"Unknown device family %s", device.get("device_family")
151-
)
152-
new_device = None
153167

154168
if new_device:
155169
self._devices[serial_number] = new_device

pymyq/device.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,43 @@ def account(self) -> "MyQAccount":
3737
return self._account
3838

3939
@property
40-
def device_family(self) -> str:
40+
def device_family(self) -> Optional[str]:
4141
"""Return the family in which this device lives."""
42-
return self.device_json["device_family"]
42+
return self.device_json.get("device_family")
4343

4444
@property
45-
def device_id(self) -> str:
45+
def device_id(self) -> Optional[str]:
4646
"""Return the device ID (serial number)."""
47-
return self.device_json["serial_number"]
47+
return self.device_json.get("serial_number")
4848

4949
@property
50-
def device_platform(self) -> str:
50+
def device_platform(self) -> Optional[str]:
5151
"""Return the device platform."""
52-
return self.device_json["device_platform"]
52+
return self.device_json.get("device_platform")
5353

5454
@property
55-
def device_type(self) -> str:
55+
def device_type(self) -> Optional[str]:
5656
"""Return the device type."""
57-
return self.device_json[DEVICE_TYPE]
57+
return self.device_json.get(DEVICE_TYPE)
5858

5959
@property
6060
def firmware_version(self) -> Optional[str]:
6161
"""Return the family in which this device lives."""
6262
return self.device_json["state"].get("firmware_version")
6363

6464
@property
65-
def name(self) -> bool:
65+
def name(self) -> Optional[str]:
6666
"""Return the device name."""
67-
return self.device_json["name"]
67+
return self.device_json.get("name")
6868

6969
@property
7070
def online(self) -> bool:
7171
"""Return whether the device is online."""
72-
return self.device_json["state"].get("online") is True
72+
state = self.device_json.get("state")
73+
if state is None:
74+
return False
75+
76+
return state.get("online") is True
7377

7478
@property
7579
def parent_device_id(self) -> Optional[str]:

0 commit comments

Comments
 (0)