The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.

This URL has Read-Only access.

Statistics
| Revision:

root / trunk / DomotiGa / FSettingsTemperaturNu.class @ 821

History | View | Annotate | Download (5.3 kB)

1
' Gambas class file
2
3
' Description:
4
' FSettingsTemperaturNu.class
5
' Settings form for TemperaturNu temperature upload.
6
7
' Development Status:
8
' Development just started.
9
10
' Links:
11
' http://www.temperatur.nu
12
13
' DomotiGa - an open source home automation program.
14
' Copyright(C) 2008-2010 Ron Klinkien
15
' This module is written by and Copyright(C) 2010 Daniel Lindmark
16
17
' Read file called COPYING for license details.
18
19
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
' initialize buttons and fill in current values
21
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
PUBLIC SUB Form_Open()
23
24
  ME.Move(FMain.X + 50, FMain.Y + 70)
25
26
  chkEnabled.Value = Main.bTemperaturNuEnabled
27
  txtCity.Text = Main.sTemperaturNuCity
28
  txtId.Text = Main.sTemperaturNuId
29
  chkDebug.Value = Main.bTemperaturNuDebug
30
  txtPushTime.Text = Main.iTemperaturNuPushTime
31
32
  IF Main.bTemperaturNuEnabled = FALSE THEN 
33
    txtCity.Enabled = FALSE
34
    txtId.Enabled = FALSE
35
    chkDebug.Enabled = FALSE
36
    btnUpload.Enabled = FALSE
37
    txtPushTime.Enabled = FALSE
38
    cmbSensor.Enabled = FALSE
39
    cmbValue.Enabled = FALSE
40
    txtValue.Enabled = FALSE
41
  END IF
42
43
  FillTemperatureDevices()
44
  FillValue()
45
46
END
47
48
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49
' fill combobox with available devices
50
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
PUBLIC SUB FillTemperatureDevices()
52
53
  DIM rResult, rDevice AS Result
54
  DIM iCount, iDevice AS Integer
55
56
  rResult = Main.hDB.Exec("SELECT * FROM devices WHERE enabled is true AND groups LIKE '%Temperature%'")
57
58
  IF NOT rResult THEN
59
    Message.Info(("Error: table 'devices' not found!"))
60
    RETURN
61
  END IF
62
63
  cmbValue.Add("", 0)
64
  cmbValue.Add("Value", 1)
65
  cmbValue.Add("Value2", 2)
66
  cmbValue.Add("Value3", 3)
67
  cmbValue.Add("Value4", 4)
68
69
  FOR iCount = 0 TO rResult.Max
70
    cmbSensor.Add(rResult!name)
71
    rResult.MoveNext
72
  NEXT
73
74
  TRY rDevice = Main.hDB.Exec("SELECT name FROM devices WHERE id = &1", Main.iTemperaturNuDeviceId)
75
  cmbSensor.Add("", 0)
76
  IF rDevice.Count THEN
77
    cmbSensor.Text = Devices.FindNameForDevice(Main.iTemperaturNuDeviceId)
78
    cmbValue.Index = Main.sTemperaturNuDeviceValue
79
  ENDIF
80
81
END
82
83
PUBLIC SUB GetDeviceId(sName AS String) AS Integer
84
85
  DIM rDevice AS Result
86
87
  TRY rDevice = Main.hDB.Exec("SELECT id FROM devices WHERE name = &1", sName)
88
  IF rDevice.Count THEN RETURN rDevice!id
89
90
END
91
92
PUBLIC SUB FillValue()
93
94
  txtValue.Text = Devices.GetCurrentValueForDevice(GetDeviceId(cmbSensor.Text), cmbValue.Index)
95
96
END
97
98
PUBLIC SUB btnCancel_Click()
99
100
  ME.Close
101
102
END
103
104
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105
' load defaults from database
106
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
PUBLIC SUB btnDefaults_Click()
108
109
  DIM rResult AS Result
110
111
  rResult = Main.GetSettingTable("temperaturnu", TRUE) ' get defaults
112
  IF rResult.Count THEN
113
    chkEnabled.Value = rResult!enabled
114
    txtCity.Text = rResult!city
115
    txtId.Text = rResult!apikey
116
    chkDebug.Value = rResult!debug
117
    txtPushTime.Text = rResult!pushtime
118
  END IF
119
  btnSave.Enabled = TRUE
120
121
END
122
123
PUBLIC SUB chkEnabled_Click()
124
125
  txtCity.Enabled = chkEnabled.Value
126
  txtId.Enabled = chkEnabled.Value
127
  chkDebug.Enabled = chkEnabled.Value
128
  btnUpload.Enabled = chkEnabled.Value
129
  txtPushTime.Enabled = chkEnabled.Value
130
  cmbSensor.Enabled = chkEnabled.Value
131
  cmbValue.Enabled = chkEnabled.Value
132
  txtValue.Enabled = chkEnabled.Value
133
  btnSave.Enabled = TRUE
134
135
END
136
137
PUBLIC SUB txtCity_KeyPress()
138
139
  btnSave.Enabled = TRUE
140
141
END
142
143
PUBLIC SUB txtId_KeyPress()
144
145
  btnSave.Enabled = TRUE
146
147
END
148
149
PUBLIC SUB txtPushTime_KeyPress()
150
151
  btnSave.Enabled = TRUE
152
153
END
154
155
PUBLIC SUB cmbSensor_Click()
156
157
  btnSave.Enabled = TRUE
158
  FillValue()
159
160
END
161
162
PUBLIC SUB cmbValue_Click()
163
164
  btnSave.Enabled = TRUE
165
  FillValue()
166
167
END
168
169
PUBLIC SUB chkDebug_Click()
170
171
  btnSave.Enabled = TRUE
172
173
END
174
175
PRIVATE SUB ValidInput() AS Boolean
176
177
  IF NOT txtCity.Text THEN
178
    Balloon(("Please enter a city name!"), txtCity)
179
    RETURN FALSE
180
  END IF
181
  IF NOT txtId.Text THEN
182
    Balloon(("Please enter an id!"), txtId)
183
    RETURN FALSE
184
  END IF
185
  IF NOT cmbSensor.Text THEN
186
    Balloon(("Please select a device!"), cmbSensor)
187
    RETURN FALSE
188
  END IF
189
  IF NOT cmbValue.Text THEN
190
    Balloon(("Please select a value field!"), cmbValue)
191
    RETURN FALSE
192
  END IF
193
  RETURN TRUE
194
195
END
196
197
PUBLIC SUB btnSave_Click()
198
199
  DIM rResult AS Result
200
201
  IF NOT ValidInput() THEN RETURN
202
203
  ' save new Temperatur.nu settings
204
  rResult = Main.hDB.Exec("UPDATE settings_temperaturnu SET debug = &1, city = &2, pushtime = &3, enabled = &4, apikey = &5, deviceid = &6, devicevalue = &7 WHERE id = 1", chkDebug.Value, txtCity.Text, txtPushTime.Text, chkEnabled.Value, txtId.Text, GetDeviceId(cmbSensor.Text), cmbValue.Index)
205
  rResult = Main.GetSettingTable("temperaturnu") ' reload settings
206
  IF rResult.Count THEN
207
    Main.bTemperaturNuEnabled = rResult!enabled
208
    Main.sTemperaturNuCity = rResult!city
209
    Main.sTemperaturNuId = rResult!apikey
210
    Main.bTemperaturNuDebug = rResult!debug
211
    Main.iTemperaturNuPushTime = rResult!pushtime
212
    Main.iTemperaturNuDeviceId = rResult!deviceid
213
    Main.sTemperaturNuDeviceValue = rResult!devicevalue
214
  END IF
215
  IF Main.bServer THEN
216
    Main.Restart_TemperaturNu()
217
  ELSE
218
    XMLClient.ModuleRestart("TemperaturNu")
219
  END IF
220
  ME.Close
221
222
END
223
224
PUBLIC SUB btnUpload_Click()
225
226
  TemperaturNu.UploadTemperaturNuData()
227
228
END
229
230
PUBLIC SUB btnWeb_Click()
231
232
  Desktop.Open("http://www.temperatur.nu/")
233
234
END