Skip to content

Commit 07d2d3a

Browse files
committed
Updated example to use account object
1 parent 5f9c439 commit 07d2d3a

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

example.py

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pymyq import login
88
from pymyq.account import MyQAccount
9-
from pymyq.api import API
109
from pymyq.errors import MyQError, RequestError
1110
from pymyq.garagedoor import STATE_CLOSED, STATE_OPEN
1211

@@ -42,22 +41,16 @@ def print_info(number: int, device):
4241
print(" ---------")
4342

4443

45-
async def print_garagedoors(api: API, account: MyQAccount):
44+
async def print_garagedoors(account: MyQAccount):
4645
"""Print garage door information and open/close if requested
4746
4847
Args:
49-
api (API): API object for the connection
5048
account (MyQAccount): Account for which to retrieve garage doors
5149
"""
52-
print(f" GarageDoors: {len(api.covers)}")
50+
print(f" GarageDoors: {len(account.covers)}")
5351
print(" ---------------")
54-
if len(api.covers) != 0:
55-
for idx, device_id in enumerate(
56-
device_id
57-
for device_id in api.covers
58-
if api.devices[device_id].account == account
59-
):
60-
device = api.devices[device_id]
52+
if len(account.covers) != 0:
53+
for idx, device in enumerate(account.covers.values()):
6154
print_info(number=idx, device=device)
6255

6356
if ISSUE_COMMANDS:
@@ -112,22 +105,16 @@ async def print_garagedoors(api: API, account: MyQAccount):
112105
print(" ------------------------------")
113106

114107

115-
async def print_lamps(api: API, account: MyQAccount):
108+
async def print_lamps(account: MyQAccount):
116109
"""Print lamp information and turn on/off if requested
117110
118111
Args:
119-
api (API): API object for the connection
120112
account (MyQAccount): Account for which to retrieve lamps
121113
"""
122-
print(f" Lamps: {len(api.lamps)}")
114+
print(f" Lamps: {len(account.lamps)}")
123115
print(" ---------")
124-
if len(api.lamps) != 0:
125-
for idx, device_id in enumerate(
126-
device_id
127-
for device_id in api.lamps
128-
if api.devices[device_id].account == account
129-
):
130-
device = api.devices[device_id]
116+
if len(account.lamps) != 0:
117+
for idx, device in enumerate(account.lamps.values()):
131118
print_info(number=idx, device=device)
132119

133120
if ISSUE_COMMANDS:
@@ -142,22 +129,16 @@ async def print_lamps(api: API, account: MyQAccount):
142129
print(" ------------------------------")
143130

144131

145-
async def print_gateways(api: API, account: MyQAccount):
132+
async def print_gateways(account: MyQAccount):
146133
"""Print gateways for account
147134
148135
Args:
149-
api (API): API object for the connection
150136
account (MyQAccount): Account for which to gateways
151137
"""
152-
print(f" Gateways: {len(api.gateways)}")
138+
print(f" Gateways: {len(account.gateways)}")
153139
print(" ------------")
154-
if len(api.gateways) != 0:
155-
for idx, device_id in enumerate(
156-
device_id
157-
for device_id in api.gateways
158-
if api.devices[device_id].account == account
159-
):
160-
device = api.devices[device_id]
140+
if len(account.gateways) != 0:
141+
for idx, device in enumerate(account.gateways.values()):
161142
print_info(number=idx, device=device)
162143

163144
print("------------------------------")
@@ -178,11 +159,11 @@ async def main() -> None:
178159

179160
# Get all devices listed with this account – note that you can use
180161
# api.covers to only examine covers or api.lamps for only lamps.
181-
await print_garagedoors(api=api, account=account)
162+
await print_garagedoors(account=account)
182163

183-
await print_lamps(api=api, account=account)
164+
await print_lamps(account=account)
184165

185-
await print_gateways(api=api, account=account)
166+
await print_gateways(account=account)
186167

187168
except MyQError as err:
188169
_LOGGER.error("There was an error: %s", err)

0 commit comments

Comments
 (0)