Skip to content

Commit b343931

Browse files
author
Clara Richter
committed
sleep monitoring done
1 parent 6255dd7 commit b343931

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

getting_started/asyncio/power/sleep_monitoring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ async def main():
4040

4141
await rvr.on_did_sleep_notify(on_entered_soft_sleep)
4242

43-
# Sleep for 5 minutes such that we see the aforementioned events have time to occur
44-
await asyncio.sleep(300)
43+
# Sleep for 310 seconds such that we see the aforementioned events have time to occur
44+
await asyncio.sleep(310)
4545

4646

4747
loop.run_until_complete(

getting_started/observer/power/sleep_monitoring.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def main():
3333

3434
rvr.on_did_sleep_notify(on_entered_soft_sleep)
3535

36-
# Sleep for 5 minutes such that we see the aforementioned events have time to occur
37-
time.sleep(300)
36+
# Sleep for 310 seconds such that we see the aforementioned events have time to occur
37+
time.sleep(310)
38+
39+
rvr.close()
3840

3941

4042
main()

sphero_sdk/asyncio/client/dal/serial_async_dal.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,22 @@ async def on_command(self, did, cid, target, handler, timeout=None, outputs=[]):
8989
9090
"""
9191
async def wrapper(msg):
92-
response_dictionary = {}
93-
for param in sorted(outputs, key=lambda x: x.index):
94-
response_dictionary[param.name] = msg.unpack(
95-
param.data_type,
96-
count=param.size
97-
)
98-
99-
logger.debug("Command response wrapper invoked, returning: %s", response_dictionary)
100-
101-
await handler(response_dictionary)
92+
if len(outputs) > 0:
93+
response_dictionary = {}
94+
for param in sorted(outputs, key=lambda x: x.index):
95+
response_dictionary[param.name] = msg.unpack(
96+
param.data_type,
97+
count=param.size
98+
)
99+
100+
logger.debug("Command response wrapper invoked, returning: {}".format(response_dictionary))
101+
await handler(response_dictionary)
102+
else:
103+
logger.debug("No outputs expected, invoking callback.")
104+
await handler()
102105

103106
return ErrorCode.SUCCESS, bytearray()
104107

105-
logger.debug("Command worker added for %s","did:{} cid:{} target:{}".format(did, cid, target))
108+
logger.debug("Command worker added for DID:{} CID:{} Target:{}".format(did, cid, target))
106109

107-
self.handler.add_command_worker(did, cid, target, wrapper)
110+
self.handler.add_command_worker(did, cid, target, wrapper)

0 commit comments

Comments
 (0)