♻ minor refactorings
* validate custom identifiers for as_dict method * minor performance improvement
This commit is contained in:
1 parent
79cd98d467
commit
46d4a73955
2 files changed
+16
-7
No files matched your search
@@ -891,6 +891,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
def _addTemperatureData(self, tools=None, bed=None, chamber=None, custom=None):
|
||||
if tools is None:
|
||||
tools = dict()
|
||||
if custom is None:
|
||||
custom = dict()
|
||||
|
||||
data = dict(time=int(time.time()))
|
||||
for tool in tools.keys():
|
||||
@@ -899,10 +901,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
data["bed"] = self._dict(actual=bed[0], target=bed[1])
|
||||
if chamber is not None and isinstance(chamber, tuple):
|
||||
data["chamber"] = self._dict(actual=chamber[0], target=chamber[1])
|
||||
if custom is None:
|
||||
custom = dict()
|
||||
for identifier in custom.keys():
|
||||
data[identifier] = self._dict(actual=custom[identifier][0], target=custom[identifier][1])
|
||||
for identifier, values in custom.items():
|
||||
data[identifier] = self._dict(actual=values[0], target=values[1])
|
||||
|
||||
self._temps.append(data)
|
||||
|
||||
@@ -1060,8 +1060,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
"""
|
||||
self._addLog(to_unicode(message, "utf-8", errors="replace"))
|
||||
|
||||
def on_comm_temperature_update(self, temp, bedTemp, chamberTemp, customTemp):
|
||||
self._addTemperatureData(tools=copy.deepcopy(temp), bed=copy.deepcopy(bedTemp), chamber=copy.deepcopy(chamberTemp), custom=copy.deepcopy(customTemp))
|
||||
def on_comm_temperature_update(self, tools, bed, chamber, custom=None):
|
||||
if custom is None:
|
||||
custom = dict()
|
||||
self._addTemperatureData(tools=copy.deepcopy(tools),
|
||||
bed=copy.deepcopy(bed),
|
||||
chamber=copy.deepcopy(chamber),
|
||||
custom=copy.deepcopy(custom))
|
||||
|
||||
def on_comm_position_update(self, position, reason=None):
|
||||
payload = dict(reason=reason)
|
||||
|
||||
@@ -279,6 +279,8 @@ class PositionRecord(object):
|
||||
return dict((attr, getattr(self, attr)) for attr in attrs)
|
||||
|
||||
class TemperatureRecord(object):
|
||||
RESERVED_IDENTIFIER_REGEX = re.compile("[0-9]+|[bc]")
|
||||
|
||||
def __init__(self):
|
||||
self._tools = dict()
|
||||
self._bed = (None, None)
|
||||
@@ -302,6 +304,8 @@ class TemperatureRecord(object):
|
||||
self._chamber = self._to_new_tuple(current, actual, target)
|
||||
|
||||
def set_custom(self, identifier, actual=None, target=None):
|
||||
if self.RESERVED_IDENTIFIER_REGEX.match(identifier):
|
||||
raise ValueError("{} is a reserved identifier".format(identifier))
|
||||
current = self._custom.get(identifier, (None, None))
|
||||
self._custom[identifier] = self._to_new_tuple(current, actual, target)
|
||||
|
||||
@@ -340,7 +344,7 @@ class TemperatureRecord(object):
|
||||
custom = self.custom
|
||||
for identifier, data in custom.items():
|
||||
result[identifier] = dict(actual=data[0],
|
||||
target=data[1])
|
||||
target=data[1])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in new issue
Block a user