Skip to content

Commit

Permalink
Sync: Add local queue mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Jun 21, 2024
1 parent 40e60fe commit 5de3ccd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@
<setting name="Insteon_SumpAlarmAddr" serializeAs="String">
<value />
</setting>
<setting name="Sync_LocalQueueMode" serializeAs="String">
<value>False</value>
</setting>
</HAController.My.MySettings>
</userSettings>
<entityFramework>
Expand Down
14 changes: 13 additions & 1 deletion My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,8 @@
<Setting Name="Insteon_SumpAlarmAddr" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Sync_LocalQueueMode" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
6 changes: 6 additions & 0 deletions modConverse.vb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Module modConverse
strCommandResponse = modInsteon.Disable()
Case "library"
strCommandResponse = modLibrary.Disable()
Case "localqueue"
My.Settings.Sync_LocalQueueMode = False
strCommandResponse = "Local queue mode disabled"
Case "mail"
strCommandResponse = modMail.Disable()
Case "mapquest"
Expand Down Expand Up @@ -156,6 +159,9 @@ Module modConverse
strCommandResponse = modInsteon.Enable()
Case "library"
strCommandResponse = modLibrary.Enable()
Case "localqueue"
My.Settings.Sync_LocalQueueMode = True
strCommandResponse = "Local queue mode enabled"
Case "mail"
strCommandResponse = modMail.Enable()
Case "mapquest"
Expand Down
3 changes: 2 additions & 1 deletion modDatabase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Module modDatabase
Public conn As SQLiteConnection = New SQLiteConnection

Sub CreateDb()
Execute("CREATE TABLE If Not EXISTS ""CONFIG"" (""Key"" varchar(100) primary key not null ,""Value"" varchar )")
Execute("CREATE TABLE IF NOT EXISTS ""CONFIG"" (""Key"" varchar(100) primary key not null ,""Value"" varchar )")
Execute("CREATE TABLE IF NOT EXISTS DEVICES(Id INTEGER PRIMARY KEY, Name TEXT, Type TEXT, Model TEXT, Location TEXT, Address TEXT UNIQUE)")
Execute("CREATE TABLE IF NOT EXISTS ENVIRONMENT(Id INTEGER PRIMARY KEY, Date TEXT, Source TEXT, Location TEXT, Temperature INTEGER, Humidity INTEGER, Condition TEXT)")
Execute("CREATE TABLE IF NOT EXISTS ""LOCALQUEUE"" (""Id"" integer primary key autoincrement not null ,""Src"" varchar ,""Auth"" varchar ,""Dest"" varchar ,""Mesg"" varchar , ""Recv"" integer )")
Execute("CREATE TABLE IF NOT EXISTS LOCATION(Id INTEGER PRIMARY KEY, Date TEXT, Latitude REAL, Longitude REAL, Speed REAL)")
Execute("CREATE TABLE IF NOT EXISTS PERSONS(Id INTEGER PRIMARY KEY, Date TEXT, FirstName TEXT, LastName TEXT, Nickname TEXT, PersonType INTEGER, Email TEXT, PhoneNumber TEXT, PhoneCarrier INTEGER, MsgPreference INTEGER, Address TEXT, Gender INTEGER, IsSocial INTEGER)")
Execute("CREATE TABLE IF NOT EXISTS PLACES(Id INTEGER PRIMARY KEY, Date TEXT, Name TEXT, Location TEXT)")
Expand Down
20 changes: 18 additions & 2 deletions modSync.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ Module modSync
Dim tmrSyncHeartbeatTimer As System.Timers.Timer

Sub InitialHeartbeatHandler()
SendMessage("server", "fetch", "none")
If My.Settings.Sync_LocalQueueMode = False Then
SendMessage("server", "fetch", "none")
Else
GetLocalMessage()
End If
End Sub

Sub SendHeartbeatHandler(sender As Object, e As EventArgs)
SendMessage("server", "fetch", "none")
If My.Settings.Sync_LocalQueueMode = False Then
SendMessage("server", "fetch", "none")
Else
GetLocalMessage()
End If
End Sub

Function ClearSyncCredentials() As String
Expand Down Expand Up @@ -38,6 +46,14 @@ Module modSync
Return "Sync module enabled"
End Function

Function GetLocalMessage() As String
Dim strLocalMesg As String = ""
modDatabase.ExecuteReader("SELECT Mesg FROM LOCALQUEUE WHERE Src = 'sync' AND Auth = 'server' AND Dest = 'hac' AND Recv = 0 LIMIT 1", strLocalMesg)
modDatabase.Execute("UPDATE LOCALQUEUE SET Recv = 1 WHERE Src = 'sync' AND Auth = 'server' AND Dest = 'hac' AND Recv = 0 AND Mesg = '" And strLocalMesg And "'")
modConverse.Interpret(strLocalMesg, True, False)
Return "OK"
End Function

Function Load() As String
If My.Settings.Sync_Enable = True Then
My.Application.Log.WriteEntry("Loading sync module")
Expand Down

0 comments on commit 5de3ccd

Please sign in to comment.