Skip to content

Commit c86f4d0

Browse files
committed
Lint fixes and udpates.
1 parent d7e6eb9 commit c86f4d0

19 files changed

Lines changed: 70 additions & 52 deletions

File tree

.github/workflows/pylint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ jobs:
4242
pylint ./octoprint_octoeverywhere/
4343
pylint ./moonraker_octoeverywhere/
4444
pylint ./elegoo_octoeverywhere/
45+
pylint ./elegoo_cc2_octoeverywhere/
4546
pylint ./bambu_octoeverywhere/
47+
pylint ./prusalink_octoeverywhere/
4648
pylint ./linux_host/
4749
pylint ./py_installer/
4850
pylint ./docker_octoeverywhere/
51+
pylint ./setup.py
4952
5053
- name: 👉 Pyright
5154
run: |
5255
pyright
5356
5457
- name: 🐶 Ruff
5558
run: |
56-
ruff check
59+
ruff check

.pylintrc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ disable=
66
C0103, # Disable bad attribute names
77
W0511, # Ignore TODOs
88
W0231, # Disable warns about init function calls
9-
W0601, # OctoPrint global function issues
109
R0901, # Too many ancestors
1110
R0904, # too-many-public-methods
1211
R0903, # too-few-public-methods
@@ -27,7 +26,6 @@ disable=
2726
R1724, # Unnecessary "else" after "break"
2827
R1715, # consider-using-get for dict gets.
2928
R1711, # Useless return at end of function or method (useless-return)
30-
E1136, # Value 'CaseInsensitiveDict' is unsubscriptable (unsubscriptable-object) - pyright and ruff will catch these.
3129

3230

3331

@@ -86,10 +84,6 @@ persistent=yes
8684
# version used to run pylint.
8785
# py-version=3.9
8886

89-
# When enabled, pylint would attempt to guess common misconfiguration and emit
90-
# user-friendly hints instead of false-positive error messages.
91-
suggestion-mode=yes
92-
9387
# Allow loading of arbitrary C extensions. Extensions are imported into the
9488
# active Python interpreter and may run arbitrary code.
9589
unsafe-load-any-extension=no
@@ -118,8 +112,6 @@ disable=raw-checker-failed,
118112
useless-suppression,
119113
deprecated-pragma,
120114
use-symbolic-message-instead,
121-
too-many-function-args,
122-
keyword-arg-before-vararg,
123115
use-dict-literal,
124116
too-many-lines
125117

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

elegoo_cc2_octoeverywhere/elegoocc2client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import socket
55
import threading
66
import time
7-
from typing import Any, Callable, Dict, List, Optional
7+
from typing import Any, Callable, Dict, List, Optional, cast
88

99
import paho.mqtt.client as mqtt
1010

@@ -528,8 +528,11 @@ def _HandleResponseMessage(self, msg:Dict[str, Any]) -> None:
528528
return
529529

530530
method = msg.get("method", None)
531-
resultObj = msg.get("result", None)
532-
if isinstance(resultObj, dict) and int(resultObj.get("error_code", 0)) == 0:
531+
rawResultObj = msg.get("result", None)
532+
resultObj:Optional[Dict[str, Any]] = None
533+
if isinstance(rawResultObj, dict):
534+
resultObj = cast(Dict[str, Any], rawResultObj)
535+
if resultObj is not None and int(resultObj.get("error_code", 0)) == 0:
533536
if method == 1001:
534537
self._HandleAttributesUpdate(resultObj)
535538
elif method == 1002:
@@ -547,11 +550,11 @@ def _HandleResponseMessage(self, msg:Dict[str, Any]) -> None:
547550

548551
error = msg.get("error", None)
549552
if isinstance(error, dict):
550-
context.SetResultAndEvent(resultObj if isinstance(resultObj, dict) else None, ResponseMsg.ELEGOO_CMD_ERROR_GENERIC, str(error))
551-
elif isinstance(resultObj, dict) and int(resultObj.get("error_code", 0)) != 0:
553+
context.SetResultAndEvent(resultObj, ResponseMsg.ELEGOO_CMD_ERROR_GENERIC, str(error))
554+
elif resultObj is not None and int(resultObj.get("error_code", 0)) != 0:
552555
context.SetResultAndEvent(resultObj, ResponseMsg.ELEGOO_CMD_ERROR_GENERIC, str(resultObj.get("error_msg", "Printer command failed.")))
553556
else:
554-
context.SetResultAndEvent(resultObj if isinstance(resultObj, dict) else {})
557+
context.SetResultAndEvent(resultObj if resultObj is not None else {})
555558

556559

557560
def _HandleStatusMessage(self, msg:Dict[str, Any], isAsyncStatus:bool) -> None:
@@ -734,6 +737,8 @@ def _GetConnectionContextToTry(self, isConnectAttemptFromEventBump:bool) -> Cc2C
734737
raise Exception("An IP address or hostname must be provided in the config for Elegoo CC2 Connect.")
735738

736739
self.SerialNumber = serialNumber
740+
if self.PortStr is None:
741+
raise Exception("A port must be provided in the config for Elegoo CC2 Connect.")
737742
return Cc2ConnectionContext(configIpOrHostname, self.PortStr, serialNumber, accessCode)
738743

739744

elegoo_cc2_octoeverywhere/elegoocc2discovery.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import socket
44
import time
5-
from typing import Any, Dict, List, Optional
5+
from typing import Any, Dict, List, Optional, cast
66

77
from octoeverywhere.sentry import Sentry
88

@@ -69,6 +69,7 @@ def _ParseDiscoveryResponse(logger:logging.Logger, data:bytes, ip:str) -> Option
6969
if not isinstance(result, dict):
7070
logger.debug("Elegoo CC2 discovery response missing result object: %s", msg)
7171
return None
72+
result = cast(Dict[str, Any], result)
7273
return ElegooCc2DiscoveryResult(
7374
ip,
7475
result.get("sn", None),

elegoo_cc2_octoeverywhere/elegoocc2models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import time
3-
from typing import Any, Dict, List, Optional, Tuple
3+
from typing import Any, Dict, List, Optional, Tuple, cast
44

55
from octoeverywhere.sentry import Sentry
66

@@ -149,6 +149,7 @@ def __init__(self, logger:logging.Logger) -> None:
149149
def OnUpdate(self, state:Dict[str, Any]) -> None:
150150
machineStatus = state.get("machine_status", {})
151151
if isinstance(machineStatus, dict):
152+
machineStatus = cast(Dict[str, Any], machineStatus)
152153
self.MachineStatus = self._GetIntOrNone(machineStatus, "status", self.MachineStatus)
153154
self.SubStatus = self._GetIntOrNone(machineStatus, "sub_status", self.SubStatus)
154155
exceptionStatus = machineStatus.get("exception_status", None)
@@ -158,6 +159,7 @@ def OnUpdate(self, state:Dict[str, Any]) -> None:
158159

159160
printStatus = state.get("print_status", {})
160161
if isinstance(printStatus, dict):
162+
printStatus = cast(Dict[str, Any], printStatus)
161163
self.FileName = self._GetStrOrNone(printStatus, "filename", self.FileName)
162164
self.TaskId = self._GetStrOrNone(printStatus, "uuid", self.TaskId)
163165
self.CurrentLayer = self._GetIntOrNone(printStatus, "current_layer", self.CurrentLayer)
@@ -169,21 +171,25 @@ def OnUpdate(self, state:Dict[str, Any]) -> None:
169171

170172
extruder = state.get("extruder", {})
171173
if isinstance(extruder, dict):
174+
extruder = cast(Dict[str, Any], extruder)
172175
self.HotendActual = self._GetFloatOrNone(extruder, "temperature", self.HotendActual)
173176
self.HotendTarget = self._GetFloatOrNone(extruder, "target", self.HotendTarget)
174177

175178
heaterBed = state.get("heater_bed", {})
176179
if isinstance(heaterBed, dict):
180+
heaterBed = cast(Dict[str, Any], heaterBed)
177181
self.BedActual = self._GetFloatOrNone(heaterBed, "temperature", self.BedActual)
178182
self.BedTarget = self._GetFloatOrNone(heaterBed, "target", self.BedTarget)
179183

180184
chamber = state.get("ztemperature_sensor", state.get("chamber", {}))
181185
if isinstance(chamber, dict):
186+
chamber = cast(Dict[str, Any], chamber)
182187
self.ChamberActual = self._GetFloatOrNone(chamber, "temperature", self.ChamberActual)
183188
self.ChamberTarget = self._GetFloatOrNone(chamber, "target", self.ChamberTarget)
184189

185190
led = state.get("led", {})
186191
if isinstance(led, dict):
192+
led = cast(Dict[str, Any], led)
187193
ledStatus = led.get("status", None)
188194
if ledStatus is not None:
189195
self.ChamberLightOn = int(ledStatus) > 0
@@ -239,7 +245,7 @@ def GetCurrentStatus(self) -> Tuple[Optional[str], Optional[str]]:
239245

240246
if self.MachineStatus == PrinterState.MACHINE_PRINTING:
241247
subState = self.SubStatus
242-
subStateStr = PrinterState.SubStatusMap.get(subState, None)
248+
subStateStr = PrinterState.SubStatusMap.get(subState, None) if subState is not None else None
243249
if subState in [
244250
PrinterState.SUB_EXTRUDER_PREHEATING,
245251
PrinterState.SUB_EXTRUDER_PREHEATING_2,
@@ -370,6 +376,7 @@ def OnUpdate(self, msg:Dict[str, Any]) -> None:
370376
self.HardwareVersion = msg.get("hardware_version", self.HardwareVersion)
371377
softwareVersion = msg.get("software_version", None)
372378
if isinstance(softwareVersion, dict):
379+
softwareVersion = cast(Dict[str, Any], softwareVersion)
373380
self.OtaVersion = softwareVersion.get("ota_version", self.OtaVersion)
374381
self.McuVersion = softwareVersion.get("mcu_version", self.McuVersion)
375382
self.SocVersion = softwareVersion.get("soc_version", self.SocVersion)

elegoo_octoeverywhere/elegooclient.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ def _ClientWorker(self):
326326

327327
# Get the current IP we want to try to connect with.
328328
self.WebSocketConnectionIp = self._GetIpForConnectionAttempt(isConnectAttemptFromEventBump)
329+
if self.WebSocketConnectionIp is None:
330+
raise Exception("No Elegoo printer IP address is available for this connection attempt.")
329331

330332
# We must update the local IP to what we are trying to connect to.
331333
# This var is system wides and helps other systems access the target client IP.

moonraker_octoeverywhere/systemconfigmanager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
import logging
4+
from typing import Set
45

56
class SystemConfigManager:
67

@@ -122,7 +123,7 @@ def EnsureAllowedServicesFile(logger:logging.Logger, klipperConfigDir:str, servi
122123
# Check if we are already in the file.
123124
with open(allowedServiceFile, "r", encoding="utf-8") as file:
124125
lines = file.readlines()
125-
existingEntries = set()
126+
existingEntries:Set[str] = set()
126127
for line in lines:
127128
entry = line.strip()
128129
if len(entry) != 0:

octoeverywhere/Webcam/quickcam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def Connect(self, url:str) -> None:
495495

496496
# Send the auth packet
497497
if authData is not None:
498-
self.SslSocket.write(authData)
498+
self.SslSocket.sendall(authData)
499499

500500

501501
# ~~ Interface Function ~~

octoeverywhere/Webcam/webcamstreaminstance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def _CustomBodyStreamRead(self) -> Optional[Buffer]:
7777
# TODO - I don't know why, but chrome seems to delay the rendering of the image until it gets two?
7878
# This could be something in the pipeline not flushing correctly, or other things. But for now, on the first send we double the image to make it render instantly.
7979
if self.IsFirstSend:
80-
imageChunkBuffer = Buffer(imageChunkBuffer.Get() + imageChunkBuffer.Get())
80+
imageChunkBufferBytes = imageChunkBuffer.ForceAsBytes()
81+
imageChunkBuffer = Buffer(imageChunkBufferBytes + imageChunkBufferBytes)
8182
self.IsFirstSend = False
8283
if self.Logger.isEnabledFor(logging.DEBUG):
8384
self.Logger.debug("QuickCam took %s seconds from octostream stream open to first image sent.", round(time.time() - self.StreamOpenTimeSec, 3))

0 commit comments

Comments
 (0)