-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtagscanner.pas
90 lines (76 loc) · 2.18 KB
/
mqtagscanner.pas
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
{
https://www.home-assistant.io/integrations/tag.mqtt/
Version 2024.12.15
}
{$mode Delphi}
unit mqTagScanner;
interface
Uses
Classes, SysUtils, mqttDevice;
Type
ETagScannerNames = tsnConfig..tsnValueTemplate;
{
tsnConfig,
tsnTopic,
tsnValueTemplate
}
Const
CTagScannerNames : array [ETagScannerNames] of string = (
'config',
'topic',
'value_template'
);
Type
{ TMQTTTagScanner }
TMQTTTagScanner = Class(TMQTTBaseObject)
private
public
Constructor Create;
function FromEnumToString(AConfigItem:Integer):string; Override;
function FromStringToEnum(AName: string): EAllNames; Override;
function Subscribe(ATopic: EAllNames; const SubId: integer): Boolean; Override;
end;
implementation
{ TMQTTTagScanner }
constructor TMQTTTagScanner.Create;
begin
Inherited Create;
FClass := hdcTagScanner;
FConfig.Add(CTagScannerNames, []);
FTopics := [Ord(tsnConfig), Ord(tsnTopic)];
FConfig[CTagScannerNames[tsnTopic]] := 'state'; //required
FConfigTopic := tsnConfig;
//FStateTopic := not used
//FCommandTopic := not used
//FIDTopic := not used
end;
function TMQTTTagScanner.FromEnumToString(AConfigItem:Integer):string;
begin
Result := '';
if (AConfigItem < Ord(Low(ETagScannerNames))) or (AConfigItem > Ord(High(ETagScannerNames))) then Exit;
Result := CTagScannerNames[ETagScannerNames(AConfigItem)];
end; //FromEnumToString
function TMQTTTagScanner.FromStringToEnum(AName: string): EAllNames;
Var
m : EAllNames;
begin
Result := eanNone;
for m := tsnConfig to tsnValueTemplate do begin
if AName = CTagScannerNames[m] then begin
Result := m;
Break;
end;
end; //for
end; //FromStringToEnum
function TMQTTTagScanner.Subscribe(ATopic: EAllNames; const SubId: integer): Boolean;
Var
CompleteTopic : string;
begin
Result := False;
if not Assigned(FParent) then Exit; // **********
CompleteTopic := TopicPrefix(ATopic) + Config[CTagScannerNames[ATopic]];
Result := FParent.Subscribe(CompleteTopic, SubId);
end; //Subscribe
Initialization
HATypeInfo[tsnValueTemplate] := hatTemplate;
end.