Skip to content

Commit

Permalink
Merge pull request #356 from puterboy/addAutoConnect
Browse files Browse the repository at this point in the history
Add auto connect option when Octoprint 'Connects'
  • Loading branch information
jneilliii authored Feb 9, 2024
2 parents 746def4 + 8d6a66c commit acbfed1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion octoprint_tplinksmartplug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ def on_after_startup(self):
else:
self._tplinksmartplug_logger.debug("powering on %s during startup failed." % (plug["ip"]))
self._reset_idle_timer()
self.loaded = True

def on_connect(self, *args, **kwargs): #Power up on connect
if hasattr(self, 'loaded') is False: return None
if self._settings.get_boolean(["connect_on_connect_request"]) is True:
self._tplinksmartplug_logger.debug("powering on due to 'Connect' request.")
for plug in self._settings.get(['arrSmartplugs']):
if plug["connect_on_connect"] is True and self._printer.is_closed_or_error():
self._tplinksmartplug_logger.debug("powering on %s due to 'Connect' request." % (plug["ip"]))
response = self.turn_on(plug["ip"])
if response.get("currentState", False) == "on":
self._tplinksmartplug_logger.debug("powering on %s during 'Connect' succeeded." % (plug["ip"]))
self._plugin_manager.send_plugin_message(self._identifier, response)
else:
self._tplinksmartplug_logger.debug("powering on %s during 'Connect' failed." % (plug["ip"]))
return None

##~~ SettingsPlugin mixin

Expand Down Expand Up @@ -1286,5 +1302,6 @@ def __plugin_load__():
"octoprint.comm.protocol.atcommand.sending": __plugin_implementation__.processAtCommand,
"octoprint.comm.protocol.temperatures.received": __plugin_implementation__.monitor_temperatures,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
"octoprint.printer.handle_connect": __plugin_implementation__.on_connect
}

0 comments on commit acbfed1

Please sign in to comment.