Add Broker Info command client-side

This commit is contained in:
2019-04-24 20:07:34 +02:00
parent e3cc6392a7
commit 0f91751087

View File

@@ -79,7 +79,23 @@ namespace PlantBox.Broker
protected override void InfoCommand(CommandStream commandStream, CommandPacket packet)
{
throw new NotImplementedException();
InfoRequest infoRequest = new InfoRequest().Deserialize(packet.Arguments);
ulong id = packet.ID;
PlantBox plantBox = Broker.PlantBoxesManager[id];
if (plantBox == null)
{
throw new InvalidOperationException($"This PlantBox (${id}) does not exist");
}
var response = new InfoResponse
(
plantBox.Name, plantBox.Type, plantBox.State,
plantBox.Humidity.Min, plantBox.Humidity.Max,
plantBox.Luminosity.Min, plantBox.Luminosity.Max,
plantBox.Temperature.Min, plantBox.Temperature.Max
);
commandStream.Send(response.ToCommandPacket(id));
}
protected override void PingCommand(CommandStream commandStream, CommandPacket packet)