Skip to content

Commit

Permalink
Fix edit dialog doesn't select printer
Browse files Browse the repository at this point in the history
  • Loading branch information
ralmn committed Feb 22, 2021
1 parent fab0fb9 commit 8c699a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion octoprint_ikea_tradfri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,17 @@ def getStateDataById(self, device_id):
device = self.getDeviceFromId(device_id)

code = "3312"

if device is None:
return dict(state=False)

if device is not None and 'type' in device and device['type'] is not None and device['type'] != "Outlet": #Light
code = "3311"

data = self.run_gateway_get_request('/15001/{}'.format(device_id))
state = data[code][0]["5850"] == 1
state = False
if code in data and len(data[code]) > 0 and "5850" in data[code][0]:
state = data[code][0]["5850"] == 1

res = dict(
state=state
Expand Down
4 changes: 4 additions & 0 deletions octoprint_ikea_tradfri/static/js/ikea-tradfri.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ $(function () {

self.devices = ko.observable([])

self.deviceIdEdit = ko.observable(-1);

self.iconClass = function (dev) {
let info = self.navInfo().state[dev.id()];
return "fa fa-" + dev.icon() + " state-icon " + (info && info.state ? 'state-on' : 'state-off');
Expand Down Expand Up @@ -243,6 +245,7 @@ $(function () {
dialog.find('[name="connect_palette2"]').prop('checked', device.connect_palette2 && device.connect_palette2());

dialog.modal();
self.deviceIdEdit(device.id());
}


Expand All @@ -254,6 +257,7 @@ $(function () {
let dialog = $('#ikea_tradfri_device_modal');
dialog.find('[name="device_name"]').val('Unnamed printer');
dialog.find('[name="device_id"]').val(-1);
self.deviceIdEdit(-1);
dialog.find('[name="on_done"]').prop('checked', true);
dialog.find('[name="on_failed"]').prop('checked', true);
dialog.find('[name="stop_timer"]').val(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<label class="control-label">{{ _('Ikea Device') }}</label>
<div class="controls">
<select name="device_id"
data-bind="optionsCaption: 'Choose...', optionsText: 'name', optionsValue: 'id', options: devices">
data-bind="optionsCaption: 'Choose...', optionsText: 'name', optionsValue: 'id', options: devices, value: deviceIdEdit, valueAllowUnset: true">
</select>
</div>
</div>
Expand Down

0 comments on commit 8c699a3

Please sign in to comment.