using System;
using System.Collections.Generic;
using HDL_ON.DAL;
namespace HDL_ON.Entity
{
public class DB_ResidenceData
{
public DB_ResidenceData()
{
}
///
/// 住宅名称
///
public string residenceName;
///
/// 住宅图片
///
public string residenceImage;
///
/// 房间列表
///
public List rooms = new List();
///
/// 功能列表
///
public List functions = new List();
///
/// 场景列表
///
public List scenes = new List();
static DB_ResidenceData instance;
public static DB_ResidenceData residenceData
{
get
{
if (instance == null)
{
try
{
var residenceDataBytes = FileUtils.ReadFile("DB_ResidenceData");
var userConfigString = CommonPage.MyEncodingUTF8.GetString(residenceDataBytes);
DB_ResidenceData temp = null;
if (userConfigString != null)
{
temp = Newtonsoft.Json.JsonConvert.DeserializeObject(userConfigString);
}
if (temp == null)
{
instance = new DB_ResidenceData { };
}
else
{
instance = temp;
}
}
catch { }
#if DEBUG
instance.residenceName = "妮儿的家";
instance.residenceImage = "Classification/Room/Roombg.png";
var r = new Room() { sid = "0001", name = "Room-1", floor = "1F", backgroundImage = "Classification/Room/Roombg.png" };
/*
r.functions.Add(new Function()
{
sid = "000000000000000000000000000000000001",
funcType = FunctionType.AC,
name = "空调",
roomIdList = new List() { "0001" },
lastState = "制冷 中风 18°C",
bus_Data = "{" +
"\"SubnetID\":42" + "," +
"\"DeviceID\":8" + "," +
"\"LoopID\":1" +
"}",
});
r.functions.Add(new Dimmer()
{
sid = "0001002019101209000025670400010002",
funcType = FunctionType.Light,
name = "客厅灯",
roomIdList = new List() { "0001" },
lastState = "20%",
bus_Data = "{" +
"\"SubnetID\":111" + "," +
"\"DeviceID\":2" + "," +
"\"LoopID\":1" +
"}",
});
r.functions.Add(new Light()
{
sid = "000000000000000000000000000000000003",
funcType = FunctionType.Curtain,
name = "窗帘",
roomIdList = new List() { "0001" },
lastState = "20%",
bus_Data = "{" +
"\"SubnetID\":42" + "," +
"\"DeviceID\":7" + "," +
"\"LoopID\":1" +
"}",
});
r.functions.Add(new Function()
{
sid = "000000000000000000000000000000000004",
funcType = FunctionType.FloorHeating,
name = "地热",
roomIdList = new List() { "0001" },
lastState = ""
});
r.functions.Add(new Light()
{
sid = "0001002019101209000025670400010005",
funcType = FunctionType.Light,
name = "客厅大灯",
roomIdList = new List() { "0001" },
bus_Data = "{" +
"\"SubnetID\":111" + "," +
"\"DeviceID\":6" + "," +
"\"LoopID\":1" +
"}",
});
*/
//--------------------
instance.functions.Add(new Function()
{
sid = "000000000000000000000000000000000001",
funcType = FunctionType.AC,
name = "空调",
roomIdList = new List() { "0001" },
collection = true,
lastState = "制冷 中风 18°C",
bus_Data = "{" +
"\"SubnetID\":42" + "," +
"\"DeviceID\":8" + "," +
"\"LoopID\":1" +
"}",
});
instance.functions.Add(new Dimmer()
{
sid = "0001002019101209000025670400010002",
funcType = FunctionType.Light,
name = "客厅灯",
roomIdList = new List() { "0001" },
lastState = "20%",
bus_Data = "{" +
"\"SubnetID\":111" + "," +
"\"DeviceID\":2" + "," +
"\"LoopID\":1" +
"}",
});
instance.functions.Add(new Light()
{
sid = "0001002019101209000025670400010005",
funcType = FunctionType.Light,
name = "客厅大灯",
roomIdList = new List() { "0001" },
collection = true,
bus_Data = "{" +
"\"SubnetID\":111" + "," +
"\"DeviceID\":6" + "," +
"\"LoopID\":1" +
"}",
});
instance.functions.Add(new Function()
{
sid = "000000000000000000000000000000000003",
funcType = FunctionType.Curtain,
name = "窗帘",
roomIdList = new List() { "0001" },
lastState = "20%"
});
instance.functions.Add(new Function()
{
sid = "000000000000000000000000000000000004",
funcType = FunctionType.FloorHeating,
collection = true,
name = "地热",
roomIdList = new List() { "0001" },
lastState = ""
});
instance.rooms.Add(r);
#endif
}
return instance;
}
}
public void SaveResidenceData()
{
var ssd = CommonPage.MyEncodingUTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
FileUtils.WriteFileByBytes("DB_ResidenceData", ssd);
}
//public List busDeviceList = new List();
//public void InitBusDeivces()
//{
// foreach(var room in rooms)
// {
// foreach(var function in room.functions)
// {
// if (!string.IsNullOrEmpty(function.bus_Data))
// {
// busDeviceList.Add(function);
// }
// }
// }
//}
///
/// 刷新住宅里面的搜索设备状态
///
public void RefreshResidenceFunctionStatus()
{
foreach (var function in functions)
{
if (!string.IsNullOrEmpty(function.bus_Data))
{
if(function.funcType == FunctionType.Light)
{
Control.Send("read", function, 3);
}
}
else
{
}
}
}
}
}