lss
2020-05-20 a6c8525a85eae4c64b90b651d42b6c1f6d0df90f
ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.SmartSound
{
@@ -20,7 +21,7 @@
            // iniData();//先加载模拟数据
            this.ScrollEnabled = false;
            //设置标题信息
            base.SetTitleText("语音控制");
@@ -77,19 +78,115 @@
            if (isAdd)
            {
                mSmartSound = new SmartSound();
                mSmartSound.HomeID = Config.Instance.Home.Id;
                mSmartSound.UserID = Config.Instance.Guid;
                Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//楼层列表
                if (floorDictionary.Count < 1)
                {
                    //没有楼层
                    //没有楼层,模拟一个
                    SmartSound.Layer layer = new SmartSound.Layer();
                    layer.LayerID = "0000";
                    layer.LayerName = "一楼";
                    layer.RoomList.Clear();
                    //添加房间
                    SmartSound.Room smartRoom = null;
                    var roomList = HdlRoomLogic.Current.GetAllListRooms();
                    for (int i = 0; i < roomList.Count; i++)
                    {
                        Room room = roomList[i];
                        smartRoom = new SmartSound.Room();
                        layer.RoomList.Add(smartRoom);
                        smartRoom.RoomID = room.Id;
                        smartRoom.RoomName = room.Name;
                        smartRoom.DeviceList.Clear();
                        smartRoom.SceneList.Clear();
                        //添加设备  // 灯光、窗帘、场景、空调
                        for (int j = 0; j < room.ListDevice.Count; j++)
                        {
                            string key = room.ListDevice[j].ToString();
                            var device = LocalDevice.Current.GetDevice(key);
                            SmartSound.Device smartDevice = new SmartSound.Device();
                            smartDevice.Id = device.DeviceID.ToString();//设备 Id
                            smartDevice.DeviceAddress = device.DeviceAddr;//设备 MAC
                            smartDevice.Epoint = device.DeviceEpoint;//设备端口
                            smartDevice.ClusterID = 0;
                            smartDevice.DeviceName = device.DeviceName;//设备名称
                            smartDevice.NicksName = "";
                            smartDevice.DeviceType = getDeviceType(device);//设备类型
                            smartDevice.GatewayID = device.CurrentGateWayId;//网关 Id
                            smartDevice.RoomID = room.Id;//房间 Id
                            smartRoom.DeviceList.Add(smartDevice);
                        }
                        var sceneList = HdlSceneLogic.Current.GetRoomSceneList(room);
                        //添加场景
                        for (int j = 0; j < sceneList.Count; j++)
                        {
                            SceneUI scene = sceneList[j];
                            SmartSound.Scene smartScene = new SmartSound.Scene();
                            smartScene.Id = scene.DeviceID.ToString();
                            smartScene.SceneName = scene.Name;
                            smartScene.SceneID = scene.Id;
                            smartScene.DelayTime = scene.DelayTime;
                            smartScene.ClusterID = 0;
                            smartScene.NicksName = "";
                            smartScene.RoomID = room.Id;
                            smartRoom.SceneList.Add(smartScene);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Zigbee设备类型转换为智能音箱使用的类型
        /// </summary>
        /// <returns></returns>
        private int getDeviceType(ZigBee.Device.CommonDevice device)
        {
            int type = 0;//1=开关灯,2=调光灯,3=RGB 灯,4=窗帘模块,5=开合帘,6=卷帘,7=空调,8=面板,9=新风
            if (device.Type == DeviceType.OnOffOutput && device.DfunctionType == DeviceFunctionType.A灯光)
            {
                type = 1;//这里面的就是继电器灯光了
            }
            else if (device.Type == DeviceType.DimmableLight)
            {
                type = 2;//调光
            }
            else if (device.Type == DeviceType.ColorDimmableLight)
            {
                type = 3;
            }
            else if (device.Type == DeviceType.WindowCoveringDevice)
            {
                //窗帘
                if (((Rollershade)device).WcdType == 4)//开合帘
                {
                    type = 5;
                }
                else if (((Rollershade)device).WcdType == 0)//卷帘
                    type = 6;//卷帘
            }
            else if (device.Type == DeviceType.Thermostat)
            {
                type = 7;
            }
            else if (device.Type == DeviceType.FreshAir)
            {
                type = 9;
            }
            return type;
        }
        private void iniView()