Skip to content

Commit 44d2ce5

Browse files
committed
Implement setting country from main settings
1 parent 5fe5f09 commit 44d2ce5

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

octoprint_netconnectd/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def hostname(self):
5151

5252
def on_settings_save(self, data):
5353
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
54-
self.country = self._settings.get(["country"])
5554
self.address = self._settings.get(["socket"])
5655

5756
def get_settings_defaults(self):
@@ -78,6 +77,7 @@ def get_api_commands(self):
7877
configure_wifi=[],
7978
forget_wifi=[],
8079
reset=[],
80+
set_country=[],
8181
)
8282

8383
def is_api_adminonly(self):
@@ -97,6 +97,7 @@ def on_api_get(self, request):
9797
data = self._get_country_list()
9898
countries = data["countries"]
9999
country = data["country"]
100+
self.country = data["country"]
100101
except Exception as e:
101102
return jsonify(dict(error=str(e)))
102103

@@ -154,6 +155,9 @@ def on_api_command(self, command, data, adminRequired=True):
154155
elif command == "stop_ap":
155156
self._stop_ap()
156157

158+
elif command == "set_country":
159+
self._set_country(data["country"])
160+
157161
self._analytics.write_wifi_config_command(command, success=True)
158162

159163
except RuntimeError as e:
@@ -254,6 +258,12 @@ def _stop_ap(self):
254258
if not flag:
255259
raise RuntimeError("Error while stopping ap: " + content)
256260

261+
def _set_country(self, country_code):
262+
payload = {"country_code": country_code}
263+
flag, content = self._send_message("set_country", payload)
264+
if not flag:
265+
raise RuntimeError("Error while setting country: " + content)
266+
257267
def _send_message(self, message, data):
258268
obj = dict()
259269
obj[message] = data

octoprint_netconnectd/static/js/netconnectd.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,15 @@ $(function() {
349349
}, 80000);
350350
};
351351

352+
self.selectedValueChanged = function(context) {
353+
if (!self.canRun()) return;
354+
355+
country = context.country();
356+
if (country) {
357+
self._postCommand("set_country", {country: country});
358+
}
359+
};
360+
352361
self.sendReset = function() {
353362
if (!self.canRun()) return;
354363

octoprint_netconnectd/templates/netconnectd_settings.jinja2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
optionsText: 'country',
1515
optionsValue: 'code',
1616
optionsCaption: 'Select Country...',
17-
value: country"></select>
17+
value: country,
18+
event: {change: selectedValueChanged}">
19+
</select>
1820
</div>
1921
</div>
2022
<div class="pull-right" data-bind="visible: enableQualitySorting">

0 commit comments

Comments
 (0)