mirror of
https://github.com/excaliburpartners/OmniLinkBridge
synced 2024-12-22 18:52:24 +00:00
0d83ded2a4
- Add interactive command line option and use path separator for mono compatibility
119 lines
3.3 KiB
C#
119 lines
3.3 KiB
C#
using HAI_Shared;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization.Json;
|
|
using System.Text;
|
|
|
|
namespace HAILogger
|
|
{
|
|
static class Helper
|
|
{
|
|
private static string lastmode = "OFF";
|
|
|
|
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;
|
|
|
|
if (area.ExitTimer > 0)
|
|
{
|
|
ret.mode = lastmode;
|
|
}
|
|
else
|
|
{
|
|
ret.mode = area.ModeText();
|
|
lastmode = ret.mode;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
public static ZoneContract ConvertZone(ushort id, clsZone zone)
|
|
{
|
|
ZoneContract ret = new ZoneContract();
|
|
|
|
ret.id = id;
|
|
ret.zonetype = zone.ZoneType;
|
|
ret.name = zone.Name;
|
|
ret.status = zone.StatusText();
|
|
ret.temp = zone.TempText();
|
|
|
|
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;
|
|
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";
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|