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

Add auto connect option when Octoprint 'Connects' #356

Merged
merged 13 commits into from
Feb 9, 2024
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v7
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed if no further activity occurs in 7 days'
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,15 @@ Check out my other plugins [here](https://plugins.octoprint.org/by_author/#jneil

### Sponsors
- Andreas Lindermayr
- [@Mearman](https://github.com/Mearman)
- [@TheTuxKeeper](https://github.com/thetuxkeeper)
- [@tideline3d](https://github.com/tideline3d/)
- [OctoFarm](https://octofarm.net/)
- [SimplyPrint](https://simplyprint.dk/)
- [SimplyPrint](https://simplyprint.io/)
- [Andrew Beeman](https://github.com/Kiendeleo)
- [Calanish](https://github.com/calanish)
- [Lachlan Bell](https://lachy.io/)
- [Johnny Bergdal](https://github.com/bergdahl)
- [Leigh Johnson](https://github.com/leigh-johnson)
- [Jonny Bergdahl](https://github.com/bergdahl)
- [Stephen Berry](https://github.com/berrystephenw)
- [Guyot François](https://github.com/iFrostizz)
- [Steve Dougherty](https://github.com/Thynix)
- [Flying Buffalo Aerial Photography](http://flyingbuffalo.info/)
## Support My Efforts
I, jneilliii, programmed this plugin for fun and do my best effort to support those that have issues with it, please return the favor and leave me a tip or become a Patron if you find this plugin helpful and want me to continue future development.

Expand Down
21 changes: 19 additions & 2 deletions octoprint_tplinksmartplug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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 @@ -747,7 +763,7 @@ def on_event(self, event, payload):
# File Uploaded Event
if event == Events.UPLOAD and self._settings.get_boolean(["event_on_upload_monitoring"]):
if payload.get("print", False) or self._settings.get_boolean(
["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
self._tplinksmartplug_logger.debug(
"File uploaded: %s. Turning enabled plugs on." % payload.get("name", ""))
self._tplinksmartplug_logger.debug(payload)
Expand Down Expand Up @@ -1215,5 +1231,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
}