Skip to content

Commit

Permalink
Add support for Combo to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Jul 27, 2024
1 parent a4d5536 commit 4ea93ac
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion HSPI_IRobot/FeaturePageHandlers/ManageRobots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private string _getRobots() {
password = robot.Password,
stateString = robot.StateString,
ip = robot.ConnectedIp,
type = robot.Type == RobotType.Vacuum ? "vacuum" : "mop",
type = RobotType.Vacuum.ToString().ToLower(),
name = robot.GetName(),
sku = robot.Client?.Sku ?? "unknown",
softwareVersion = robot.Client?.SoftwareVersion ?? "unknown"
Expand Down
56 changes: 25 additions & 31 deletions HSPI_IRobot/HSPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using IRobotLANClient;
using IRobotLANClient.Enums;
using IRobotLANClient.Exceptions;
using IRobotLANClient.RobotInterfaces;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -158,11 +159,10 @@ public override void SetIOMulti(List<ControlEvent> colSend) {
break;

case RobotStatus.Evac:
if (robot.Type == RobotType.Vacuum) {
RobotVacuumClient roboVac = (RobotVacuumClient) robot.Client;
roboVac.Evac();
if (robot.Client is IVacuumClient client) {
client.Evac();
}

break;

case RobotStatus.Train:
Expand Down Expand Up @@ -341,28 +341,22 @@ private void HandleRobotStatusUpdate(object src, EventArgs arg) {
feature = robot.GetFeature(FeatureType.Error);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, robot.Client.ErrorCode);

switch (robot.Type) {
case RobotType.Vacuum:
RobotVacuumClient roboVac = (RobotVacuumClient) robot.Client;

// Bin
feature = robot.GetFeature(FeatureType.VacuumBin);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, (double) roboVac.BinStatus);

break;

case RobotType.Mop:
RobotMopClient roboMop = (RobotMopClient) robot.Client;

// Tank
feature = robot.GetFeature(FeatureType.MopTank);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, (double) roboMop.TankStatus);

// Pad type
feature = robot.GetFeature(FeatureType.MopPad);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, (double) roboMop.MopPadType);
if (robot.Client is IVacuumClient roboVac) {
// Bin
feature = robot.GetFeature(FeatureType.VacuumBin);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, (double) roboVac.BinStatus);
}

if (robot.Client is IMopClient roboMop) {
// Tank
feature = robot.GetFeature(FeatureType.MopTank);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, (double) roboMop.TankStatus);

break;
// Pad type
feature = robot.GetFeature(FeatureType.MopPad);
HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, (double) roboMop.MopPadType);

// TODO tank and dock tank level features for Combo
}

// Did our navigating state change?
Expand Down Expand Up @@ -459,23 +453,23 @@ public override string GetJuiDeviceConfigPage(int deviceRef) {
break;

case ConfigOption.BinFullPause:
currentSetting = ((RobotVacuumClient) robot.Client).BinFullPause ? "1" : "0";
currentSetting = ((IVacuumClient) robot.Client).BinFullPause ? "1" : "0";
break;

case ConfigOption.CleaningPassMode:
currentSetting = ((int) ((RobotVacuumClient) robot.Client).CleaningPassMode).ToString();
currentSetting = ((int) ((IVacuumClient) robot.Client).CleaningPassMode).ToString();
break;

case ConfigOption.WetMopPadWetness:
currentSetting = ((RobotMopClient) robot.Client).WetMopPadWetness.ToString();
currentSetting = ((IMopClient) robot.Client).WetMopPadWetness.ToString();
break;

case ConfigOption.WetMopPassOverlap:
currentSetting = ((RobotMopClient) robot.Client).WetMopRankOverlap.ToString();
currentSetting = ((IMopClient) robot.Client).WetMopRankOverlap.ToString();
break;

case ConfigOption.EvacAllowed:
currentSetting = ((RobotVacuumClient) robot.Client).EvacAllowed ? "1" : "0";
currentSetting = ((IVacuumClient) robot.Client).EvacAllowed ? "1" : "0";
break;

default:
Expand Down Expand Up @@ -639,7 +633,7 @@ private async void _createNewRobotDevice(string ip, string blid, string password
extraData.AddNamed("lastknownip", ip);
extraData.AddNamed("blid", blid);
extraData.AddNamed("password", password);
extraData.AddNamed("robottype", verifier.DetectedType == RobotType.Vacuum ? "vacuum" : "mop");
extraData.AddNamed("robottype", verifier.DetectedType.ToString().ToLower());
extraData.AddNamed("version", "1");

DeviceFactory factory = DeviceFactory.CreateDevice(Id)
Expand Down
26 changes: 18 additions & 8 deletions HSPI_IRobot/HsRobot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using HomeSeer.PluginSdk.Devices;
using HomeSeer.PluginSdk.Logging;
Expand Down Expand Up @@ -59,7 +60,7 @@ public HsRobot(int deviceRef) {

try {
PlugExtraData ped = PlugExtraData;
Type = ped["robottype"] == "vacuum" ? RobotType.Vacuum : RobotType.Mop;
Type = StringToRobotType(ped["robottype"]);
Blid = ped["blid"];
Password = ped["password"];

Expand All @@ -78,7 +79,7 @@ public HsRobot(int deviceRef) {
// Try to init again
try {
PlugExtraData ped = PlugExtraData;
Type = ped["robottype"] == "vacuum" ? RobotType.Vacuum : RobotType.Mop;
Type = StringToRobotType(ped["robottype"]);
Blid = ped["blid"];
Password = ped["password"];
} catch (KeyNotFoundException) {
Expand Down Expand Up @@ -111,12 +112,12 @@ public async Task AttemptConnect(string ip = null, bool skipStateCheck = false)
WriteLog(ELogType.Info, $"Attempting to connect to robot at IP {connectIp} ({Blid})");

Client = null;
RobotClient robot;
if (Type == RobotType.Vacuum) {
robot = new RobotVacuumClient(connectIp, Blid, Password);
} else {
robot = new RobotMopClient(connectIp, Blid, Password);
}
RobotClient robot = Type switch {
RobotType.Vacuum => new RobotVacuumClient(connectIp, Blid, Password),
RobotType.Mop => new RobotMopClient(connectIp, Blid, Password),
RobotType.Combo => new RobotComboClient(connectIp, Blid, Password),
_ => throw new ArgumentOutOfRangeException()
};

robot.OnStateUpdated += HandleDataUpdate;
robot.OnDebugOutput += (sender, args) => {
Expand Down Expand Up @@ -464,6 +465,15 @@ public ConfigOption[] GetSupportedOptions() {
.Where(option => Client.SupportsConfigOption(option))
.ToArray();
}

private static RobotType StringToRobotType(string type) {
return type switch {
"vacuum" => RobotType.Vacuum,
"mop" => RobotType.Mop,
"combo" => RobotType.Combo,
_ => RobotType.Unrecognized
};
}

private void WriteLog(ELogType logType, string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) {
// ReSharper disable once ExplicitCallerInfoArgument
Expand Down
11 changes: 6 additions & 5 deletions HSPI_IRobot/RobotOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using IRobotLANClient;
using IRobotLANClient.Enums;
using IRobotLANClient.RobotInterfaces;

namespace HSPI_IRobot;

Expand Down Expand Up @@ -151,23 +152,23 @@ public static bool ChangeSetting(HsRobot robot, ConfigOption option, int setting
return true;

case ConfigOption.BinFullPause:
((RobotVacuumClient) robot.Client).SetBinFullPause(settingValue != 0);
((IVacuumClient) robot.Client).SetBinFullPause(settingValue != 0);
return true;

case ConfigOption.CleaningPassMode:
((RobotVacuumClient) robot.Client).SetCleaningPassMode((CleaningPassMode) settingValue);
((IVacuumClient) robot.Client).SetCleaningPassMode((CleaningPassMode) settingValue);
return true;

case ConfigOption.WetMopPadWetness:
((RobotMopClient) robot.Client).SetWetMopPadWetness((byte) settingValue);
((IMopClient) robot.Client).SetWetMopPadWetness((byte) settingValue);
return true;

case ConfigOption.WetMopPassOverlap:
((RobotMopClient) robot.Client).SetWetMopRankOverlap((byte) settingValue);
((IMopClient) robot.Client).SetWetMopRankOverlap((byte) settingValue);
return true;

case ConfigOption.EvacAllowed:
((RobotVacuumClient) robot.Client).SetEvacAllowed(settingValue != 0);
((IVacuumClient) robot.Client).SetEvacAllowed(settingValue != 0);
return true;

default:
Expand Down
2 changes: 1 addition & 1 deletion IRobotLANClient/RobotInterfaces/IMopClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace IRobotLANClient.RobotInterfaces;

internal interface IMopClient {
public interface IMopClient {
public TankStatus TankStatus { get; internal set; }
public MopPadType MopPadType { get; internal set; }
public byte WetMopPadWetness { get; internal set; }
Expand Down
2 changes: 1 addition & 1 deletion IRobotLANClient/RobotInterfaces/IVacuumClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace IRobotLANClient.RobotInterfaces;

internal interface IVacuumClient {
public interface IVacuumClient {
public BinStatus BinStatus { get; internal set; }
public bool EvacAllowed { get; internal set; }
public bool BinFullPause { get; internal set; }
Expand Down

0 comments on commit 4ea93ac

Please sign in to comment.