Skip to content
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

Soft soft power off #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions power_api/power_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,17 @@ def get_rtc_time(self, format=Definition.TIME_FORMAT_EPOCH, timeout=RESPONSE_DEL
return time


def soft_power_off(self, timeout=RESPONSE_DELAY):
def soft_power_off(self, check=False, timeout=RESPONSE_DELAY):
"""
Function for checking any soft power off request is exist. If any
request exist, raspberry pi turns off by using "sudo shutdown" terminal
command in 5 seconds.

Parameters
-----------
check : boolean (optional)
check if it is time to perform a soft power off (default is False)

timeout : int (optional)
timeout while receiving the response (default is RESPONSE_DELAY)

Expand All @@ -1101,7 +1104,6 @@ def soft_power_off(self, timeout=RESPONSE_DELAY):
command.send_command()
delay_ms(timeout)
raw = command.receive_command(COMMAND_SIZE_FOR_UINT8)
result2 = 0
result = raw[PROTOCOL_HEADER_SIZE]

if result == Definition.SET_OK:
Expand All @@ -1112,8 +1114,9 @@ def soft_power_off(self, timeout=RESPONSE_DELAY):
result2 = raw[PROTOCOL_HEADER_SIZE]

if result2 == Definition.SET_OK:
print("Raspberry Pi will shutdown in 5 seconds!")
os.system("sleep 5 && sudo shutdown -h now")
if check is False:
print("Raspberry Pi will shutdown in 5 seconds!")
os.system("sleep 5 && sudo shutdown -h now")
return result2

return Definition.SET_FAILED
Expand Down