Merge PR #126: Some improvements in the main page delegates
This commit is contained in:
commit
ab986f62d7
@ -86,11 +86,13 @@ MainPageTile {
|
|||||||
switch (model.name) {
|
switch (model.name) {
|
||||||
case "sensor":
|
case "sensor":
|
||||||
case "weather":
|
case "weather":
|
||||||
|
case "smartmeter":
|
||||||
case "smartmeterconsumer":
|
case "smartmeterconsumer":
|
||||||
case "smartmeterproducer":
|
case "smartmeterproducer":
|
||||||
case "extendedsmartmeterconsumer":
|
case "extendedsmartmeterconsumer":
|
||||||
case "extendedsmartmeterproducer":
|
case "extendedsmartmeterproducer":
|
||||||
return labelComponent;
|
return sensorComponent;
|
||||||
|
// return labelComponent;
|
||||||
|
|
||||||
case "light":
|
case "light":
|
||||||
case "media":
|
case "media":
|
||||||
@ -391,7 +393,6 @@ MainPageTile {
|
|||||||
|
|
||||||
property var device: devicesProxy.get(0)
|
property var device: devicesProxy.get(0)
|
||||||
property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
||||||
property var state: deviceClass ? device.states.getState(deviceClass.stateTypes.findByName("temperature").id) : null
|
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: parent.device.name
|
text: parent.device.name
|
||||||
@ -399,22 +400,114 @@ MainPageTile {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Label {
|
Component {
|
||||||
font.pixelSize: app.largeFont
|
id: sensorComponent
|
||||||
color: app.accentColor
|
MouseArea {
|
||||||
Layout.fillWidth: true
|
id: sensorsRoot
|
||||||
horizontalAlignment: Text.AlignRight
|
property int currentDevice: 0
|
||||||
text: {
|
|
||||||
if (devicesProxy.count > 0) {
|
property Device device: devicesProxy.get(currentDevice)
|
||||||
var stateName;
|
property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
||||||
// switch (model.name) {
|
|
||||||
// case "sensor":
|
property var shownSensors: findSensors(deviceClass)
|
||||||
// }
|
property int currentSensor: 0
|
||||||
return (Math.round(parent.state.value * 100) / 100) + " °C";
|
|
||||||
|
ListModel {
|
||||||
|
id: supportedSensors
|
||||||
|
ListElement { ifaceName: "temperaturesensor"; stateName: "temperature" }
|
||||||
|
ListElement { ifaceName: "weather"; stateName: "temperature" }
|
||||||
|
ListElement { ifaceName: "humiditysensor"; stateName: "humidity" }
|
||||||
|
ListElement { ifaceName: "moisturesensor"; stateName: "moisture" }
|
||||||
|
ListElement { ifaceName: "pressuresensor"; stateName: "pressure" }
|
||||||
|
ListElement { ifaceName: "daylightsensor"; stateName: "daylight" }
|
||||||
|
ListElement { ifaceName: "presencesensor"; stateName: "isPresent" }
|
||||||
|
ListElement { ifaceName: "lightsensor"; stateName: "lightIntensity" }
|
||||||
|
ListElement { ifaceName: "co2sensor"; stateName: "co2" }
|
||||||
|
ListElement { ifaceName: "conductivity"; stateName: "conductivity" }
|
||||||
|
ListElement { ifaceName: "noisesensor"; stateName: "noise" }
|
||||||
|
ListElement { ifaceName: "smartmeterconsumer"; stateName: "totalEnergyConsumed" }
|
||||||
|
ListElement { ifaceName: "smartmeterproducer"; stateName: "totalEnergyProduced" }
|
||||||
|
}
|
||||||
|
function findSensors(deviceClass) {
|
||||||
|
var ret = []
|
||||||
|
for (var i = 0; i < supportedSensors.count; i++) {
|
||||||
|
if (deviceClass.interfaces.indexOf(supportedSensors.get(i).ifaceName) >= 0) {
|
||||||
|
ret.push({ifaceName: supportedSensors.get(i).ifaceName, stateName: supportedSensors.get(i).stateName})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
property StateType shownStateType: deviceClass.stateTypes.findByName(shownSensors[currentSensor].stateName)
|
||||||
|
|
||||||
|
function nextSensor() {
|
||||||
|
var newSensorIndex = sensorsRoot.currentSensor + 1;
|
||||||
|
if (newSensorIndex > sensorsRoot.shownSensors.length - 1) {
|
||||||
|
var newDeviceIndex = (sensorsRoot.currentDevice + 1) % devicesProxy.count;
|
||||||
|
newSensorIndex = 0;
|
||||||
|
sensorsRoot.currentDevice = newDeviceIndex;
|
||||||
|
}
|
||||||
|
sensorsRoot.currentSensor = newSensorIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
nextSensorAnimation.start()
|
||||||
|
timer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
SequentialAnimation {
|
||||||
|
id: nextSensorAnimation
|
||||||
|
NumberAnimation { target: sensorsRoot; property: "opacity"; from: 1; to: 0; duration: 500 }
|
||||||
|
ScriptAction { script: { nextSensor(); } }
|
||||||
|
NumberAnimation { target: sensorsRoot; property: "opacity"; from: 0; to: 1; duration: 500 }
|
||||||
|
}
|
||||||
|
Timer {
|
||||||
|
id: timer
|
||||||
|
interval: 10000
|
||||||
|
repeat: true
|
||||||
|
running: sensorsRoot.shownSensors.length > 1 || devicesProxy.count > 1
|
||||||
|
onTriggered: nextSensorAnimation.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
ColorIcon {
|
||||||
|
Layout.preferredHeight: app.iconSize
|
||||||
|
Layout.preferredWidth: app.iconSize
|
||||||
|
name: app.interfaceToIcon(sensorsRoot.shownSensors[sensorsRoot.currentSensor].ifaceName)
|
||||||
|
color: app.interfaceToColor(sensorsRoot.shownSensors[sensorsRoot.currentSensor].ifaceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
Label {
|
||||||
|
text: sensorsRoot.device.name
|
||||||
|
font.pixelSize: app.smallFont
|
||||||
|
Layout.fillWidth: true
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: sensorsRoot.shownStateType
|
||||||
|
? sensorsRoot.device.states.getState(shownStateType.id).value + " " + sensorsRoot.shownStateType.unitString
|
||||||
|
: ""
|
||||||
|
// font.pixelSize: app.smallFont
|
||||||
|
Layout.fillWidth: true
|
||||||
|
visible: sensorsRoot.shownStateType.type.toLowerCase() !== "bool"
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
Led {
|
||||||
|
Layout.preferredHeight: app.iconSize * .5
|
||||||
|
Layout.preferredWidth: height
|
||||||
|
on: sensorsRoot.device.stateValue(sensorsRoot.shownStateType.id) === true
|
||||||
|
visible: sensorsRoot.shownStateType.type.toLowerCase() === "bool"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -175,34 +175,18 @@ Item {
|
|||||||
property var device: null
|
property var device: null
|
||||||
property var deviceClass: null
|
property var deviceClass: null
|
||||||
|
|
||||||
ItemDelegate {
|
readonly property var powerStateType: deviceClass.stateTypes.findByName("power");
|
||||||
Layout.preferredWidth: app.iconSize
|
readonly property var powerState: device.states.getState(powerStateType.id)
|
||||||
Layout.preferredHeight: app.iconSize
|
|
||||||
Layout.leftMargin: app.margins / 2
|
readonly property var brightnessStateType: deviceClass.stateTypes.findByName("brightness");
|
||||||
Layout.alignment: Qt.AlignVCenter
|
readonly property var brightnessState: device.states.getState(brightnessStateType.id)
|
||||||
padding: 0; topPadding: 0; bottomPadding: 0
|
|
||||||
contentItem: ColorIcon {
|
|
||||||
name: "../images/light-off.svg"
|
|
||||||
color: app.accentColor
|
|
||||||
}
|
|
||||||
onClicked: {
|
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
|
||||||
var actionType = deviceClass.actionTypes.findByName("power");
|
|
||||||
var params = [];
|
|
||||||
var powerParam = {}
|
|
||||||
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
|
||||||
powerParam["value"] = false;
|
|
||||||
params.push(powerParam)
|
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrottledSlider {
|
ThrottledSlider {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: app.margins / 2
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
visible: deviceClass.interfaces.indexOf("dimmablelight") >= 0
|
opacity: deviceClass.interfaces.indexOf("dimmablelight") >= 0 ? 1 : 0
|
||||||
readonly property var brightnessStateType: deviceClass.stateTypes.findByName("brightness");
|
enabled: opacity > 0
|
||||||
readonly property var brightnessState: device.states.getState(brightnessStateType.id)
|
|
||||||
from: 0
|
from: 0
|
||||||
to: 100
|
to: 100
|
||||||
value: brightnessState.value
|
value: brightnessState.value
|
||||||
@ -224,8 +208,9 @@ Item {
|
|||||||
Layout.rightMargin: app.margins / 2
|
Layout.rightMargin: app.margins / 2
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
padding: 0; topPadding: 0; bottomPadding: 0
|
padding: 0; topPadding: 0; bottomPadding: 0
|
||||||
|
|
||||||
contentItem: ColorIcon {
|
contentItem: ColorIcon {
|
||||||
name: "../images/light-on.svg"
|
name: powerState.value === true ? "../images/light-on.svg" : "../images/light-off.svg"
|
||||||
color: app.accentColor
|
color: app.accentColor
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
@ -234,7 +219,7 @@ Item {
|
|||||||
var params = [];
|
var params = [];
|
||||||
var powerParam = {}
|
var powerParam = {}
|
||||||
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
||||||
powerParam["value"] = true;
|
powerParam["value"] = !powerState.value;
|
||||||
params.push(powerParam)
|
params.push(powerParam)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params);
|
engine.deviceManager.executeAction(device.id, actionType.id, params);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user