Skip to content

Commit

Permalink
Various readability improvements
Browse files Browse the repository at this point in the history
- Re-added Icon to the app
- csproj update?
- Learned ESeesmart was just a followr of Eesmartlock.
- Removed wasted space in Config
- Reorganized some default config values.
  • Loading branch information
ZenithVal committed Jun 28, 2023
1 parent cce33fb commit 5fcb653
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 157 deletions.
6 changes: 3 additions & 3 deletions Bluetooth/ESmartLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private ESmartLock(BluetoothLEDevice bleDevice, GattDeviceService service, GattC
*/
private async Task<string> GetDevicePassword() {
if (isCloudSetup) {
if (string.IsNullOrEmpty(ConfigManager.ApplicationConfig.DevicePassword)) {
if (string.IsNullOrEmpty(ConfigManager.ApplicationConfig.ESmartConfig.DevicePassword)) {
Console.WriteLine("Device password unknown, grabbing from api... logging in...");
var loginToken = await ESmartLockAPI.Login();
if (loginToken.StartsWith("ERROR"))
Expand All @@ -55,11 +55,11 @@ private async Task<string> GetDevicePassword() {
return "ERROR_NO_PASS";

Console.WriteLine("Retrived device password from cloud, saving it to config");
ConfigManager.ApplicationConfig.DevicePassword = devicePassword;
ConfigManager.ApplicationConfig.ESmartConfig.DevicePassword = devicePassword;
ConfigManager.Save();
}

return ConfigManager.ApplicationConfig.DevicePassword;
return ConfigManager.ApplicationConfig.ESmartConfig.DevicePassword;
}
else return "123456";
}
Expand Down
22 changes: 14 additions & 8 deletions Configs/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,35 @@ public static void Reset() {
File.Delete(CONFIG_FILE);
File.Delete("app.pass");
File.WriteAllText(CONFIG_FILE, TomletMain.TomlStringFrom(new MainConfig {

vrchatAddress = "127.0.0.1",
port = 9001,
vrchatPort = 9000,
vrchatAddress = "127.0.0.1",
apiUsername = "",
apiPassword = "",
DevicePassword = "",


Mode = ApplicationMode.Testing,

ESmartConfig = new ESmartCredentials
{
apiUsername = "",
apiPassword = "",
DevicePassword = "",
},


BasicConfig = new BasicMode {
parameter = "/avatar/parameters/unlock"
},

TimerConfig = new TimerMode {
maxTime = 240,
absMin = 20,
maxTime = 60,
absMin = 0,
StartTime = new DefaultTime {
startingValue = -1,
randomMin = 10,
randomMax = 20
},
inc_parameter = "/avatar/parameters/timer_inc",
inc_step = 20,
inc_step = 1,
dec_parameter = "/avatar/parameters/timer_dec",
dec_step = 5,

Expand Down
2 changes: 1 addition & 1 deletion Configs/DefaultTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace OSCLock.Configs {
public class DefaultTime {
[TomlProperty("starting_value")]
[TomlInlineComment("Random if set to -1")]
[TomlInlineComment("If set to -1, a random value will be chosen betwen the min and max below.")]
public int startingValue { get; set; }
[TomlProperty("random_min")]
public int randomMin { get; set; }
Expand Down
24 changes: 24 additions & 0 deletions Configs/ESmartCredentials.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tomlet.Attributes;

namespace OSCLock.Configs
{
public class ESmartCredentials
{
[TomlPrecedingComment("If you have your lock bound to the app/cloud, we must get the device's password from the cloud for now\nFor this the username and password of an account the lock is shared with is required.")]
[TomlProperty("esmart_username")]
public string apiUsername { get; set; }

[TomlProperty("esmart_password")]
[TomlInlineComment("Leave blank if not using a cloud/app bound esmartlock")]
public string apiPassword { get; set; }

[TomlProperty("device_password")]
[TomlInlineComment("The password to the device, gotten from the cloud after a successful login.")]
public string DevicePassword { get; set; }
}
}
17 changes: 3 additions & 14 deletions Configs/MainConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,15 @@ public class MainConfig {
[TomlProperty("write_port")]
public int vrchatPort { get; set; }

[TomlPrecedingComment("\n--- Eseesmart lock Login ---\nIf you have your lock bound to the app/cloud, we must get the device's password from the cloud for now\n\nFor this the username and password of an account the lock is shared with is required.")]
[TomlProperty("esmart_username")]
public string apiUsername { get; set; }

[TomlProperty("esmart_password")]
[TomlInlineComment("Leave blank if not using a cloud/app bound esmartlock")]
public string apiPassword { get; set; }

[TomlProperty("device_password")]
[TomlInlineComment("The password to the device, gotten from the cloud after a successful login.")]
public string DevicePassword { get; set; }

[TomlProperty("Mode")]
public ApplicationMode Mode { get; set; }

[TomlProperty("Credentials for ESmartLock")]
public ESmartCredentials ESmartConfig { get; set; }

[TomlPrecedingComment("")]
[TomlProperty("Basic")]
public BasicMode BasicConfig { get; set; }

[TomlPrecedingComment("")]
[TomlProperty("Timer")]
public TimerMode TimerConfig { get; set; }
}
Expand Down
5 changes: 3 additions & 2 deletions Configs/TimerMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ public class TimerMode {
//[TomlInlineComment("Miniumum time that must pass before the system can unlock. Minimum Sand")]
public int absMin { get; set; }


[TomlProperty("absolute_max")]
//[TomlInlineComment("If the total time has reached this, it can not increase. How much total sand is there?")]
public int absMax { get; set; }

[TomlProperty("StartingTime")]
public DefaultTime StartTime { get; set; }

[TomlPrecedingComment("\n--- Incoming OSC Parameters ---")]
[TomlPrecedingComment("--- Incoming OSC Parameters ---")]
//[TomlInlineComment("When this Bool is true, it should increase the timer once by inc_step.")]
public string inc_parameter { get; set; }

Expand All @@ -32,7 +33,7 @@ public class TimerMode {
public int dec_step { get; set; }


[TomlPrecedingComment("\n-- Outgoing OSC Parameters ---")]
[TomlPrecedingComment("-- Outgoing OSC Parameters ---")]
public int readout_mode { get; set; }
public string readout_parameter { get; set; }
public string readout_parameter2 { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions ESmartLockAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static ESmartLockAPI() {

public static async Task<string> GetDevicePassword(string deviceAddress, string loginToken) {
var deviceInfoResponse = await client.PostAsync("http://web.iloveismarthome.com?m=lock&a=getLockInfoByMac", new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("user_name", ConfigManager.ApplicationConfig.apiUsername),
new KeyValuePair<string, string>("user_name", ConfigManager.ApplicationConfig.ESmartConfig.apiUsername),
new KeyValuePair<string, string>("loginToken", loginToken),
new KeyValuePair<string, string>("mac", deviceAddress)
}));
Expand Down Expand Up @@ -55,8 +55,8 @@ public static async Task<string> GetDevicePassword(string deviceAddress, string

public static async Task<string> Login() {
var loginResponse = await client.PostAsync("http://web.iloveismarthome.com?m=user&a=login", new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("user_name", ConfigManager.ApplicationConfig.apiUsername),
new KeyValuePair<string, string>("user_pwd", ConfigManager.ApplicationConfig.apiPassword),
new KeyValuePair<string, string>("user_name", ConfigManager.ApplicationConfig.ESmartConfig.apiUsername),
new KeyValuePair<string, string>("user_pwd", ConfigManager.ApplicationConfig.ESmartConfig.apiPassword),
new KeyValuePair<string, string>("type", "2"),
new KeyValuePair<string, string>("way", "0")
}));
Expand Down
6 changes: 4 additions & 2 deletions Logic/OSCTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task OnDecParam(OscMessage message) {
var shouldDec = (bool) message.Arguments[0];
if (shouldDec)
Console.WriteLine($"Param recieved - Attempting to remove {dec_step} minute(s)");
AddTime(dec_step*-1);
AddTime(dec_step);
}

public static void Setup() {
Expand Down Expand Up @@ -78,7 +78,7 @@ public static void Setup() {
}

dec_parameter = timerConfig.dec_parameter;
dec_step = timerConfig.dec_step;
dec_step = -timerConfig.dec_step;

//If dec_parameter is NOT null, then add a handler and print the added parameter.
if (dec_parameter != "") {
Expand Down Expand Up @@ -417,8 +417,10 @@ private static async void OnProgress(object sender, ElapsedEventArgs elapsedEven
VRChatConnector.SendToVRChat(message6BoolFalse);
VRChatConnector.SendToVRChat(message6Minutes);


var message6Seconds = new OscMessage(readout_param, Readout6Seconds);
var message6BoolTrue = new OscMessage(readout_param2, true);

VRChatConnector.SendToVRChat(message6BoolTrue);
VRChatConnector.SendToVRChat(message6Seconds);
break;
Expand Down
Loading

0 comments on commit 5fcb653

Please sign in to comment.