Advertisement
robofred310

__init__.py

Oct 26th, 2021
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.44 KB | None | 0 0
  1. # coding=utf-8
  2. from __future__ import absolute_import
  3.  
  4. ### (Don't forget to remove me)
  5. # This is a basic skeleton for your plugin's __init__.py. You probably want to adjust the class name of your plugin
  6. # as well as the plugin mixins it's subclassing from. This is really just a basic skeleton to get you started,
  7. # defining your plugin as a template plugin, settings and asset plugin. Feel free to add or remove mixins
  8. # as necessary.
  9. #
  10. # Take a look at the documentation on what other plugin mixins are available.
  11.  
  12. import octoprint.plugin
  13.  
  14. import flask
  15.  
  16. class IrenePlugin(octoprint.plugin.SettingsPlugin,
  17.     octoprint.plugin.AssetPlugin,
  18.     octoprint.plugin.TemplatePlugin,
  19.     octoprint.plugin.SimpleApiPlugin
  20. ):
  21.  
  22.     ##~~ SettingsPlugin mixin
  23.  
  24.     def get_settings_defaults(self):
  25.         return {
  26.             # put your plugin's default settings here
  27.         }
  28.  
  29.     def get_template_configs(self):
  30.         return[
  31.             dict(type="navbar", custom_bindings=False),
  32.             dict(type="settings", custom_bindings=False),
  33.             dict(type="sidebar", custom_bindings=True)
  34.         ]
  35.  
  36.     ##~~ AssetPlugin mixin
  37.  
  38.     def get_assets(self):
  39.         # Define your plugin's asset files to automatically include in the
  40.         # core UI here.
  41.         return {
  42.             "js": ["js/irene.js"],
  43.             "css": ["css/irene.css"],
  44.             "less": ["less/irene.less"]
  45.         }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     def get_api_commands(self):
  54.         return dict(
  55.             update_speed=["speed"]
  56.         )
  57.  
  58.  
  59.  
  60.     def on_api_command(self, command, data):
  61.         if command == "update_speed":
  62.             speedStr = data.get('speed', None)
  63.             if speedStr != None:
  64.                 self._logger.info("Something happened here kir2koon {speedStr}".format(**locals()))
  65.                 speed = float(speedStr)
  66.                 if speed is not None:
  67.                     # self.update_fan_speed(speed)
  68.                     print("yo")
  69.  
  70.  
  71.  
  72.     # def on_api_command(self, command, data):
  73.     #     import flask
  74.     #     if speed == "command1":
  75.     #         parameter = "unset"
  76.     #         if "parameter" in data:
  77.     #             parameter = "set"
  78.     #         self._logger.info("command1 called, parameter is {parameter}".format(**locals()))
  79.     #     elif command == "command2":
  80.     #         self._logger.info("command2 called, some_parameter is {some_parameter}".format(**data))
  81.  
  82.     # def on_api_get(self, request):
  83.     #     return flask.jsonify(foo="bar")
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.     ##~~ Softwareupdate hook
  99.  
  100.     def get_update_information(self):
  101.         # Define the configuration for your plugin to use with the Software Update
  102.         # Plugin here. See https://docs.octoprint.org/en/master/bundledplugins/softwareupdate.html
  103.         # for details.
  104.         return {
  105.             "irene": {
  106.                 "displayName": "Irene Plugin",
  107.                 "displayVersion": self._plugin_version,
  108.  
  109.                 # version check: github repository
  110.                 "type": "github_release",
  111.                 "user": "robofred",
  112.                 "repo": "OctoPrint-Irene",
  113.                 "current": self._plugin_version,
  114.  
  115.                 # update method: pip
  116.                 "pip": "https://github.com/robofred/OctoPrint-Irene/archive/{target_version}.zip",
  117.             }
  118.         }
  119.  
  120.  
  121. # If you want your plugin to be registered within OctoPrint under a different name than what you defined in setup.py
  122. # ("OctoPrint-PluginSkeleton"), you may define that here. Same goes for the other metadata derived from setup.py that
  123. # can be overwritten via __plugin_xyz__ control properties. See the documentation for that.
  124. __plugin_name__ = "Irene Plugin"
  125.  
  126. # Starting with OctoPrint 1.4.0 OctoPrint will also support to run under Python 3 in addition to the deprecated
  127. # Python 2. New plugins should make sure to run under both versions for now. Uncomment one of the following
  128. # compatibility flags according to what Python versions your plugin supports!
  129. #__plugin_pythoncompat__ = ">=2.7,<3" # only python 2
  130. #__plugin_pythoncompat__ = ">=3,<4" # only python 3
  131. #__plugin_pythoncompat__ = ">=2.7,<4" # python 2 and 3
  132.  
  133.  
  134. __plugin_pythoncompat__ = ">=2.7,<4"
  135.  
  136. def __plugin_load__():
  137.     global __plugin_implementation__
  138.     __plugin_implementation__ = IrenePlugin()
  139.  
  140.     global __plugin_hooks__
  141.     __plugin_hooks__ = {
  142.         "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
  143.     }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement