Skip to content

Commit 4b2b787

Browse files
committed
Allow M999, bump version to 1.3.15, support self-update via GCODE.
1 parent 042ca7a commit 4b2b787

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "simplyprint-duet3d"
3-
version = "1.3.14"
3+
version = "1.3.15"
44
description = "SimplyPrint integration with any Duet3D powered RepRapFirmware printers "
55
readme = "README.rst"
66
license-files = ["LICENSE"]

simplyprint_duet3d/ota.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import sys
77
import tempfile
88
from importlib import metadata
9-
from typing import Optional
9+
from typing import Optional, TYPE_CHECKING
1010

1111
import aiohttp
1212

1313
from simplyprint_duet3d.gcode import GCodeCommand
1414

15+
if TYPE_CHECKING:
16+
from simplyprint_duet3d.printer import DuetPrinter
17+
1518

1619
def in_virtual_env() -> bool:
1720
"""Detect venvs (venv/virtualenv), pipx venvs, and conda envs."""
@@ -224,19 +227,22 @@ async def update_external_component(
224227

225228

226229
async def process_m997_command(
227-
logger: logging.Logger,
230+
client: "DuetPrinter",
228231
command: GCodeCommand,
229232
) -> bool:
230233
"""Process an M997 GCode command for OTA component updates."""
231234
s_param = next(filter(lambda p: p.startswith("S"), command.parameters), None)
232235
if not s_param:
233-
logger.error("M997 command missing S parameter.")
236+
client.logger.error("M997 command missing S parameter.")
234237
return False
235238
component_name = s_param[1:] # Remove 'S' prefix
236239
component_name = component_name.strip('"').lower()
237240

241+
if component_name == "self" or component_name == "simplyprint_duet3d":
242+
return await client.perform_self_upgrade()
243+
238244
if component_name not in SUPPORTED_COMPONENTS:
239-
logger.error(f"Component '{component_name}' is not supported for OTA updates.")
245+
client.logger.error(f"Component '{component_name}' is not supported for OTA updates.")
240246
return False
241247

242-
return await update_external_component(logger, component_name)
248+
return await update_external_component(client.logger, component_name)

simplyprint_duet3d/printer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ async def deferred_gcode(self, event: GcodeDemandData) -> None:
347347
"G29",
348348
"G90",
349349
"G91",
350+
"M999",
350351
]
351352

352353
response = []
@@ -359,14 +360,14 @@ async def deferred_gcode(self, event: GcodeDemandData) -> None:
359360
await self._notify_with_setup_code(),
360361
)
361362
elif item.code == "M997":
362-
await ota.process_m997_command(self.logger, item)
363+
await ota.process_m997_command(self, item)
363364
else:
364365
response.append("{!s} G-Code blocked".format(item.code))
365366
# TODO: notify sentry
366367

367368
self.logger.debug("Gcode response: {!s}".format("\n [gcode] ".join(response)))
368369

369-
async def _perform_self_upgrade(self) -> None:
370+
async def perform_self_upgrade(self) -> bool:
370371
"""Perform self-upgrade and restart the API."""
371372
self.logger.info("Performing self upgrade")
372373

@@ -378,7 +379,7 @@ async def _perform_self_upgrade(self) -> None:
378379
if ret == 0:
379380
self.logger.info("Plugin updated successfully, restarting API.")
380381
await self.on_api_restart()
381-
return
382+
return True
382383

383384
await self.push_notification(
384385
severity=NotificationEventSeverity.WARNING,
@@ -388,6 +389,8 @@ async def _perform_self_upgrade(self) -> None:
388389
),
389390
)
390391

392+
return False
393+
391394
async def on_gcode(self, event: GcodeDemandData) -> None:
392395
"""
393396
Receive GCode from SP and send GCode to duet.
@@ -839,4 +842,4 @@ async def on_plugin_install(self, event: PluginInstallDemandData) -> None:
839842
)
840843
return
841844

842-
await self._perform_self_upgrade()
845+
await self.perform_self_upgrade()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)