Fix temperature profiles saving string values

Closes #2520
This commit is contained in:
Gina Häußge committed 2018-03-27 16:23:13 +02:00
1 parent 2571d32134
commit 0cbad44055
4 files changed
+67 -4

No files matched your search

+10 -1
View File
@@ -424,7 +424,16 @@ def _saveSettings(data):
if "watched" in data["folder"]: s.setBaseFolder("watched", data["folder"]["watched"])
if "temperature" in data.keys():
if "profiles" in data["temperature"]: s.set(["temperature", "profiles"], data["temperature"]["profiles"])
if "profiles" in data["temperature"]:
result = []
for profile in data["temperature"]["profiles"]:
try:
profile["bed"] = int(profile["bed"])
profile["extruder"] = int(profile["extruder"])
except ValueError:
pass
result.append(profile)
s.set(["temperature", "profiles"], result)
if "cutoff" in data["temperature"]:
try:
cutoff = int(data["temperature"]["cutoff"])
+38 -1
View File
@@ -920,7 +920,8 @@ class Settings(object):
self._migrate_gcode_scripts,
self._migrate_core_system_commands,
self._migrate_serial_features,
self._migrate_resend_without_ok
self._migrate_resend_without_ok,
self._migrate_string_temperature_profile_values
)
for migrate in migrators:
@@ -932,6 +933,8 @@ class Settings(object):
def _migrate_gcode_scripts(self, config):
"""
Migrates an old development version of gcode scripts to the new template based format.
Added in 1.2.0
"""
dirty = False
@@ -956,6 +959,8 @@ class Settings(object):
def _migrate_printer_parameters(self, config):
"""
Migrates the old "printer > parameters" data structure to the new printer profile mechanism.
Added in 1.2.0
"""
default_profile = config["printerProfiles"]["defaultProfile"] if "printerProfiles" in config and "defaultProfile" in config["printerProfiles"] else dict()
dirty = False
@@ -1021,6 +1026,8 @@ class Settings(object):
"""
Migrates the old "server > baseUrl" and "server > scheme" configuration entries to
"server > reverseProxy > prefixFallback" and "server > reverseProxy > schemeFallback".
Added in 1.2.0
"""
if "server" in config.keys() and ("baseUrl" in config["server"] or "scheme" in config["server"]):
prefix = ""
@@ -1048,6 +1055,8 @@ class Settings(object):
"""
Migrates the old event configuration format of type "events > gcodeCommandTrigger" and
"event > systemCommandTrigger" to the new events format.
Added in 1.2.0
"""
if "events" in config.keys() and ("gcodeCommandTrigger" in config["events"] or "systemCommandTrigger" in config["events"]):
self._logger.info("Migrating config (event subscriptions)...")
@@ -1143,6 +1152,8 @@ class Settings(object):
If server commands for action is not yet set, migrates command. Otherwise only
deletes definition from custom system commands.
Added in 1.3.0
"""
changed = False
@@ -1189,6 +1200,8 @@ class Settings(object):
Migrates feature flags identified as serial specific from the feature to the serial config tree and vice versa.
If a flag already exists in the target tree, only deletes the copy in the source tree.
Added in 1.3.7
"""
changed = False
@@ -1232,6 +1245,8 @@ class Settings(object):
Migrates supportResendsWithoutOk flag from boolean to ("always", "detect", "never") value range.
True gets migrated to "always", False to "detect" (which is the new default).
Added in 1.3.7
"""
if "serial" in config and "supportResendsWithoutOk" in config["serial"] \
and config["serial"]["supportResendsWithoutOk"] not in ("always", "detect", "never"):
@@ -1243,6 +1258,28 @@ class Settings(object):
return True
return False
def _migrate_string_temperature_profile_values(self, config):
"""
Migrates/fixes temperature profile wrongly saved with strings instead of ints as temperature values.
Added in 1.3.8
"""
if "temperature" in config and "profiles" in config["temperature"]:
profiles = config["temperature"]["profiles"]
if any(map(lambda x: not isinstance(x.get("extruder", 0), int) or not isinstance(x.get("bed", 0), int),
profiles)):
result = []
for profile in profiles:
try:
profile["extruder"] = int(profile["extruder"])
profile["bed"] = int(profile["bed"])
except ValueError:
pass
result.append(profile)
config["temperature"]["profiles"] = result
return True
return False
def backup(self, suffix, path=None):
import shutil
@@ -729,6 +729,23 @@ $(function() {
});
return result;
}
},
temperature: {
profiles: function() {
var result = [];
_.each(self.temperature_profiles(), function(profile) {
try {
result.push({
name: profile.name,
extruder: Math.floor(_.isNumber(profile.extruder) ? profile.extruder : parseInt(profile.extruder)),
bed: Math.floor(_.isNumber(profile.bed) ? profile.bed : parseInt(profile.bed))
});
} catch (ex) {
// ignore
}
});
return result;
}
}
};
@@ -40,11 +40,11 @@
<input type="text" class="span12 text-right" data-bind="value: name">
</div>
<div class="input-append span3">
<input type="number" class="input-mini text-right" data-bind="value: extruder">
<input type="number" min="0" step="1" class="input-mini text-right" data-bind="value: extruder">
<span class="add-on">&deg;C</span>
</div>
<div class="input-append span3">
<input type="number" class="input-mini text-right" data-bind="value: bed">
<input type="number" min="0" step="1" class="input-mini text-right" data-bind="value: bed">
<span class="add-on">&deg;C</span>
</div>
<div class="span2">