|
|
|
@ -340,54 +340,89 @@ namespace hass_workstation_service.Data
|
|
|
|
|
|
|
|
|
|
public void AddConfiguredSensor(AbstractSensor sensor)
|
|
|
|
|
{
|
|
|
|
|
this.ConfiguredSensors.Add(sensor);
|
|
|
|
|
sensor.PublishAutoDiscoveryConfigAsync();
|
|
|
|
|
AddSensor(sensor);
|
|
|
|
|
WriteSensorSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddConfiguredCommand(AbstractCommand command)
|
|
|
|
|
{
|
|
|
|
|
this.ConfiguredCommands.Add(command);
|
|
|
|
|
command.PublishAutoDiscoveryConfigAsync();
|
|
|
|
|
AddCommand(command);
|
|
|
|
|
WriteCommandSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void DeleteConfiguredSensor(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var sensorToRemove = this.ConfiguredSensors.FirstOrDefault(s => s.Id == id);
|
|
|
|
|
if (sensorToRemove != null)
|
|
|
|
|
public void AddConfiguredSensors(List<AbstractSensor> sensors)
|
|
|
|
|
{
|
|
|
|
|
await sensorToRemove.UnPublishAutoDiscoveryConfigAsync();
|
|
|
|
|
this.ConfiguredSensors.Remove(sensorToRemove);
|
|
|
|
|
sensors.ForEach(sensor => AddSensor(sensor));
|
|
|
|
|
WriteSensorSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
public void AddConfiguredCommands(List<AbstractCommand> commands)
|
|
|
|
|
{
|
|
|
|
|
Log.Logger.Warning($"sensor with id {id} not found");
|
|
|
|
|
commands.ForEach(command => AddCommand(command));
|
|
|
|
|
WriteCommandSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void DeleteConfiguredSensor(Guid id)
|
|
|
|
|
{
|
|
|
|
|
await DeleteSensor(id);
|
|
|
|
|
WriteSensorSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void DeleteConfiguredCommand(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var commandToRemove = this.ConfiguredCommands.FirstOrDefault(s => s.Id == id);
|
|
|
|
|
if (commandToRemove != null)
|
|
|
|
|
await DeleteCommand(id);
|
|
|
|
|
WriteCommandSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void UpdateConfiguredSensor(Guid id, AbstractSensor sensor)
|
|
|
|
|
{
|
|
|
|
|
await commandToRemove.UnPublishAutoDiscoveryConfigAsync();
|
|
|
|
|
this.ConfiguredCommands.Remove(commandToRemove);
|
|
|
|
|
await DeleteSensor(id);
|
|
|
|
|
AddSensor(sensor);
|
|
|
|
|
WriteSensorSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void UpdateConfiguredCommand(Guid id, AbstractCommand command)
|
|
|
|
|
{
|
|
|
|
|
await DeleteCommand(id);
|
|
|
|
|
AddCommand(command);
|
|
|
|
|
WriteCommandSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
private void AddSensor(AbstractSensor sensor)
|
|
|
|
|
{
|
|
|
|
|
Log.Logger.Warning($"command with id {id} not found");
|
|
|
|
|
ConfiguredSensors.Add(sensor);
|
|
|
|
|
sensor.PublishAutoDiscoveryConfigAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddCommand(AbstractCommand command)
|
|
|
|
|
{
|
|
|
|
|
ConfiguredCommands.Add(command);
|
|
|
|
|
command.PublishAutoDiscoveryConfigAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddConfiguredSensors(List<AbstractSensor> sensors)
|
|
|
|
|
private async Task DeleteSensor(Guid id)
|
|
|
|
|
{
|
|
|
|
|
sensors.ForEach((sensor) => this.ConfiguredSensors.Add(sensor));
|
|
|
|
|
WriteSensorSettingsAsync();
|
|
|
|
|
var sensorToRemove = ConfiguredSensors.FirstOrDefault(s => s.Id == id);
|
|
|
|
|
if (sensorToRemove == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Logger.Warning($"sensor with id {id} not found");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await sensorToRemove.UnPublishAutoDiscoveryConfigAsync();
|
|
|
|
|
ConfiguredSensors.Remove(sensorToRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DeleteCommand(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var commandToRemove = ConfiguredCommands.FirstOrDefault(c => c.Id == id);
|
|
|
|
|
if (commandToRemove == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Logger.Warning($"command with id {id} not found");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await commandToRemove.UnPublishAutoDiscoveryConfigAsync();
|
|
|
|
|
ConfiguredCommands.Remove(commandToRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|