-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #497
base: master
Are you sure you want to change the base?
Solution #497
Conversation
mshmygel
commented
Jan 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this project! While your code is well-structured and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Awaiting Coroutines: The
run_sequence
andrun_parallel
functions return coroutines, which need to be awaited to execute them immediately. Please ensure that these are correctly awaited in your code. -
run_program
Method: This method is currently being passed a coroutine fromrun_parallel
, which is not handled correctly. You need to adjust the method to handle coroutines or change how programs are defined and executed. -
Message Handling: The
run_program
method attempts to await a list, which is not valid. You should iterate over the list and await eachMessage
individually if they are asynchronous operations. -
Imports and Definitions: Ensure that
Message
andMessageType
are correctly defined and imported in themessage.py
file to avoid errors when using them.
Once these issues are resolved, your code will be in great shape! Keep up the excellent work, and don't hesitate to reach out if you have any questions. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
@@ -1,64 +1,79 @@ | |||
import time | |||
import asyncio | |||
|
|||
from .message import MessageType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that MessageType
is correctly defined in the message.py
file. If it's not defined or imported correctly, it will cause an error when trying to use message_type.name
in the send_message
methods.
print("=====RUNNING PROGRAM======") | ||
for msg in program: | ||
self.send_msg(msg) | ||
await program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_program
method currently attempts to await a list, which is not valid. You should iterate over the program
list and await each Message
individually if they are asynchronous operations.
app/iot/service.py
Outdated
@@ -2,48 +2,53 @@ | |||
import string | |||
from typing import Protocol | |||
|
|||
from .message import Message, MessageType | |||
from app.iot.message import Message, MessageType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that Message
and MessageType
are correctly defined in the message.py
file. If they are not defined or imported correctly, it will cause errors when using them in the code.
|
||
# run the programs | ||
service.run_program(wake_up_program) | ||
service.run_program(sleep_program) | ||
await service.run_program(run_parallel(wake_up_program, sleep_program)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_program
method in IOTService
is designed to take a list of Message
objects, but here it's being passed the result of run_parallel
, which is a coroutine. You need to adjust the run_program
method to handle coroutines or change the way programs are defined and executed.
MessageType.PLAY_SONG, | ||
"Rick Astley - Never Gonna Give You Up" | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_sequence
function returns a coroutine, which should be awaited. Ensure that when you call run_sequence
, you await its result if you intend to execute it immediately.
), | ||
service.send_msg(toilet_id, MessageType.FLUSH), | ||
service.send_msg(toilet_id, MessageType.CLEAN), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, ensure that the sleep_program
coroutine is awaited if you intend to execute it immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your submission! Your code is on the right track, but there are a few critical issues that need attention to ensure full functionality:
-
Awaiting Coroutines: The
run_sequence
andrun_parallel
functions return coroutines that need to be awaited to execute them immediately. Make sure to awaitwake_up_program
andsleep_program
to ensure they run as expected. -
run_program
Method: This method is currently attempting to await a list directly, which is not valid. You should iterate over theprogram
list and await each coroutine individually. Consider usingawait asyncio.gather(*program)
ifprogram
is a list of coroutines. -
Handling Coroutines: The
run_program
method is passed a coroutine fromrun_parallel
, which is not handled correctly. Adjust the method to handle coroutines properly or redefine how programs are executed.
Your efforts are appreciated, and these adjustments will help you improve your understanding and implementation of asynchronous programming. Keep up the good work, and make sure to address these issues in future iterations to enhance your learning experience. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
async def run_program(self, program: list[Message]) -> None: | ||
print("=====RUNNING PROGRAM======") | ||
for msg in program: | ||
self.send_msg(msg) | ||
await program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_program
method attempts to await a list, which is not valid. You should iterate over the program
list and await each Message
individually if they are asynchronous operations.
wake_up_program = run_sequence( | ||
run_parallel( | ||
service.send_msg(hue_light_id, MessageType.SWITCH_ON), | ||
service.send_msg(speaker_id, MessageType.SWITCH_ON), | ||
), | ||
service.send_msg( | ||
speaker_id, | ||
MessageType.PLAY_SONG, | ||
"Rick Astley - Never Gonna Give You Up" | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_sequence
function returns a coroutine and should be awaited to execute it immediately. Ensure that wake_up_program
is awaited.
sleep_program = run_sequence( | ||
run_parallel( | ||
service.send_msg(hue_light_id, MessageType.SWITCH_OFF), | ||
service.send_msg(speaker_id, MessageType.SWITCH_OFF), | ||
), | ||
service.send_msg(toilet_id, MessageType.FLUSH), | ||
service.send_msg(toilet_id, MessageType.CLEAN), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_sequence
function returns a coroutine and should be awaited to execute it immediately. Ensure that sleep_program
is awaited.
|
||
# run the programs | ||
service.run_program(wake_up_program) | ||
service.run_program(sleep_program) | ||
await service.run_program(run_parallel(wake_up_program, sleep_program)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run_program
method is passed a coroutine from run_parallel
, which is not handled correctly. You need to adjust the method to handle coroutines or change how programs are defined and executed.