-
Notifications
You must be signed in to change notification settings - Fork 2
/
SwitchItem.qml
171 lines (156 loc) · 2.98 KB
/
SwitchItem.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import QtQuick 1.1
import BasicUIControls 1.0
Item {
id: switchItem
width: 177
height: 75
property string entity_id;
property string friendly_name;
property string last_changed;
property string last_updated;
property string switchState;
property string type: entity_id.split('.')[0]
property color colorLight: "#f0f0f0"
property color colorMedium: "#A8A8A8"
property color colorDark: "#565656"
property color bckgColorUp: "#f0f0f0"
property color bckgColorDown: "#A8A8A8"
state: "up"
visible: true
states: [
State {
name: "up"
PropertyChanges {
target: switch1Title;color: colorDark
}
PropertyChanges {
target: switch1Last;color: colorDark
}
PropertyChanges {
target: switch1Data;color: colorDark
}
PropertyChanges {
target: switch1BG;color: bckgColorUp
}
},
State {
name: "down"
PropertyChanges {
target: switch1Title;color: bckgColorUp
}
PropertyChanges {
target: switch1Last;color: bckgColorUp
}
PropertyChanges {
target: switch1Data;color: bckgColorUp
}
PropertyChanges {
target: switch1BG;color: bckgColorDown
}
}
]
function getImage(switchState, type) {
switch (type) {
case 'group':
if(switchState != "on" && switchState != "off")
break;
case 'light':
case 'switch':
return (switchState === "off") ? "./drawables/bulb_off.png" : "./drawables/bulb_on.png"
default:
return "./drawables/sensor.png"
}
}
MouseArea {
anchors.fill: parent
onPressed: {
switchItem.state = "down"
switch (type) {
case 'group':
{
if(switchState != "on" && switchState != "off")
break;
}
case 'light':
case 'switch':
{
switchState = (switchState == "off" ? "on" : "off")
app.postHomeAssistant(entity_id, switchState)
break;
}
default:
break;
}
}
onReleased: {
switchItem.state = "up"
}
}
Item {
anchors.fill: parent
Rectangle {
id: switch1BG
width: parent.width
height: parent.height
radius: 3
color: bckgColorUp
}
Image {
id: switch1Button
anchors {
top: parent.top
topMargin: 11
left: parent.left
leftMargin: 10
}
visible: true;
width: 30
height: 38
source: getImage(switchState, type)
}
Text {
id: switch1Title
anchors {
top: parent.top
topMargin: 7
left: parent.left
leftMargin: 50
}
font {
family: qfont.semiBold.name
pixelSize: 15
}
color: colorDark
text: friendly_name.substring(0, 14)
}
Text {
id: switch1Data
anchors {
top: switch1Title.bottom
left: switch1Button.right
leftMargin: 10
}
font {
family: qfont.semiBold.name
pixelSize: 12
}
color: colorDark
text: switchState
}
Text {
id: switch1Last
anchors {
top: switch1Data.bottom
topMargin: 3
left: switch1Button.right
leftMargin: 10
}
font {
family: qfont.semiBold.name
pixelSize: 9
}
color: colorMedium
text: last_updated.substring(0, 16)
}
}
}