Skip to content

Commit

Permalink
Disable setting pump schedules
Browse files Browse the repository at this point in the history
See #47
  • Loading branch information
LordMike committed May 23, 2021
1 parent eda8737 commit b6a71ba
Showing 1 changed file with 50 additions and 42 deletions.
92 changes: 50 additions & 42 deletions MBW.BlueRiiot2MQTT/Commands/SetPumpScheduleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
using MBW.Client.BlueRiiotApi.Objects;
using MBW.HassMQTT;
using MBW.HassMQTT.CommonServices.Commands;
using Microsoft.Extensions.Logging;
using MQTTnet;
using Newtonsoft.Json;

namespace MBW.BlueRiiot2MQTT.Commands
{
internal class SetPumpScheduleCommand : IMqttCommandHandler
{
private readonly ILogger<SetPumpScheduleCommand> _logger;
private readonly HassMqttManager _hassMqttManager;
private readonly FeatureUpdateManager _updateManager;
private readonly BlueClient _blueClient;

public SetPumpScheduleCommand(HassMqttManager hassMqttManager, FeatureUpdateManager updateManager, BlueClient blueClient)
public SetPumpScheduleCommand(ILogger<SetPumpScheduleCommand> logger, HassMqttManager hassMqttManager, FeatureUpdateManager updateManager, BlueClient blueClient)
{
_logger = logger;
_hassMqttManager = hassMqttManager;
_updateManager = updateManager;
_blueClient = blueClient;
Expand All @@ -32,53 +35,58 @@ public string[] GetFilter()

public async Task Handle(string[] topicLevels, MqttApplicationMessage message, CancellationToken token = new CancellationToken())
{
string poolId = topicLevels[2];
string newScheduleString = message.ConvertPayloadToString();
// Setting pump schedules seems to brick accounts, so it is disabled for now.
_logger.LogWarning("Setting pump schedules is disabled, see: https://github.com/LordMike/MBW.BlueRiiot2MQTT/issues/47");

// Get pool details
SwimmingPool pool = await _blueClient.GetSwimmingPool(poolId, token);
return;

if (string.IsNullOrEmpty(newScheduleString) ||
"none".Equals(newScheduleString, StringComparison.OrdinalIgnoreCase))
{
// Set none
pool.Characteristics.FilterPump = new SwimmingPoolCharacteristicsFilterPump
{
IsPresent = false,
OperatingType = "Manual"
};
}
else if ("manual".Equals(newScheduleString, StringComparison.OrdinalIgnoreCase))
{
// Set manual
pool.Characteristics.FilterPump = new SwimmingPoolCharacteristicsFilterPump
{
IsPresent = true,
OperatingType = "Manual"
};
}
else
{
// Set schedule
TimeSpan[][] newRanges = JsonConvert.DeserializeObject<TimeSpan[][]>(newScheduleString);
//string poolId = topicLevels[2];
//string newScheduleString = message.ConvertPayloadToString();

pool.Characteristics.FilterPump = new SwimmingPoolCharacteristicsFilterPump
{
IsPresent = true,
OperatingType = "Scheduled",
OperatingHours = newRanges.Select(s => new TimeRange
{
Start = s[0],
End = s[1]
}).ToList()
};
}
//// Get pool details
//SwimmingPool pool = await _blueClient.GetSwimmingPool(poolId, token);

SwimmingPool newPool = await _blueClient.PutSwimmingPool(poolId, pool, token);
//if (string.IsNullOrEmpty(newScheduleString) ||
// "none".Equals(newScheduleString, StringComparison.OrdinalIgnoreCase))
//{
// // Set none
// pool.Characteristics.FilterPump = new SwimmingPoolCharacteristicsFilterPump
// {
// IsPresent = false,
// OperatingType = "Manual"
// };
//}
//else if ("manual".Equals(newScheduleString, StringComparison.OrdinalIgnoreCase))
//{
// // Set manual
// pool.Characteristics.FilterPump = new SwimmingPoolCharacteristicsFilterPump
// {
// IsPresent = true,
// OperatingType = "Manual"
// };
//}
//else
//{
// // Set schedule
// TimeSpan[][] newRanges = JsonConvert.DeserializeObject<TimeSpan[][]>(newScheduleString);

_updateManager.Process(newPool, newPool);
// pool.Characteristics.FilterPump = new SwimmingPoolCharacteristicsFilterPump
// {
// IsPresent = true,
// OperatingType = "Scheduled",
// OperatingHours = newRanges.Select(s => new TimeRange
// {
// Start = s[0],
// End = s[1]
// }).ToList()
// };
//}

await _hassMqttManager.FlushAll(token);
//SwimmingPool newPool = await _blueClient.PutSwimmingPool(poolId, pool, token);

//_updateManager.Process(newPool, newPool);

//await _hassMqttManager.FlushAll(token);
}
}
}

0 comments on commit b6a71ba

Please sign in to comment.