Skip to content

Add ability to disable/enable the added switches/buttons #94

Description

@PartemImperium

In addition to adding HomeAssistant discovery to the base MQTT plugin's sensors it also adds some buttons/switches/actions.

def _on_emergency_stop(
self, topic, message, retained=None, qos=None, *args, **kwargs
):
self._logger.debug("Emergency stop message received: " + str(message))
if message:
self._printer.commands("M112")
def _on_cancel_print(
self, topic, message, retained=None, qos=None, *args, **kwargs
):
self._logger.debug("Cancel print message received: " + str(message))
if message:
self._printer.cancel_print()
def _on_pause_print(self, topic, message, retained=None, qos=None, *args, **kwargs):
self._logger.debug("Pause print message received: " + str(message))
if message:
self._printer.pause_print()
else:
self._printer.resume_print()
def _on_shutdown_system(self, topic, message, retained=None, qos=None, *args, **kwargs):
self._logger.debug("Shutdown print message received: " + str(message))
if message:
shutdown_command = self._settings.global_get(
["server", "commands", "systemShutdownCommand"]
)
try:
import sarge
sarge.run(shutdown_command, async_=True)
except Exception as e:
self._logger.info("Unable to run shutdown command: " + str(e))
def _on_restart_system(self, topic, message, retained=None, qos=None, *args, **kwargs):
self._logger.debug("Reboot print message received: " + str(message))
if message:
_command = self._settings.global_get(
["server", "commands", "systemRestartCommand"]
)
try:
import sarge
sarge.run(_command, async_=True)
except Exception as e:
self._logger.info("Unable to run system reboot command: " + str(e))
def _on_restart_server(self, topic, message, retained=None, qos=None, *args, **kwargs):
self._logger.debug("Restart print message received: " + str(message))
if message:
_command = self._settings.global_get(
["server", "commands", "serverRestartCommand"]
)
try:
import sarge
sarge.run(_command, async_=True)
except Exception as e:
self._logger.info("Unable to run system reboot command: " + str(e))
def _on_psu(self, topic, message, retained=None, qos=None, *args, **kwargs):
message = message.decode()
self._logger.debug("PSUControl message received: " + message)
if message == "True":
self._logger.info("Turning on PSU")
self.turn_psu_on()
else:
self._logger.info("Turning off PSU")
self.turn_psu_off()
It would be nice if like the base MQTT plugin you can disable/enable topics.

EDIT: I didnt know links to code would show the code inline so formatted better knowing that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions