Skip to content

Commit

Permalink
Enable relevant telemetry commands for enabled/disabled/unconfigured'
Browse files Browse the repository at this point in the history
  • Loading branch information
kageurufu committed Dec 11, 2024
1 parent 86d1f55 commit ceeebaf
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions klippy/extras/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,39 @@
import uuid


class KalicoTelemetryPrompt:
"Kalico extra prompting the user to enable or disable telemetry"
class KalicoTelementry:
TELEMETRY_ENDPOINT = "https://telemetry.kalico.gg/collect"

def __init__(self, config):
self.printer = config.get_printer()
self.enabled = config.getboolean("enabled", None)

gcode = self.printer.lookup_object("gcode")
gcode.register_command(
"ENABLE_TELEMETRY", self.cmd_ENABLE_TELEMETRY, True
)
gcode.register_command(
"DISABLE_TELEMETRY", self.cmd_DISABLE_TELEMETRY, True
"TELEMETRY_EXAMPLE", self.cmd_TELEMETRY_EXAMPLE, True
)

self.printer.register_event_handler("klippy:ready", self._handle_ready)
if self.enabled is not True:
gcode.register_command(
"ENABLE_TELEMETRY", self.cmd_ENABLE_TELEMETRY, True
)

def _handle_ready(self):
if self.enabled is not False:
gcode.register_command(
"DISABLE_TELEMETRY", self.cmd_DISABLE_TELEMETRY, True
)

if self.enabled is None:
self.printer.register_event_handler(
"klippy:ready", self._telemetry_prompt
)

if self.enabled:
self.printer.register_event_handler(
"klippy:ready", self._handle_ready
)

def _telemetry_prompt(self):
gcode = self.printer.lookup_object("gcode")

gcode.respond_info(
Expand Down Expand Up @@ -77,36 +93,8 @@ def cmd_DISABLE_TELEMETRY(self, gcmd):
"file with this setting and restart the printer."
)


class KalicoTelementry:
TELEMETRY_ENDPOINT = "https://telemetry.kalico.gg/collect"

def __init__(self, config):
self.printer = config.get_printer()
self.enabled = config.getboolean("enabled", None)

self.last_report = None

gcode = self.printer.lookup_object("gcode")

if self.enabled is not False:
gcode.register_command(
"TELEMETRY_EXAMPLE", self.cmd_TELEMETRY_EXAMPLE, True
)

if self.enabled is None:
self.telemetry_prompt = KalicoTelemetryPrompt(config)

elif self.enabled:
self.printer.register_event_handler(
"klippy:ready", self._handle_ready
)

def get_status(self, eventtime=None):
return {
"enabled": self.enabled,
"last_report": self.last_report,
}
return {"enabled": self.enabled}

def _handle_ready(self):
try:
Expand Down

0 comments on commit ceeebaf

Please sign in to comment.