|
|
@@ -107,6 +107,8 @@ ApplicationWindow { |
|
|
|
|
|
|
|
Page { |
|
|
|
property var lights: {} |
|
|
|
property var lastViewedLight: null |
|
|
|
|
|
|
|
header: Loader { |
|
|
|
sourceComponent: headerBar |
|
|
|
property var title: "Radiate" |
|
|
@@ -121,7 +123,8 @@ ApplicationWindow { |
|
|
|
delegate: ItemDelegate { |
|
|
|
width: parent.width |
|
|
|
onClicked: { |
|
|
|
stackView.push(lightPage, {light: model}); |
|
|
|
lastViewedLight = model.id; |
|
|
|
stackView.push(lightPage, {lightID: model.id}); |
|
|
|
} |
|
|
|
RowLayout { |
|
|
|
height: parent.height |
|
|
@@ -148,27 +151,6 @@ ApplicationWindow { |
|
|
|
BridgeConnectionConnector { |
|
|
|
id: connector |
|
|
|
|
|
|
|
function fetchLight(id) { |
|
|
|
const light = connector.get_light(id); |
|
|
|
lights[id] = light; |
|
|
|
|
|
|
|
for(var i = 0; i < lightListModel.count; i++) { |
|
|
|
const item = lightListModel.get(i); |
|
|
|
if(item.id == id) { |
|
|
|
console.log("replacing"); |
|
|
|
item.name = light.name.toString(); |
|
|
|
item.state = light.state; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log("new item"); |
|
|
|
|
|
|
|
const newItem = {name: light.name.toString(), state: light.state, id: id}; |
|
|
|
console.log(JSON.stringify(newItem)); |
|
|
|
lightListModel.append(newItem); |
|
|
|
} |
|
|
|
|
|
|
|
onLights_changed: { |
|
|
|
const ids = connector.get_lights(); |
|
|
|
lights = {}; |
|
|
@@ -181,6 +163,33 @@ ApplicationWindow { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function fetchLight(id) { |
|
|
|
const light = connector.get_light(id); |
|
|
|
lights[id] = light; |
|
|
|
|
|
|
|
for(var i = 0; i < lightListModel.count; i++) { |
|
|
|
const item = lightListModel.get(i); |
|
|
|
if(item.id == id) { |
|
|
|
console.log("replacing"); |
|
|
|
item.name = light.name.toString(); |
|
|
|
item.state = light.state; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log("new item"); |
|
|
|
|
|
|
|
const newItem = {name: light.name.toString(), state: light.state, id: id}; |
|
|
|
console.log(JSON.stringify(newItem)); |
|
|
|
lightListModel.append(newItem); |
|
|
|
} |
|
|
|
|
|
|
|
StackView.onActivating: { |
|
|
|
if(lastViewedLight) { |
|
|
|
fetchLight(lastViewedLight); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Component.onCompleted: { |
|
|
|
connector.init(settings.bridgeHost, settings.bridgeUsername); |
|
|
|
} |
|
|
@@ -191,6 +200,7 @@ ApplicationWindow { |
|
|
|
id: lightPage |
|
|
|
|
|
|
|
Page { |
|
|
|
property var lightID |
|
|
|
property var light |
|
|
|
header: Loader { |
|
|
|
sourceComponent: headerBar |
|
|
@@ -217,7 +227,7 @@ ApplicationWindow { |
|
|
|
id: onSwitch |
|
|
|
checked: light.state.on |
|
|
|
onToggled: { |
|
|
|
connector.start_set_light_on(light.id, checked); |
|
|
|
connector.start_set_light_on(lightID, checked); |
|
|
|
} |
|
|
|
} |
|
|
|
Item { Layout.preferredWidth: 2 } |
|
|
@@ -242,7 +252,7 @@ ApplicationWindow { |
|
|
|
|
|
|
|
onMoved: { |
|
|
|
console.log(value); |
|
|
|
connector.start_set_light_brightness(light.id, value); |
|
|
|
connector.start_set_light_brightness(lightID, value); |
|
|
|
} |
|
|
|
} |
|
|
|
Item { Layout.preferredWidth: 2 } |
|
|
@@ -270,7 +280,7 @@ ApplicationWindow { |
|
|
|
|
|
|
|
onMoved: { |
|
|
|
console.log(value); |
|
|
|
connector.start_set_light_hue(light.id, value); |
|
|
|
connector.start_set_light_hue(lightID, value); |
|
|
|
} |
|
|
|
} |
|
|
|
Item { Layout.preferredWidth: 2 } |
|
|
@@ -298,7 +308,7 @@ ApplicationWindow { |
|
|
|
|
|
|
|
onMoved: { |
|
|
|
console.log(value); |
|
|
|
connector.start_set_light_saturation(light.id, value); |
|
|
|
connector.start_set_light_saturation(lightID, value); |
|
|
|
} |
|
|
|
} |
|
|
|
Item { Layout.preferredWidth: 2 } |
|
|
@@ -310,18 +320,19 @@ ApplicationWindow { |
|
|
|
id: connector |
|
|
|
|
|
|
|
function fetchLight() { |
|
|
|
const newLight = connector.get_light(light.id); |
|
|
|
const newState = newLight.state; |
|
|
|
console.log(typeof light.state, typeof newState); |
|
|
|
console.log(light.state, newState); |
|
|
|
|
|
|
|
light.name = newLight.name.toString(); |
|
|
|
light.state = newState; |
|
|
|
const newLight = connector.get_light(lightID); |
|
|
|
if(!light) light = newLight; |
|
|
|
else { |
|
|
|
light.name = newLight.name; |
|
|
|
light.state = newLight.state; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onLights_changed: fetchLight() |
|
|
|
|
|
|
|
onLight_changed: fetchLight() |
|
|
|
|
|
|
|
Component.onCompleted: fetchLight() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|