优化检测下位机升级的条件为升级klipper或者重启moonraker
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
|||||||
import asyncio
|
import asyncio
|
||||||
from .flash_tool import FlashTool
|
from .flash_tool import FlashTool
|
||||||
from ..confighelper import ConfigHelper
|
from ..confighelper import ConfigHelper
|
||||||
|
from ..common import KlippyState
|
||||||
from .klippy_apis import KlippyAPI
|
from .klippy_apis import KlippyAPI
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
@@ -29,9 +30,9 @@ class FirmwareUpdate:
|
|||||||
self.klipper_version: str = ""
|
self.klipper_version: str = ""
|
||||||
self.current_progress = 0
|
self.current_progress = 0
|
||||||
self.updating = False
|
self.updating = False
|
||||||
self.lock = True
|
self.need_check_update = True
|
||||||
self.server.register_event_handler(
|
self.server.register_event_handler(
|
||||||
"server:klippy_identified", self._handle_ready)
|
"server:klippy_started", self._on_klippy_startup)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def klippy_apis(self) -> KlippyAPI:
|
def klippy_apis(self) -> KlippyAPI:
|
||||||
@@ -40,17 +41,14 @@ class FirmwareUpdate:
|
|||||||
def is_updating(self) -> bool:
|
def is_updating(self) -> bool:
|
||||||
return self.updating
|
return self.updating
|
||||||
|
|
||||||
async def _handle_ready(self) -> None:
|
async def _on_klippy_startup(self, state: KlippyState) -> None:
|
||||||
if not self._is_firmware_dir_exists():
|
if not self.need_check_update or not self._is_firmware_dir_exists():
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
await self.build_mcu_info()
|
await self.build_mcu_info()
|
||||||
logging.info(f"{self.mcu_info}")
|
logging.info(f"{self.mcu_info}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"An error occurred during the building mcu info process: {e}")
|
logging.exception(f"An error occurred during the building mcu info process: {e}")
|
||||||
|
|
||||||
if self.lock:
|
|
||||||
self.lock = False
|
|
||||||
for mcu_data in self.mcu_info.values():
|
for mcu_data in self.mcu_info.values():
|
||||||
if mcu_data.get('need_update', False):
|
if mcu_data.get('need_update', False):
|
||||||
await self.start_update()
|
await self.start_update()
|
||||||
@@ -77,36 +75,25 @@ class FirmwareUpdate:
|
|||||||
self.updating = False
|
self.updating = False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"An error occurred during the update process: {e}")
|
logging.exception(f"An error occurred during the update process: {e}")
|
||||||
try:
|
|
||||||
self.updating = False
|
self.updating = False
|
||||||
logging.info("Power button enabled due to error recovery.")
|
|
||||||
except Exception as power_err:
|
|
||||||
logging.exception(f"Failed to enable power button during error recovery: {power_err}")
|
|
||||||
|
|
||||||
async def build_mcu_info(self) -> None:
|
async def build_mcu_info(self) -> None:
|
||||||
retries = 0
|
|
||||||
printer_info: Dict[str, Any] = {}
|
printer_info: Dict[str, Any] = {}
|
||||||
cfg_status: Dict[str, Any] = {}
|
cfg_status: Dict[str, Any] = {}
|
||||||
while retries < 5:
|
|
||||||
printer_info = await self.klippy_apis.get_klippy_info()
|
|
||||||
klipper_sta = printer_info.get("state", "")
|
|
||||||
if klipper_sta != "startup":
|
|
||||||
try:
|
try:
|
||||||
|
printer_info = await self.klippy_apis.get_klippy_info()
|
||||||
cfg_status = await self.klippy_apis.query_objects({'configfile': None})
|
cfg_status = await self.klippy_apis.query_objects({'configfile': None})
|
||||||
|
except self.server.error:
|
||||||
|
logging.exception("PanelDue initialization request failed")
|
||||||
config = cfg_status.get('configfile', {}).get('config', {})
|
config = cfg_status.get('configfile', {}).get('config', {})
|
||||||
self.klipper_version = printer_info.get("software_version", "").split('-')[0]
|
self.klipper_version = printer_info.get("software_version", "").split('-')[0]
|
||||||
|
try:
|
||||||
self._build_basic_mcu_info(config)
|
self._build_basic_mcu_info(config)
|
||||||
await self._update_mcu_versions()
|
await self._update_mcu_versions()
|
||||||
self._check_mcu_update_needed()
|
self._check_mcu_update_needed()
|
||||||
logging.info("MCU versions updated successfully.")
|
|
||||||
break
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
retries += 1
|
logging.exception(f"An error occurred while building MCU info: {e}")
|
||||||
await asyncio.sleep(1.)
|
|
||||||
else:
|
|
||||||
logging.info("Klipper is in startup state. Waiting...")
|
|
||||||
retries += 1
|
|
||||||
await asyncio.sleep(1.)
|
|
||||||
|
|
||||||
def _build_basic_mcu_info(self, config: Dict[str, Any]) -> None:
|
def _build_basic_mcu_info(self, config: Dict[str, Any]) -> None:
|
||||||
for mcu, value in config.items():
|
for mcu, value in config.items():
|
||||||
@@ -122,6 +109,7 @@ class FirmwareUpdate:
|
|||||||
if mcu == "mcu":
|
if mcu == "mcu":
|
||||||
self.min_version = mcu_data.get('min_firmware_version', "")
|
self.min_version = mcu_data.get('min_firmware_version', "")
|
||||||
if mcu_version:
|
if mcu_version:
|
||||||
|
self.need_check_update = False
|
||||||
short_version: str = mcu_version.split('-')[0]
|
short_version: str = mcu_version.split('-')[0]
|
||||||
if short_version.lower().startswith('v'):
|
if short_version.lower().startswith('v'):
|
||||||
short_version = short_version[1:]
|
short_version = short_version[1:]
|
||||||
|
@@ -258,6 +258,9 @@ class AppDeploy(BaseDeploy):
|
|||||||
if svc == "klipper":
|
if svc == "klipper":
|
||||||
kconn: Klippy = self.server.lookup_component("klippy_connection")
|
kconn: Klippy = self.server.lookup_component("klippy_connection")
|
||||||
svc = kconn.unit_name
|
svc = kconn.unit_name
|
||||||
|
firmware_manager = self.server.lookup_component("firmware_manager", None)
|
||||||
|
if firmware_manager is not None:
|
||||||
|
firmware_manager.need_check_update = True
|
||||||
await machine.do_service_action("restart", svc)
|
await machine.do_service_action("restart", svc)
|
||||||
|
|
||||||
async def _read_system_dependencies(self) -> List[str]:
|
async def _read_system_dependencies(self) -> List[str]:
|
||||||
|
Reference in New Issue
Block a user