-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThermostat.vb
938 lines (873 loc) · 38.7 KB
/
Thermostat.vb
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
Imports HomeSeerAPI
Imports Scheduler
Public Class Thermostat
#Region "Variables"
Public RefID As Integer = 0
Const eParent As Integer = 0 'this is not in the enumeration to exclude it from being included in the loop of the child devices
Dim arrValues As New hsCollection
Dim SetPoint_Low As Integer
Dim SetPoint_High As Integer
Dim Temp_Low As Integer
Dim Temp_High As Integer
Dim iTempScale As Integer
Dim bDamperStatus As Boolean
#End Region
#Region "Enumerations"
Enum eDeviceValues
'parent device values
Address 'This is the default parent value
'the rest use custom code
Name
Location
Location2
Message
End Enum
Enum eDeviceTypes
Heat_SetPoint = 1
Cool_SetPoint
Mode
Fan
Hold
Temperature
Outside_Temp
RunTime
Filter_Remind
Damper_Status
Calling_Status
Schedule
End Enum
Enum eDamper As Integer
Closed = False
Open = True
End Enum
Enum eMode As Integer
Off
Heat
Cool
Auto
Aux
End Enum
Enum eFan As Integer
Auto
FanOn
End Enum
Enum eHold
Run
Hold
Tmp
End Enum
Enum eTempScale
Fahrenheit
Celsius
End Enum
Enum eAddress
Low = 1
High = 15
End Enum
#End Region
#Region "Object Initialization"
Public Sub New(ByVal DeviceName As String, ByVal Address As Integer, Optional ByVal iRefID As Integer = 0, Optional ByVal TempScale As eTempScale = eTempScale.Fahrenheit)
MyBase.New()
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim enumValues As Array = System.[Enum].GetValues(GetType(eDeviceTypes))
Dim ChildRefID As Integer
Me.TempScale = TempScale
If iRefID > 0 Then 'the device already exists
RefID = iRefID
Else
RefID = CreateDevice(DeviceName, Address)
End If
dv = GetDevice(eParent)
dtThermostats.Rows.Add(eParent, RefID, RefID, dv.Address(hs)) 'set the child and parent ref ID's to the same
dtThermostats.AcceptChanges()
Dim PED As clsPlugExtraData = dv.PlugExtraData_Get(hs)
If PED Is Nothing Then PED = New clsPlugExtraData
For Each ChildDevice As eDeviceTypes In enumValues
ChildRefID = PEDGet(PED, ChildDevice.ToString) 'get the ref for this child device from the parent data
ChildRefID = IIf(ChildRefID = Nothing, 0, ChildRefID) 'qualify the result
ChildRefID = CreateDevice(ChildDevice.ToString, Address, ChildDevice, ChildRefID) 'check for a device, if not found, create it
dtThermostats.Rows.Add(ChildDevice, ChildRefID, RefID, 0) 'keep the data centrally located for multiple lookup types
PEDAdd(PED, ChildDevice.ToString, ChildRefID) 'Keep a reference to the child ref using the enumeration for quicker retrieval.
BindParentAndChild(dv, RefID, ChildRefID) 'in this loop the child is being bound to the parent device ('cuz we have it)
Next
dv.PlugExtraData_Set(hs) = PED
Me.Name = DeviceName
Poll()
End Sub
#End Region
#Region "Properties"
Public Property Name() As String
Get
Return GetDeviceValue(eParent, eDeviceValues.Name)
End Get
Set(ByVal value As String)
SetDeviceValue(eParent, value, eDeviceValues.Name)
End Set
End Property
Public Property Location() As String
Get
Return GetDeviceValue(eParent, eDeviceValues.Location)
End Get
Set(ByVal value As String)
SetDeviceValue(eParent, value, eDeviceValues.Location)
End Set
End Property
Public Property Location2() As String
Get
Return GetDeviceValue(eParent, eDeviceValues.Location2)
End Get
Set(ByVal value As String)
SetDeviceValue(eParent, value, eDeviceValues.Location2)
End Set
End Property
Public Property Address() As Integer
Get
Return GetDeviceValue(eParent, eDeviceValues.Address)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eParent, value, eDeviceValues.Address)
End Set
End Property
Public Property HeatSetPoint() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Heat_SetPoint)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Heat_SetPoint, value)
End Set
End Property
Public Property CoolSetPoint() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Cool_SetPoint)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Cool_SetPoint, value)
End Set
End Property
Public Property Mode() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Mode)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Mode, value)
End Set
End Property
Public Property Fan() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Fan)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Fan, value)
End Set
End Property
Public Property Hold() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Hold)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Hold, value)
End Set
End Property
Public Property Damper() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Damper_Status)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Damper_Status, value)
End Set
End Property
Public Property Calling() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Calling_Status)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Calling_Status, value)
End Set
End Property
Public Property Temperature() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Temperature)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Temperature, value)
End Set
End Property
Public Property OutsideTemp() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Outside_Temp)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Outside_Temp, value)
End Set
End Property
Public Property TempScale() As eTempScale
Get
Return iTempScale
End Get
Set(ByVal value As eTempScale)
iTempScale = value
SetTempScaleData(value)
End Set
End Property
Public Property Message() As String
Get
Return GetDeviceValue(eParent, eDeviceValues.Message)
End Get
Set(ByVal value As String)
SetDeviceValue(eParent, value, eDeviceValues.Message)
End Set
End Property
Public Property FilterRemind() As Integer
Get
Return GetDeviceValue(eDeviceTypes.Filter_Remind)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.Filter_Remind, value)
End Set
End Property
Public Property TotalRunTime() As Integer
Get
Return GetDeviceValue(eDeviceTypes.RunTime)
End Get
Set(ByVal value As Integer)
SetDeviceValue(eDeviceTypes.RunTime, value)
End Set
End Property
#End Region
#Region "Private Subs/Functions"
Private Sub SetTempScaleData(ByVal TempScale As eTempScale)
Select Case TempScale
Case eTempScale.Fahrenheit
SetPoint_Low = 40
SetPoint_High = 99
Temp_Low = -67
Temp_High = 257
Case eTempScale.Celsius
SetPoint_Low = 5
SetPoint_High = 37
Temp_Low = -55
Temp_High = 125
End Select
UpdateTempControls()
End Sub
Private Sub UpdateTempControls()
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim RefIDs() As Integer
Dim iRefID As Integer
Dim PED As clsPlugExtraData
Dim DeviceType As Integer
dv = hs.GetDeviceByRef(RefID)
If dv IsNot Nothing Then
RefIDs = dv.AssociatedDevices(hs) 'get all the child devices
For Each iRefID In RefIDs
dv = hs.GetDeviceByRef(iRefID)
PED = dv.PlugExtraData_Get(hs) 'the device type is referenced inside the PED
DeviceType = PEDGet(PED, dv.Ref(hs))
Select Case DeviceType 'clear out previous controls
Case Thermostat.eDeviceTypes.Heat_SetPoint, Thermostat.eDeviceTypes.Cool_SetPoint, Thermostat.eDeviceTypes.Temperature
hs.DeviceVSP_ClearAll(dv.Ref(hs), True)
End Select
Select Case DeviceType 'add new controls based on device type
Case Thermostat.eDeviceTypes.Heat_SetPoint
AddControl(dv.Ref(hs), "Heat Point", DeviceType, SetPoint_Low, SetPoint_High)
Case Thermostat.eDeviceTypes.Cool_SetPoint
AddControl(dv.Ref(hs), "Cool Point", DeviceType, SetPoint_Low, SetPoint_High)
Case Thermostat.eDeviceTypes.Temperature
AddControl(dv.Ref(hs), "Temp", DeviceType, Temp_Low, Temp_High)
Case Thermostat.eDeviceTypes.Outside_Temp
AddControl(dv.Ref(hs), "Outside Temp", DeviceType, Temp_Low, Temp_High)
End Select
Next
End If
End Sub
Private Function GetDeviceValue(ByVal DeviceType As eDeviceTypes, Optional ByVal ParentData As eDeviceValues = eDeviceValues.Address) As String
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim ReturnValue As String = ""
Dim ref As Integer
Dim PED As clsPlugExtraData
If arrValues.ContainsKey(DeviceType.ToString) Then 'we already have the value for this device, don't get the device, no need.
ReturnValue = arrValues(DeviceType.ToString)
Else
dv = GetDevice(DeviceType)
ref = dv.Ref(Nothing)
Select Case DeviceType
Case eParent 'the parent device holds multiple pieces of info that we need
Select Case ParentData
Case eDeviceValues.Name
ReturnValue = dv.Name(Nothing)
Case eDeviceValues.Address
PED = dv.PlugExtraData_Get(hs)
ReturnValue = PEDGet(PED, "Parent")
Case eDeviceValues.Location
ReturnValue = dv.Location(Nothing)
Case eDeviceValues.Location2
ReturnValue = dv.Location2(Nothing)
End Select
Case Else 'get the default value from the device
PED = dv.PlugExtraData_Get(hs)
ReturnValue = PEDGet(PED, DeviceType.ToString)
End Select
End If
Return ReturnValue
End Function
Private Sub SetDeviceValue(ByVal DeviceType As eDeviceTypes, ByVal Value As String, Optional ByVal ParentData As eDeviceValues = eDeviceValues.Address)
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim ref As Integer
Dim PED As clsPlugExtraData
Dim DeviceValue As String = ""
Value = Value.Replace("_", " ")
'because the parent device holds multiple pieces of info, we can't use the data list, as the key would be the same for all the parent data.
Select Case DeviceType
Case eParent 'the parent device holds multiple pieces of info that we need to set
dv = GetDevice(DeviceType)
ref = dv.Ref(Nothing)
Select Case ParentData
Case eDeviceValues.Name
dv.Name(hs) = Value
Case eDeviceValues.Address
ChangeThermostatTable(eDataTableAction.Update, RefID, ref, Value)
PED = dv.PlugExtraData_Get(hs)
PEDAdd(PED, "Parent", Value)
dv.PlugExtraData_Set(hs) = PED
dv.Address(hs) = Value
hs.SetDeviceValueByRef(ref, Value, True)
Case eDeviceValues.Location
dv.Location(hs) = Value
UpdateChildDevices(eDeviceValues.Location, Value)
Case eDeviceValues.Location2
dv.Location2(hs) = Value
UpdateChildDevices(eDeviceValues.Location2, Value)
Case eDeviceValues.Message
dv.AdditionalDisplayData(hs) = {Value}
End Select
Case Else 'set the default value for the device
dv = GetDevice(DeviceType)
ref = dv.Ref(Nothing)
'add to our data list for quick internal retrieval.
arrValues.Add(CObj(Value), DeviceType.ToString)
'keep the data table current, we may use it at some point for data values.
ChangeThermostatTable(eDataTableAction.Update, RefID, ref, Value)
'update the HS3 device
PED = dv.PlugExtraData_Get(hs)
PEDAdd(PED, DeviceType.ToString, Value)
dv.PlugExtraData_Set(hs) = PED
DeviceValue = dv.devValue(Nothing)
If DeviceValue <> Value AndAlso Value <> "" Then 'something has changed, so update
hs.SetDeviceValueByRef(ref, Value, True)
End If
End Select
End Sub
Public Sub UpdatePhysicalDevice(ByVal DeviceType As eDeviceTypes, ByVal Value As Integer)
'This is custom based on the manufacturer
Dim Addr As String = ""
Dim Command As String = ""
Select Case DeviceType
Case eDeviceTypes.Heat_SetPoint
Command = "SPH=" & CStr(Value)
Case eDeviceTypes.Cool_SetPoint
Command = "SPC=" & CStr(Value)
Case eDeviceTypes.Filter_Remind
Command = "FR=" & CStr(Value)
Case eDeviceTypes.Fan
Select Case Value
Case eFan.Auto
Command = "F=A"
Case eFan.FanOn
Command = "F=O"
End Select
Case eDeviceTypes.Hold
Select Case Value
Case eHold.Run
Command = "SC=0"
Case eHold.Hold
Command = "SC=1"
Case eHold.Tmp ' I think this should always be sent with SPH or SPC
Command = "SC=2"
End Select
Case eDeviceTypes.Mode
Select Case Value
Case eMode.Auto
Command = "M=3"
Case eMode.Aux
Command = "M=EH"
Case eMode.Cool
Command = "M=2"
Case eMode.Heat
Command = "M=1"
Case eMode.Off
Command = "M=0"
End Select
End Select
If Command.Length > 0 Then
Addr = "A=" & Me.Address.ToString & " "
Command = Addr & "O=00 " & Command & vbCr
SendCMD(Command)
End If
End Sub
Private Function GetDevice(ByVal DeviceType As eDeviceTypes) As Scheduler.Classes.DeviceClass
Select Case DeviceType
Case eParent
Return hs.GetDeviceByRef(RefID)
Case Else
Return hs.GetDeviceByRef(GetRefID(DeviceType))
End Select
End Function
Private Function GetRefID(ByVal DeviceType As eDeviceTypes) As Integer
Dim Rows() As DataRow
Dim DeviceRefID As Integer = 0
Rows = dtThermostats.Select("ParentRefID='" & RefID & "' AND DeviceType='" & DeviceType & "'")
DeviceRefID = Rows(0).Item("RefID")
Return DeviceRefID
End Function
Private Function GetDeviceType(ByVal DeviceRefID As Integer) As Integer
Dim Rows() As DataRow
Dim DeviceType As Integer
Rows = dtThermostats.Select("ParentRefID='" & RefID & "' AND RefID='" & DeviceRefID & "'")
DeviceType = Rows(0).Item("DeviceType")
Return DeviceType
End Function
Private Sub UpdateChildDevices(ByVal DataType As eDeviceValues, ByVal value As String)
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim RefIDs() As Integer
Dim iRefID As Integer
dv = hs.GetDeviceByRef(RefID)
If dv IsNot Nothing Then
RefIDs = dv.AssociatedDevices(hs)
For Each iRefID In RefIDs
dv = hs.GetDeviceByRef(iRefID)
Select Case DataType
Case eDeviceValues.Location
dv.Location(hs) = value
Case eDeviceValues.Location2
dv.Location2(hs) = value
End Select
Next
End If
End Sub
Private Sub BindParentAndChild(ByVal dv As Scheduler.Classes.DeviceClass, ByVal ParentRefID As Integer, ByVal ChildRefID As Integer)
'in a parent/child relationship in Homeseer both parties must be aware of each other
'the parent must be linked to the child, and the child must be linked to the parent.
If ParentRefID = ChildRefID Then Exit Sub 'the child IS the parent, don't do anything.
If dv.Ref(hs) = ParentRefID Then 'we're binding the child to the parent
dv.AssociatedDevice_Add(hs, ChildRefID)
dv.Relationship(hs) = Enums.eRelationship.Parent_Root
Else 'we're binding the parent to the child
dv.AssociatedDevice_Add(hs, ParentRefID)
dv.Relationship(hs) = Enums.eRelationship.Child
End If
End Sub
Sub AddControl(ByVal ref As Integer, ByVal name As String, DeviceType As eDeviceTypes, ByVal value1 As Integer, Optional ByVal value2 As Integer = 0)
Dim Pair As VSPair = Nothing
Select Case DeviceType
Case eDeviceTypes.Filter_Remind
If (value2 = 0) Then
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = value1
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.Button
Else
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
Pair.PairType = VSVGPairType.Range
Pair.RangeStart = value1
Pair.RangeEnd = value2
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.RangeStatusSuffix = " Days"
Pair.Render = Enums.CAPIControlType.ValuesRange
End If
Case eDeviceTypes.RunTime
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
Pair.PairType = VSVGPairType.Range
Pair.RangeStart = value1
Pair.RangeEnd = value2
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.RangeStatusSuffix = " Days"
Pair.Render = Enums.CAPIControlType.ValuesRange
Case eDeviceTypes.Damper_Status
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = value1
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.Values
Case eDeviceTypes.Calling_Status
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = value1
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.Values
Case eDeviceTypes.Fan
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = value1
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.Button
Select Case value1
Case eFan.Auto
Pair.ControlUse = ePairControlUse._ThermFanAuto
Case eFan.FanOn
Pair.ControlUse = ePairControlUse._ThermFanOn
End Select
Case eDeviceTypes.Hold
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = value1
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.Button
Case eDeviceTypes.Mode
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = value1
Pair.Status = name
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.Button
Select Case value1
Case eMode.Auto
Pair.ControlUse = ePairControlUse._ThermModeAuto
Case eMode.Cool
Pair.ControlUse = ePairControlUse._ThermModeCool
Case eMode.Heat
Pair.ControlUse = ePairControlUse._ThermModeHeat
Case eMode.Off
Pair.ControlUse = ePairControlUse._ThermModeOff
'Case eMode.Aux
'Pair.ControlUse = ePairControlUse._ThermModeAux
End Select
Case eDeviceTypes.Cool_SetPoint
Pair = New VSPair(ePairStatusControl.Both)
Pair.PairType = VSVGPairType.Range
Pair.RangeStart = value1
Pair.RangeEnd = value2
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.ValuesRange
Pair.ControlUse = ePairControlUse._CoolSetPoint
Pair.RangeStatusSuffix = "°"
Case eDeviceTypes.Heat_SetPoint
Pair = New VSPair(ePairStatusControl.Both)
Pair.PairType = VSVGPairType.Range
Pair.RangeStart = value1
Pair.RangeEnd = value2
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.Render = Enums.CAPIControlType.ValuesRange
Pair.ControlUse = ePairControlUse._HeatSetPoint
Pair.RangeStatusSuffix = "°"
Case eDeviceTypes.Temperature, eDeviceTypes.Outside_Temp
Pair = New VSPair(ePairStatusControl.Status)
Pair.PairType = VSVGPairType.Range
Pair.RangeStart = value1
Pair.RangeEnd = value2
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.RangeStatusSuffix = "°"
Pair.Render = Enums.CAPIControlType.Values
Case eParent ' ToDo add support for message display
Pair = New VSPair(ePairStatusControl.Status)
Pair.PairType = VSVGPairType.Range
Pair.RangeStart = value1
Pair.RangeEnd = value2
Pair.Render_Location.Row = 1
Pair.Render_Location.Column = 1
Pair.RangeStatusPrefix = "Address "
Pair.Render = Enums.CAPIControlType.Values
End Select
hs.DeviceVSP_AddPair(ref, Pair)
End Sub
Sub SetUpStatusOnly(ByRef dv As Scheduler.Classes.DeviceClass)
'swap this to a status only
dv.MISC_Clear(hs, Enums.dvMISC.SHOW_VALUES)
dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
'clear out defaults
hs.DeviceVSP_ClearAll(dv.Ref(hs), True)
hs.DeviceVGP_ClearAll(dv.Ref(hs), True)
End Sub
' Public Enum eDeviceType_Thermostat
' Operating_State = 1
' Temperature = 2
' Mode_Set = 3
' Fan_Mode_Set = 4
' Fan_Status = 5
' Setpoint = 6
' RunTime = 7
' Hold_Mode = 8
' Operating_Mode = 9
' Additional_Temperature = 10
' Setback = 11
' Filter_Remind = 12
' Root = 99
' End Enum
Private Function CreateDevice(ByVal DeviceName As String, ByVal Address As Integer, Optional ChildDeviceType As eDeviceTypes = -1, Optional iRefID As Integer = 0) As Integer
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim ref As Integer
Dim PED As clsPlugExtraData
If iRefID > 0 Then
dv = hs.GetDeviceByRef(iRefID)
If dv IsNot Nothing Then Return iRefID 'no need to create the device
End If
DeviceName = DeviceName.Replace("_", " ")
Try
ref = hs.NewDeviceRef(DeviceName)
dv = hs.GetDeviceByRef(ref)
dv.Name(hs) = DeviceName
dv.Can_Dim(hs) = False
dv.Device_Type_String(hs) = DeviceName
Dim DT As New DeviceTypeInfo
DT.Device_API = DeviceTypeInfo.eDeviceAPI.Thermostat
dv.DeviceType_Set(hs) = DT
dv.Interface(hs) = IFACE_NAME
dv.InterfaceInstance(hs) = ""
dv.Last_Change(hs) = Now
dv.Location(hs) = "Not Set"
dv.Location2(hs) = "Not Set"
dv.Can_Dim(hs) = False
dv.Status_Support(hs) = False
dv.UserNote(hs) = ""
dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
PED = dv.PlugExtraData_Get(hs)
PEDAdd(PED, ref.ToString, ChildDeviceType)
dv.PlugExtraData_Set(hs) = PED
'put device specific stuff here
Select Case ChildDeviceType
Case eDeviceTypes.Heat_SetPoint
dv.Can_Dim(hs) = True
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
AddControl(ref, "Heat Point", ChildDeviceType, SetPoint_Low, SetPoint_High)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Setpoint
DT.Device_SubType = DeviceTypeInfo.eDeviceSubType_Setpoint.Heating_1
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Cool_SetPoint
dv.Can_Dim(hs) = True
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
AddControl(ref, "Cool Point", ChildDeviceType, SetPoint_Low, SetPoint_High)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Setpoint
DT.Device_SubType = DeviceTypeInfo.eDeviceSubType_Setpoint.Cooling_1
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Mode
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
AddControl(ref, "Auto", ChildDeviceType, eMode.Auto)
AddControl(ref, "Aux", ChildDeviceType, eMode.Aux)
AddControl(ref, "Cool", ChildDeviceType, eMode.Cool)
AddControl(ref, "Heat", ChildDeviceType, eMode.Heat)
AddControl(ref, "Off", ChildDeviceType, eMode.Off)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Operating_Mode
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Fan
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
AddControl(ref, "Auto", ChildDeviceType, eFan.Auto)
AddControl(ref, "On", ChildDeviceType, eFan.FanOn)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Fan_Status
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Damper_Status
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
AddControl(ref, "Closed", ChildDeviceType, False)
AddControl(ref, "Open", ChildDeviceType, True)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Operating_State
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Hold
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
AddControl(ref, "Hold", ChildDeviceType, eHold.Hold)
AddControl(ref, "Run", ChildDeviceType, eHold.Run)
AddControl(ref, "Tmp", ChildDeviceType, eHold.Tmp)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Hold_Mode
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Temperature
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
SetUpStatusOnly(dv)
AddControl(ref, "Temp", ChildDeviceType, Temp_Low, Temp_High)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Temperature
DT.Device_SubType = DeviceTypeInfo.eDeviceSubType_Temperature.Temperature
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Outside_Temp
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
SetUpStatusOnly(dv)
AddControl(ref, "Outside Temp", ChildDeviceType, Temp_Low, Temp_High)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Temperature
DT.Device_SubType = DeviceTypeInfo.eDeviceSubType_Temperature.Other_Temperature
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.RunTime
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
SetUpStatusOnly(dv)
AddControl(ref, "Run Time", ChildDeviceType, 0, 2147483647)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.RunTime
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Filter_Remind
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
'SetUpStatusOnly(dv)
AddControl(ref, "Filter Time", ChildDeviceType, 0, 2147483647)
AddControl(ref, "Reset", ChildDeviceType, 120)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Filter_Remind
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Calling_Status
dv.ImageLarge(hs) = "images/evcstat/thermostat-sub.png"
dv.Image(hs) = "images/evcstat/thermostat-sub_small.png"
SetUpStatusOnly(dv)
AddControl(ref, "Idle", ChildDeviceType, False)
AddControl(ref, "Calling", ChildDeviceType, True)
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Filter_Remind + 1
dv.DeviceType_Set(hs) = DT
Case eDeviceTypes.Schedule
Case Else 'parent
dv.ImageLarge(hs) = "images/evcstat/thermostat-main.png"
dv.Image(hs) = "images/evcstat/thermostat-main_small.png"
SetUpStatusOnly(dv)
AddControl(ref, DeviceName, eParent, eAddress.Low, eAddress.High)
dv.Device_Type_String(hs) = "EVC Thermostats"
dv.Address(hs) = Address
DT.Device_Type = DeviceTypeInfo.eDeviceType_Thermostat.Root
dv.DeviceType_Set(hs) = DT
RefID = ref
End Select
BindParentAndChild(dv, RefID, ref)
hs.SaveEventsDevices()
Return ref
Catch ex As Exception
hs.WriteLog(IFACE_NAME, "Error initializing device: " & ex.Message)
Return -1
End Try
End Function
Private Sub SendCMD(ByVal Command As String)
ComThread.SendCommand(Command)
End Sub
#End Region
#Region "Public Subs/Functions"
Public Sub Poll()
Try
Log("In Poll: Time: " & Now(), LogLevel.Debug)
Try
Dim cmd As String = "A=" & Me.Address.ToString & " O=00 R=1 R=2 SC=?" & vbCr
SendCMD(cmd)
Catch ex As Exception
Log("Error in Poll: " & ex.Message, LogLevel.Normal)
End Try
Catch ex As Exception
Log("Error polling: " & ex.Message, LogLevel.Debug)
End Try
End Sub
Public Sub ProcessDataReceived(ByVal Data As String)
Dim Prop As String
Dim Value As String
Dim addr As String = "1"
Dim zone As String = "00"
' OK, We can get multiple items here. So, split them all then parse each one.
Dim commands() As String = Split(Trim(Data))
Try
For Each item As String In commands
' Get The Property
Prop = Mid(item, 1, InStr(item, "=") - 1)
Value = Mid(item, InStr(item, "=") + 1)
Log("In ProcessCMD, Property= " & Prop & ", Value= " & Value, LogLevel.Debug)
Try
Select Case Prop
Case "A"
addr = Value
Case "Z"
zone = Value
Case "M"
Select Case Value
Case "O"
Me.Mode = eMode.Off
Case "A"
Me.Mode = eMode.Auto
Case "C"
Me.Mode = eMode.Cool
Case "H"
Me.Mode = eMode.Heat
Case "E", "EH"
Me.Mode = eMode.Aux
Case Else
Log("In ProcessCMD, Invalid Mode Value, Property= " & Prop & ", Value= " & Value, LogLevel.Err)
End Select
Case "F", "FM"
Select Case Value
Case "A"
Me.Fan = eFan.Auto
Case "O"
Me.Fan = eFan.FanOn
Case Else
Log("In ProcessCMD, Invalid Fan Value, Property= " & Prop & ", Value= " & Value, LogLevel.Err)
End Select
Case "DS"
Select Case Value
Case "O"
Me.Damper = True
Case "C"
Me.Damper = False
Case Else
Log("In ProcessCMD, Invalid Damper Value, Property= " & Prop & ", Value= " & Value, LogLevel.Err)
End Select
Case "CS"
Select Case Value
Case "C"
Me.Calling = True
Case "I"
Me.Calling = False
Case Else
Log("In ProcessCMD, Invalid Calling Value, Property= " & Prop & ", Value= " & Value, LogLevel.Err)
End Select
Case "FR"
'Remaining Filter Time
Me.FilterRemind = Value
Case "FT"
'Total Filter Time
Me.TotalRunTime = Value
Case "SPH"
'HeatSet
Me.HeatSetPoint = Value
Case "SPC"
'Coolset
Me.CoolSetPoint = Value
Case "T"
Me.Temperature = Value
Case "TM"
Me.Message = Value
Case "OA"
Me.OutsideTemp = Value
Case "SC"
Select Case Value
Case "0"
Me.Hold = eHold.Run
Case "1"
Me.Hold = eHold.Hold
Case "2"
Me.Hold = eHold.Tmp
Case Else
Log("In ProcessCMD, Invalid Hold Value, Property= " & Prop & ", Value= " & Value, LogLevel.Err)
End Select
Case Else
CheckTriggers(addr, zone, Prop, Value)
End Select
Catch ex As Exception
Log("Error in ProcessCMD Select Block, Selecting Properties, " & ex.Message)
End Try
Next
Catch ex As Exception
Log("Error in ProcessCMD, Selecting Properties, " & ex.Message)
End Try
End Sub
#End Region
End Class