def switch_device(self, device, currently):
switch_path = "/home/" + pi_link_pnl.target_user + "/Pigrow/scripts/switches/"
if currently == "ON":
switch_command = switch_path + device + "_off.py"
future_state = "OFF"
elif currently == "OFF":
switch_command = switch_path + device + "_on.py"
future_state = "ON"
else:
switch_command = "ERROR"
#if error show error message
if not switch_command == "ERROR":
#make dialogue box to ask if should switch the device
d = wx.MessageDialog(
self, "Are you sure you want to switch " + device + " to the " +
future_state + " poisition?\n\n\n " +
"Note: automated control scripts might " +
"\n switch this " + currently + " again " +
"\n if thier trigger conditions are met. "
, "Switch " + device + " " + future_state + "?"
, wx.OK | wx.CANCEL | wx.ICON_QUESTION)
answer = d.ShowModal()
d.Destroy()
#if user said ok then switch device
if (answer == wx.ID_OK):
out, error = MainApp.localfiles_ctrl_pannel.run_on_pi(switch_command)
print out # shows box with switch info from pigrow
if not error == "": print error
config_ctrl_pnl.currently_toedit = future_state #for if toggling within the dialog box
self.update_box_text()
config_ctrl_pnl.currently_new = future_state
config_ctrl_pnl.device_new = device
config_ctrl_pnl.gpio_new = config_ctrl_pnl.gpio_toedit
config_ctrl_pnl.wiring_new = config_ctrl_pnl.wiring_toedit
else:
d = wx.MessageDialog(self, "Error, current state not determined\n You must upload the settings to the pigrow before switching the device", "Error", wx.OK | wx.ICON_ERROR)
answer = d.ShowModal()
d.Destroy()
return "ERROR"
评论列表
文章目录