64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using PlantBox.Shared.Communication.Commands;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace PlantBox.Broker
|
|
{
|
|
class PlantBox
|
|
{
|
|
// General Info
|
|
public ulong ID { get; set; }
|
|
public string Name { get; set; }
|
|
public PlantType Type { get; set; }
|
|
public PlantState State { get; set; }
|
|
|
|
// Captors
|
|
public DateTime LastMeasureDate { get; set; }
|
|
public double TankLevel { get; set; }
|
|
public CaptorValue Humidity { get; set; }
|
|
public CaptorValue Luminosity { get; set; }
|
|
public CaptorValue Temperature { get; set; }
|
|
|
|
// Historic
|
|
public HistoricManager HistoricManager { get; set; }
|
|
|
|
// State conditions
|
|
public void UpdateState()
|
|
{
|
|
bool IsDay()
|
|
{
|
|
double hour = DateTime.Now.Hour;
|
|
|
|
return hour > 8 && hour < 20;
|
|
}
|
|
|
|
if (Humidity.Value < Humidity.Min || Humidity.Value > Humidity.Max)
|
|
{
|
|
State = PlantState.Warning;
|
|
}
|
|
if (IsDay() && Luminosity.Value < Luminosity.Min || Luminosity.Value > Luminosity.Max)
|
|
{
|
|
State = PlantState.Warning;
|
|
}
|
|
if (Temperature.Value < Temperature.Min || Temperature.Value > Temperature.Max)
|
|
{
|
|
State = PlantState.Warning;
|
|
}
|
|
if (TankLevel < 20)
|
|
{
|
|
State = PlantState.Warning;
|
|
}
|
|
if ((DateTime.Now - LastMeasureDate).TotalMinutes >= 7)
|
|
{
|
|
State = PlantState.Bad;
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{ID}:\n Name: {Name}\n Type: {Type}\n State: {State}";
|
|
}
|
|
}
|
|
}
|