Skip to content

Commit

Permalink
Adding a config option to control the cooldown temp threshold.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnDamerell committed Aug 17, 2024
1 parent e62f2e3 commit 4a83118
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions bambu_octoeverywhere/bambuhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def RunBlocking(self, configPath, localStorageDir, repoRoot, devConfig_CanBeNone
stateTranslator = BambuStateTranslator(self.Logger)
self.NotificationHandler = NotificationsHandler(self.Logger, stateTranslator)
self.NotificationHandler.SetPrinterId(printerId)
self.NotificationHandler.SetBedCooldownThresholdTemp(self.Config.GetFloat(Config.GeneralSection, Config.GeneralBedCooldownThresholdTempC, Config.GeneralBedCooldownThresholdTempCDefault))
stateTranslator.SetNotificationHandler(self.NotificationHandler)

# Setup the command handler
Expand Down
28 changes: 28 additions & 0 deletions linux_host/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Config:
LogFileMaxSizeMbKey = "max_file_size_mb"
LogFileMaxCountKey = "max_file_count"

GeneralSection = "general"
GeneralBedCooldownThresholdTempC = "bed_cooldown_threshold_temp_celsius"
GeneralBedCooldownThresholdTempCDefault = 40.0


#
# Used for the local Moonraker plugin and companions.
Expand Down Expand Up @@ -79,6 +83,7 @@ class Config:
{ "Target": WebcamFlipH, "Comment": "Flips the webcam image horizontally. Valid values are True or False"},
{ "Target": WebcamFlipV, "Comment": "Flips the webcam image vertically. Valid values are True or False"},
{ "Target": WebcamRotation, "Comment": "Rotates the webcam image. Valid values are 0, 90, 180, or 270"},
{ "Target": GeneralBedCooldownThresholdTempC, "Comment": "The temperature in Celsius that the bed must be under to be considered cooled down. This is used to fire the Bed Cooldown Complete notification.."},
]


Expand Down Expand Up @@ -163,6 +168,29 @@ def GetInt(self, section:str, key:str, defaultValue) -> int:
return int(defaultValue)


# Gets a value from the config given the header and key.
# If the value isn't set, the default value is returned and the default value is saved into the config.
# If the default value is None, the default will not be written into the config.
def GetFloat(self, section:str, key:str, defaultValue) -> float:
# Use a try catch, so if a user sets an invalid value, it doesn't crash us.
result = None
try:
# If None is passed as the default, don't str it.
if defaultValue is not None:
defaultValue = str(defaultValue)

result = self.GetStr(section, key, defaultValue)
# If None is returned, don't int it, return None.
if result is None:
return None

return float(result)
except Exception as e:
self.Logger.error(f"Config settings error! {key} failed to get as float. Value was `{result}`. Resetting to default. "+str(e))
self.SetStr(section, key, str(defaultValue))
return float(defaultValue)


# Gets a value from the config given the header and key.
# If the value isn't set, the default value is returned and the default value is saved into the config.
# If the default value is None, the default will not be written into the config.
Expand Down
6 changes: 4 additions & 2 deletions moonraker_octoeverywhere/moonrakerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def __init__(self, logger:logging.Logger, config:Config, moonrakerConfigFilePath
self.JsonRpcWaitingContexts = {}

# Setup the Moonraker compat helper object.
self.MoonrakerCompat = MoonrakerCompat(self.Logger, printerId)
cooldownThresholdTempC = self.Config.GetFloat(Config.GeneralSection, Config.GeneralBedCooldownThresholdTempC, Config.GeneralBedCooldownThresholdTempCDefault)
self.MoonrakerCompat = MoonrakerCompat(self.Logger, printerId, cooldownThresholdTempC)

# Setup the non response message thread
# See _NonResponseMsgQueueWorker to why this is needed.
Expand Down Expand Up @@ -786,7 +787,7 @@ def SetSocketClosed(self):
# common OctoEverywhere logic.
class MoonrakerCompat:

def __init__(self, logger:logging.Logger, printerId:str) -> None:
def __init__(self, logger:logging.Logger, printerId:str, bedCooldownThresholdTempC:float) -> None:
self.Logger = logger

# This indicates if we are ready to process notifications, so we don't
Expand All @@ -800,6 +801,7 @@ def __init__(self, logger:logging.Logger, printerId:str) -> None:
# We pass our self as the Printer State Interface
self.NotificationHandler = NotificationsHandler(self.Logger, self)
self.NotificationHandler.SetPrinterId(printerId)
self.NotificationHandler.SetBedCooldownThresholdTemp(bedCooldownThresholdTempC)


def SetOctoKey(self, octoKey:str):
Expand Down
14 changes: 12 additions & 2 deletions octoeverywhere/notifications/bedcooldownwatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class BedCooldownWatcher:


def __init__(self, logger:logging.Logger, notificationHandler, printerStateInterface):

# Default the the bed is under ~100F, we will consider it cooled down.
# This can be changed in the config by the user.
self.CooldownThresholdTempC:float = 40.0

self.Logger = logger
self.NotificationHandler = notificationHandler
self.PrinterStateInterface = printerStateInterface
Expand Down Expand Up @@ -46,6 +51,11 @@ def Stop(self):
self._stopTimerUnderLock()


# Sets the temp that the bed must be under to be considered cooled down.
def SetBedCooldownThresholdTemp(self, tempC:float):
self.Logger.debug(f"Bed cooldown watcher, setting threshold temp to {tempC}")
self.CooldownThresholdTempC = tempC


def _stopTimerUnderLock(self):
if self.Timer is not None:
Expand All @@ -72,8 +82,8 @@ def _timerCallback(self):
isFirstTimerRead = self.IsFirstTimerRead
self.IsFirstTimerRead = False

# When the bed is under ~90F, we will consider it cooled down.
if bedTempCelsiusFloat > 33:
# Check if we are cooled down yet.
if bedTempCelsiusFloat > self.CooldownThresholdTempC:
# Keep waiting.
self.Logger.debug(f"Bed cooldown watcher, bed temp is {bedTempCelsiusFloat}. Waiting...")
return
Expand Down
5 changes: 5 additions & 0 deletions octoeverywhere/notificationshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def IsTrackingPrint(self) -> bool:
return self._IsPingTimerRunning()


# Sets the cooldown threshold temp
def SetBedCooldownThresholdTemp(self, tempC:float):
self.BedCooldownWatcher.SetBedCooldownThresholdTemp(tempC)


# A special case used by moonraker and bambu to restore the state of an ongoing print that we don't know of.
# What we want to do is check moonraker or bambu's current state and our current state, to see if there's anything that needs to be synced.
# Remember that we might be syncing because our service restarted during a print, or moonraker restarted, so we might already have
Expand Down

0 comments on commit 4a83118

Please sign in to comment.