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

Enable relevant telemetry commands for enabled/disabled/unconfigured' #480

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading