Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batteryState to robot #1871

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/api/Controllers/Models/RobotResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class RobotResponse

public float BatteryLevel { get; set; }

public BatteryState? BatteryState { get; set; }

public float? PressureLevel { get; set; }

public IList<DocumentInfo> Documentation { get; set; }
Expand Down Expand Up @@ -61,6 +63,7 @@ public RobotResponse(Robot robot)
CurrentInstallation = robot.CurrentInstallation;
CurrentArea = robot.CurrentArea != null ? new AreaResponse(robot.CurrentArea) : null;
BatteryLevel = robot.BatteryLevel;
BatteryState = robot.BatteryState;
PressureLevel = robot.PressureLevel;
Documentation = robot.Documentation;
VideoStreams = robot.VideoStreams;
Expand Down
8 changes: 8 additions & 0 deletions backend/api/Database/Models/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public Robot(CreateRobotQuery createQuery, Installation installation, RobotModel

public float BatteryLevel { get; set; }

public BatteryState? BatteryState { get; set; }

public float? PressureLevel { get; set; }

public bool IsRobotPressureTooLow()
Expand Down Expand Up @@ -192,4 +194,10 @@ public enum RobotCapabilitiesEnum
docking_procedure,
return_to_home,
}

public enum BatteryState
{
Normal,
Charging,
}
}
4 changes: 4 additions & 0 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ private async void OnIsarBatteryUpdate(object? sender, MqttReceivedArgs mqttArgs
_logger.LogDebug("Semaphore acquired for updating battery");

var robot = await BatteryTimeseriesService.AddBatteryEntry(batteryStatus.BatteryLevel, batteryStatus.IsarId);
if (robot != null && robot.BatteryState != batteryStatus.BatteryState)
{
robot = await RobotService.UpdateRobotBatteryState(robot.Id, batteryStatus.BatteryState);
}

_updateRobotSemaphore.Release();
_logger.LogDebug("Semaphore released after updating battery");
Expand Down
4 changes: 4 additions & 0 deletions backend/api/MQTT/MessageModels/IsarBattery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using Api.Database.Models;

namespace Api.Mqtt.MessageModels
{
Expand All @@ -8,6 +9,9 @@ public class IsarBatteryMessage : MqttMessage
[JsonPropertyName("battery_level")]
public float BatteryLevel { get; set; }

[JsonPropertyName("battery_state")]
public BatteryState? BatteryState { get; set; }

[JsonPropertyName("robot_name")]
public string RobotName { get; set; }

Expand Down
Loading
Loading