2016-11-15 17:37:56 +00:00
|
|
|
|
using HAI_Shared;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.Serialization.Json;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace HAILogger
|
|
|
|
|
{
|
|
|
|
|
static class Helper
|
|
|
|
|
{
|
|
|
|
|
public static AreaContract ConvertArea(ushort id, clsArea area)
|
|
|
|
|
{
|
|
|
|
|
AreaContract ret = new AreaContract();
|
|
|
|
|
|
|
|
|
|
ret.id = id;
|
|
|
|
|
ret.name = area.Name;
|
|
|
|
|
ret.burglary = area.AreaBurglaryAlarmText;
|
|
|
|
|
ret.co = area.AreaGasAlarmText;
|
|
|
|
|
ret.fire = area.AreaFireAlarmText;
|
|
|
|
|
ret.water = area.AreaWaterAlarmText;
|
|
|
|
|
|
|
|
|
|
string mode = area.ModeText();
|
|
|
|
|
|
2016-11-21 02:31:27 +00:00
|
|
|
|
if (mode.Contains("DAY"))
|
2016-11-15 17:37:56 +00:00
|
|
|
|
ret.mode = "DAY";
|
|
|
|
|
else if (mode.Contains("NIGHT"))
|
|
|
|
|
ret.mode = "NIGHT";
|
|
|
|
|
else if (mode.Contains("AWAY"))
|
|
|
|
|
ret.mode = "AWAY";
|
|
|
|
|
else if (mode.Contains("VACATION"))
|
|
|
|
|
ret.mode = "VACATION";
|
2016-11-21 02:31:27 +00:00
|
|
|
|
else
|
|
|
|
|
ret.mode = "OFF";
|
2016-11-15 17:37:56 +00:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ZoneContract ConvertZone(ushort id, clsZone zone)
|
|
|
|
|
{
|
|
|
|
|
ZoneContract ret = new ZoneContract();
|
|
|
|
|
|
|
|
|
|
ret.id = id;
|
2016-11-21 02:31:27 +00:00
|
|
|
|
ret.zonetype = zone.ZoneType;
|
2016-11-15 17:37:56 +00:00
|
|
|
|
ret.name = zone.Name;
|
|
|
|
|
ret.status = zone.StatusText();
|
2016-11-21 02:31:27 +00:00
|
|
|
|
ret.temp = zone.TempText();
|
2016-11-15 17:37:56 +00:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static UnitContract ConvertUnit(ushort id, clsUnit unit)
|
|
|
|
|
{
|
|
|
|
|
UnitContract ret = new UnitContract();
|
|
|
|
|
|
|
|
|
|
ret.id = id;
|
|
|
|
|
ret.name = unit.Name;
|
|
|
|
|
|
|
|
|
|
if (unit.Status > 100)
|
|
|
|
|
ret.level = (ushort)(unit.Status - 100);
|
|
|
|
|
else if (unit.Status == 1)
|
|
|
|
|
ret.level = 100;
|
|
|
|
|
else
|
|
|
|
|
ret.level = 0;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ThermostatContract ConvertThermostat(ushort id, clsThermostat unit)
|
|
|
|
|
{
|
|
|
|
|
ThermostatContract ret = new ThermostatContract();
|
|
|
|
|
|
|
|
|
|
ret.id = id;
|
|
|
|
|
ret.name = unit.Name;
|
|
|
|
|
|
|
|
|
|
ushort temp, heat, cool, humidity;
|
|
|
|
|
|
|
|
|
|
ushort.TryParse(unit.TempText(), out temp);
|
|
|
|
|
ushort.TryParse(unit.HeatSetpointText(), out heat);
|
|
|
|
|
ushort.TryParse(unit.CoolSetpointText(), out cool);
|
|
|
|
|
ushort.TryParse(unit.HumidityText(), out humidity);
|
|
|
|
|
|
|
|
|
|
ret.temp = temp;
|
|
|
|
|
ret.humidity = humidity;
|
|
|
|
|
ret.heatsetpoint = heat;
|
|
|
|
|
ret.coolsetpoint = cool;
|
|
|
|
|
ret.mode = unit.Mode;
|
2016-11-21 02:31:27 +00:00
|
|
|
|
ret.fanmode = unit.FanMode;
|
|
|
|
|
ret.hold = unit.HoldStatus;
|
|
|
|
|
|
|
|
|
|
string status = unit.HorC_StatusText();
|
|
|
|
|
|
|
|
|
|
if (status.Contains("COOLING"))
|
|
|
|
|
ret.status = "COOLING";
|
|
|
|
|
else if (status.Contains("HEATING"))
|
|
|
|
|
ret.status = "HEATING";
|
|
|
|
|
else
|
|
|
|
|
ret.status = "OFF";
|
2016-11-15 17:37:56 +00:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int ConvertTemperature(int f)
|
|
|
|
|
{
|
|
|
|
|
// Convert to celsius
|
|
|
|
|
double c = 5.0 / 9.0 * (f - 32);
|
|
|
|
|
|
|
|
|
|
// Convert to omni temp (0 is -40C and 255 is 87.5C)
|
|
|
|
|
return (int)Math.Round((c + 40) * 2, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Serialize<T>(T obj)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
|
|
|
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
|
|
|
|
|
ser.WriteObject(stream, obj);
|
|
|
|
|
return Encoding.UTF8.GetString(stream.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|