IHConfigGatawayDetailView.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. //
  2. // IHConfigGatawayDetailView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/8/25.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. import PKHUD
  11. protocol IHConfigGatawayDetailViewDelete : NSObjectProtocol{
  12. //选择关联的设备
  13. func selectIndexGetDeviceFromGateway( index : Int)
  14. //不关联的设备
  15. func selectIndexFoundDevice( index : Int)
  16. //添加未关联的设备
  17. func addDeviceToGateway(deviceUUid : String)
  18. //删除关联的设备
  19. func deleteDeviceFromGateway(deviceAddress : String)
  20. //开关灯(485/cw)
  21. func setLightTurnOn(_ isTurnOn : Bool, _ device : (address: String, type: String))
  22. //配置485灯传感器工作模式
  23. // 参数2:自动调光 ,参数3: 检测人体
  24. // 0: 不开启, 1: 开启
  25. func configLightWorkModel( _ device : (address: String, type: String),_ dodgeEnable : String, _ bodyEnable : String)
  26. // //给cw/485灯配置情景模式
  27. // func setAllLightScence(<#parameters#>) -> <#return type#> {
  28. // <#function body#>
  29. // }
  30. }
  31. class IHConfigGatawayDetailView: UIView {
  32. // var delegate:IHGatewayDetailViewDelegate?
  33. // var associatedList:[GatewayLamp]?{
  34. // didSet{
  35. // segmentedView.reloadData()
  36. // if let list = self.associatedList {
  37. // self.associatedCountLabel.text = "\(list.count)"
  38. // }
  39. // }
  40. // }
  41. //
  42. // var notAssociatedList:[GatewayLamp]?{
  43. // didSet{
  44. // segmentedView.reloadData()
  45. // }
  46. // }
  47. //
  48. // var gateway : GatewayData?{
  49. // didSet{
  50. // if let gateway = self.gateway {
  51. // if let gatewayName = gateway.network_name,let gatewayId = gateway.gatewayId {
  52. // self.gatewayNameLabel.text = gatewayName.isBlanck == false ? gatewayName : "网关"
  53. // self.gatewayIdLabel.text = "网关 · " + gatewayId
  54. // }
  55. // }
  56. //
  57. // }
  58. // }
  59. weak var delete : IHConfigGatawayDetailViewDelete?
  60. // let associateGatewayView = IHAssociateGatewayView()
  61. var assciateDeviceCallBack : (([(address : String ,type : String)]) -> Void)?
  62. var notAssciateDeviceCallBack : (([String]) -> Void)?
  63. // var deviceList : [(address : String ,type : String)]?
  64. @IBOutlet weak var gatewayNameLabel: UILabel!
  65. @IBOutlet weak var gatewayIdLabel: UILabel!
  66. @IBOutlet weak var associatedCountLabel: UILabel!
  67. @IBOutlet weak var listContentView: UIView!
  68. @IBOutlet weak var rightLayoutConstraint: NSLayoutConstraint!
  69. var gateway : gatewayInfor?{
  70. didSet{
  71. if let localGateway = self.gateway{
  72. self.gatewayNameLabel.text = "未命名"
  73. self.gatewayIdLabel.text = "GateWay . " + localGateway.SN!
  74. }
  75. }
  76. }
  77. var associatedDeviceList : [(address : String ,type : String)]?{
  78. didSet{
  79. segmentedView.reloadData()
  80. }
  81. }
  82. var notAssociateDeviceList : [String]?{
  83. didSet{
  84. segmentedView.reloadData()
  85. }
  86. }
  87. let titles = ["关联", "未关联"]
  88. var currentIndex : Int? = 0
  89. var totalItemWidth: CGFloat = 0 //总长度
  90. var segmentedDataSource:JXSegmentedBaseDataSource?
  91. var segmentedView = JXSegmentedView()
  92. lazy var listContainerView: JXSegmentedListContainerView! = {
  93. return JXSegmentedListContainerView(dataSource: self)
  94. }()
  95. override func awakeFromNib() {
  96. super.awakeFromNib()
  97. //添加设备后返回刷新
  98. NotificationCenter.default.addObserver(self, selector: #selector(updataNotAssciateDevice), name: NSNotification.Name(KNotifiAddDeviceToGateway), object: nil)
  99. //删除设备后返回刷新
  100. NotificationCenter.default.addObserver(self, selector: #selector(updataAssciateDevice), name: NSNotification.Name(KNotifiDeleteDeviceFromGateway), object: nil)
  101. //获取相关的设备
  102. NotificationCenter.default.addObserver(self, selector: #selector(getAssciateDevice), name: NSNotification.Name(KNonitifiGetAsssociatedDevices), object: nil)
  103. //获取未关联的设备
  104. NotificationCenter.default.addObserver(self, selector: #selector(getNotAssciateDevice), name: NSNotification.Name(KNonitifiGetNotAsssociatedDevices), object: nil)
  105. //开/关灯返回的状态
  106. NotificationCenter.default.addObserver(self, selector: #selector(turnOnLightFalse), name: NSNotification.Name(KNotifiTurnOnLightFalse), object: nil)
  107. //保存设备的位置在本地
  108. // let defaults = UserDefaults.standard
  109. // let locationArr = defaults.object(forKey: "allLocation")
  110. // if locationArr == nil {
  111. // //都是16进制数
  112. // let blackboardLightLocation = ["10","11","12"]
  113. // let classLightLocation = ["20","21","22","23","24","25","26","27","28"]
  114. // let curtainLocation = ["01","02"]
  115. // var allLocation = [[String : [String]]]()
  116. // allLocation.append(["blackboardLightLocation" : blackboardLightLocation])
  117. // allLocation.append(["classLightLocation" : classLightLocation])
  118. // allLocation.append(["curtainLocation" : curtainLocation])
  119. // defaults.set(allLocation, forKey: "allLocation")
  120. // defaults.synchronize()
  121. // }
  122. cinfigSegmentdView()
  123. }
  124. deinit {
  125. log.debug("IHConfigGatawayDetailView销毁")
  126. NotificationCenter.default.removeObserver(self)
  127. }
  128. //关开灯返回更新状态
  129. @objc private func turnOnLightFalse(noti : Notification){
  130. let oldDevice = noti.userInfo?["turnOn"] as? (address : String,type : String,turnOn : Bool)
  131. //更改此light的状态
  132. let defaults = UserDefaults.standard
  133. let arrDevice = defaults.object(forKey: "saveDeviceList") as? [[String : String]]
  134. var newDevice = [[String : String]]()
  135. if let arrDevice = arrDevice {
  136. newDevice = arrDevice
  137. for (index , subDic) in arrDevice.enumerated() {
  138. let address = subDic["address"]!
  139. //let bright = subDic["bright"]
  140. if oldDevice!.address == address && oldDevice!.turnOn == true && oldDevice!.type == "31"{
  141. newDevice.remove(at: index)
  142. newDevice.append(["address" : oldDevice!.address,"type" : oldDevice!.type,"bright" : "50","color" : "10"])
  143. break
  144. }
  145. if oldDevice!.address == address && oldDevice!.turnOn == false && oldDevice!.type == "31"{
  146. newDevice.remove(at: index)
  147. newDevice.append(["address" : oldDevice!.address,"type" : oldDevice!.type,"bright" : "0","color" : "10"])
  148. break
  149. }
  150. if oldDevice!.address == address && oldDevice!.turnOn == true && (oldDevice!.type == "04" || oldDevice!.type == "01"){
  151. newDevice.remove(at: index)
  152. newDevice.append(["address" : oldDevice!.address,"type" : oldDevice!.type,"bright" : "255","color" : "255"])
  153. break
  154. }
  155. if oldDevice!.address == address && oldDevice!.turnOn == false && (oldDevice!.type == "04" || oldDevice!.type == "01"){
  156. newDevice.remove(at: index)
  157. newDevice.append(["address" : oldDevice!.address,"type" : oldDevice!.type,"bright" : "0","color" : "255"])
  158. break
  159. }
  160. }
  161. defaults.set(newDevice, forKey: "saveDeviceList")
  162. defaults.synchronize()
  163. //刷新列表
  164. DispatchQueue.main.async {
  165. self.segmentedView.reloadData()
  166. }
  167. }
  168. }
  169. @objc private func getAssciateDevice(noti : Notification){
  170. let deviceList = noti.userInfo?["associatedDevice"] as? [(address : String,type : String)]
  171. if let deviceList = deviceList {
  172. self.associatedCountLabel.text = "\(deviceList.count)"
  173. //保存新数据在本地
  174. saveDeviceToPlist(deviceList: deviceList)
  175. //1. 保存485灯传感器的工作模式
  176. //2 . cw/485灯配置情景模式
  177. configDeviceWorkModel(deviceList: deviceList)
  178. self.associatedDeviceList = deviceList
  179. }
  180. }
  181. //2. 给新的灯配置模式
  182. //配置485灯传感器工作模式
  183. private func configDeviceWorkModel(deviceList :[(address : String ,type : String)]){
  184. let defults = UserDefaults.standard
  185. let deviceArr = defults.object(forKey: "deviceWorkModel") as? [[String : String]]
  186. //(address,type)
  187. if deviceList.count > 0 {
  188. if deviceArr != nil {
  189. //来新的了
  190. for subDevice in deviceList {
  191. var i = 0
  192. for subDic in deviceArr! {
  193. i = i + 1
  194. let address = subDic["address"]!
  195. if subDevice.address == address {
  196. break
  197. }
  198. if i == deviceArr!.count && subDevice.address != address && subDevice.type == "31"{
  199. //485的面板灯
  200. DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
  201. self.delete?.configLightWorkModel(subDevice, "1", "1")
  202. }
  203. }
  204. }
  205. }
  206. }else{
  207. //第一次
  208. for subDevice in deviceList {
  209. if subDevice.type == "31"{
  210. //485的面板灯
  211. DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
  212. self.delete?.configLightWorkModel(subDevice, "1", "1")
  213. }
  214. }
  215. }
  216. }
  217. }else{
  218. //没有值
  219. defults.set(nil, forKey: "deviceWorkModel")
  220. defults.synchronize()
  221. }
  222. }
  223. //更新后的数据保存在本地
  224. //绑定的与解绑的都来这里
  225. //1. 保存灯(address,type,bright,color)
  226. private func saveDeviceToPlist(deviceList :[(address : String ,type : String)]){
  227. let defults = UserDefaults.standard
  228. if deviceList.count > 0 {
  229. //保存灯(address,type,bright,color)
  230. let deviceArr = defults.object(forKey: "saveDeviceList") as? [[String : String]]
  231. if deviceArr != nil{
  232. //找新的
  233. var newDeviceList = [[String : String]]()
  234. newDeviceList = deviceArr!
  235. if deviceList.count > deviceArr!.count{
  236. //1.新增的 - 绑定
  237. bindedDevice(newDeviceList: newDeviceList, deviceList: deviceList, deviceArr: deviceArr!, defults: defults)
  238. }else{
  239. //2. 减少的 - 解绑
  240. reduceDevice(deviceList: deviceList, defults: defults)
  241. }
  242. // if newDeviceList.count > 0 {
  243. // for subDevice in deviceList{
  244. // var i = 0
  245. // for saveDevice in deviceArr! {
  246. // i = i + 1
  247. // let address = saveDevice["address"]!
  248. // if address == subDevice.address{
  249. // break
  250. // }
  251. // if i == deviceArr!.count && subDevice.type == "31" && address != subDevice.address{
  252. // newDeviceList.append(["address" : subDevice.address,"type" : subDevice.type,"bright" : "50","color" : "10"])
  253. // }
  254. // if i == deviceArr!.count && (subDevice.type == "04" || subDevice.type == "01" ) && address != subDevice.address {
  255. // newDeviceList.append(["address" : subDevice.address,"type" : subDevice.type,"bright" : "50","color" : "255"])
  256. // }
  257. // }
  258. // }
  259. // }
  260. //
  261. // defults.set(newDeviceList, forKey: "saveDeviceList")
  262. // defults.synchronize()
  263. }else{
  264. //第一次
  265. var saveDeviceList = [[String : String]]()
  266. for device in deviceList {
  267. //485灯的亮度: 0-50 ,cw灯的亮度: 0-255
  268. //485灯的色温 : 0-10, cw灯的色温: 0-255
  269. if device.type == "31"{
  270. //485
  271. saveDeviceList.append(["address" : device.address,"type" : device.type,"bright" : "50","color" : "10"])
  272. }
  273. if device.type == "04" || device.type == "01"{
  274. saveDeviceList.append(["address" : device.address,"type" : device.type,"bright" : "255","color":"255"])
  275. }
  276. }
  277. defults.set(saveDeviceList, forKey: "saveDeviceList")
  278. defults.synchronize()
  279. }
  280. }else{
  281. //没有值时
  282. defults.set(nil, forKey: "saveDeviceList")
  283. defults.synchronize()
  284. }
  285. }
  286. //相关联 -- 解绑后,会减少设备了
  287. private func reduceDevice( deviceList : [(address : String ,type : String)],defults : UserDefaults ){
  288. //deviceArr是保存在本地
  289. var newDeviceArr = [[String : String]]()
  290. for subDevice in deviceList{
  291. newDeviceArr.append(["address" : subDevice.address,"type" : subDevice.type,"bright" : "50","color" : "10"])
  292. }
  293. defults.set(newDeviceArr, forKey: "saveDeviceList")
  294. defults.synchronize()
  295. }
  296. //绑定 - 新添加的
  297. private func bindedDevice(newDeviceList :[[String : String]], deviceList : [(address : String ,type : String)],deviceArr : [[String : String]],defults : UserDefaults ){
  298. //deviceArr是保存在本地
  299. var newDeviceList = newDeviceList
  300. if newDeviceList.count > 0 {
  301. for subDevice in deviceList{
  302. var i = 0
  303. for saveDevice in deviceArr{
  304. i = i + 1
  305. let address = saveDevice["address"]!
  306. if address == subDevice.address{
  307. break
  308. }
  309. if i == deviceArr.count && subDevice.type == "31" && address != subDevice.address{
  310. newDeviceList.append(["address" : subDevice.address,"type" : subDevice.type,"bright" : "50","color" : "10"])
  311. }
  312. if i == deviceArr.count && (subDevice.type == "04" || subDevice.type == "01" ) && address != subDevice.address {
  313. newDeviceList.append(["address" : subDevice.address,"type" : subDevice.type,"bright" : "50","color" : "255"])
  314. }
  315. }
  316. }
  317. }
  318. defults.set(newDeviceList, forKey: "saveDeviceList")
  319. defults.synchronize()
  320. }
  321. @objc private func getNotAssciateDevice(noti : Notification){
  322. let deviceList = noti.userInfo?["notAssociatedDevice"] as? [String]
  323. if let deviceList = deviceList {
  324. self.notAssociateDeviceList = deviceList
  325. }
  326. }
  327. @objc private func updataAssciateDevice(){
  328. self.delete?.selectIndexGetDeviceFromGateway(index: self.currentIndex!)
  329. }
  330. @objc private func updataNotAssciateDevice(){
  331. self.delete?.selectIndexFoundDevice(index : self.currentIndex!)
  332. }
  333. override func layoutSubviews() {
  334. super.layoutSubviews()
  335. segmentedView.frame = CGRect(x: 20, y: 0, width: totalItemWidth, height: 30)
  336. listContainerView.frame = CGRect(x: 0, y: 40, width: KSCREENWIDTH, height: self.listContentView.bounds.size.height - 40)
  337. if KNavBarHeight == 64 {
  338. self.rightLayoutConstraint.constant = 60
  339. }
  340. }
  341. }
  342. extension IHConfigGatawayDetailView{
  343. func cinfigSegmentdView() {
  344. totalItemWidth = UIScreen.main.bounds.size.width - 20*2
  345. backgroundColor = .white
  346. let titleDataSource = JXSegmentedTitleDataSource()
  347. titleDataSource.itemContentWidth = totalItemWidth/CGFloat(titles.count)
  348. titleDataSource.titles = titles
  349. titleDataSource.titleNormalFont = UIFont(name: Alibaba_PuHuiTi_Regular, size: 13)!
  350. titleDataSource.titleSelectedFont = UIFont(name: Alibaba_PuHuiTi_Bold, size: 13)!
  351. titleDataSource.isTitleMaskEnabled = true
  352. titleDataSource.titleNormalColor = UIColor(hexString: "#657085")!
  353. titleDataSource.titleSelectedColor = UIColor(hexString: "#FFFFFF")!
  354. titleDataSource.itemSpacing = 0
  355. // titleDataSource.itemContentWidth = 120
  356. //titleDataSource.isItemSpacingAverageEnabled = false
  357. segmentedDataSource = titleDataSource
  358. segmentedView.dataSource = segmentedDataSource
  359. segmentedView.layer.masksToBounds = true
  360. segmentedView.layer.cornerRadius = 15
  361. segmentedView.backgroundColor = UIColor(hexString: "#F6F8F7")
  362. segmentedView.delegate = self
  363. self.listContentView.addSubview(segmentedView)
  364. let indicator = JXSegmentedIndicatorBackgroundView()
  365. indicator.indicatorHeight = 25
  366. indicator.backgroundWidthIncrement = -10
  367. // #05CFAB
  368. indicator.indicatorColor = UIColor(hexString: "#573F95")!
  369. indicator.layer.shadowColor = UIColor(hexString: "#573F95")!.cgColor
  370. indicator.layer.shadowRadius = 3
  371. indicator.layer.shadowOffset = CGSize.zero
  372. indicator.layer.shadowOpacity = 0.7
  373. segmentedView.indicators = [indicator]
  374. segmentedView.listContainer = listContainerView
  375. self.listContentView.addSubview(listContainerView)
  376. self.segmentedView.contentScrollView = self.listContainerView.scrollView
  377. }
  378. }
  379. extension IHConfigGatawayDetailView : JXSegmentedViewDelegate{
  380. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  381. // if let delegate = self.delegate {
  382. // delegate.equipmentlistViewdidSelectedItemAt(index)
  383. // }
  384. // self.associateGatewayView.delegate = self
  385. //
  386. self.currentIndex = index
  387. if index == 0 {
  388. HUD.flash(.progress)
  389. self.delete?.selectIndexGetDeviceFromGateway(index: index)
  390. self.assciateDeviceCallBack = { (deviceList : [(address : String ,type : String)]) in
  391. //保存新数据在本地
  392. self.saveDeviceToPlist(deviceList: deviceList)
  393. //保存485灯传感器的工作模式
  394. self.configDeviceWorkModel(deviceList: deviceList)
  395. self.associatedCountLabel.text = "\(deviceList.count)"
  396. self.associatedDeviceList = deviceList
  397. self.segmentedDataSource?.reloadData(selectedIndex: self.currentIndex!)
  398. // if deviceList.count > 0{
  399. //
  400. //
  401. //
  402. // // self.deviceList = deviceList
  403. // // view.associatedDeviceList = deviceList
  404. //
  405. //// self.associatedCountLabel.text = "\(deviceList.count)"
  406. // // self.deviceList = deviceList
  407. // //// view.associatedDeviceList = deviceList
  408. // }
  409. }
  410. }else{
  411. HUD.flash(.progress)
  412. self.delete?.selectIndexFoundDevice(index: index)
  413. self.notAssciateDeviceCallBack = { (deviceUUidList : [String]) in
  414. self.notAssociateDeviceList = deviceUUidList
  415. // if deviceUUidList.count > 0{
  416. // //view.notAssociatedDeviceList = deviceUUidList
  417. //
  418. //
  419. //// self.segmentedDataSource?.reloadData(selectedIndex: self.currentIndex!)
  420. // }
  421. }
  422. // self.delete?.selectIndexFoundDevice(index: index)
  423. // self.notAssciateDeviceCallBack = { (deviceList : [(address : String ,type : String)]) in
  424. //
  425. // if deviceList.count > 0{
  426. //
  427. // self.associatedCountLabel.text = "\(deviceList.count)"
  428. // // view.notAssociatedDeviceList = deviceList
  429. //
  430. // }
  431. //
  432. // }
  433. }
  434. // self.currentIndex = index
  435. // if let dotDataSource = segmentedDataSource as? JXSegmentedDotDataSource {
  436. // //先更新数据源的数据
  437. // dotDataSource.dotStates[index] = false
  438. // //再调用reloadItem(at: index)
  439. // segmentedView.reloadItem(at: index)
  440. // }
  441. }
  442. }
  443. extension IHConfigGatawayDetailView : JXSegmentedListContainerViewDataSource{
  444. func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
  445. if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
  446. return titleDataSource.dataSource.count
  447. }
  448. return 0
  449. }
  450. func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
  451. let view = IHAssociateGatewayView()
  452. view.delegate = self
  453. view.currentIndex = index
  454. // associateGatewayView.delegate = self
  455. // associateGatewayView.currentIndex = index
  456. // self.associateGatewayView.currentIndex = index
  457. if index == 0 {
  458. if let associatedDeviceList = self.associatedDeviceList {
  459. self.associatedCountLabel.text = "\(associatedDeviceList.count)"
  460. view.associatedDeviceList = self.associatedDeviceList
  461. }
  462. // if let associate = self.associatedList {
  463. // view.associatedList = associate
  464. // }
  465. // if let deviceList = self.deviceList{
  466. // self.associateGatewayView.associatedDeviceList = deviceList
  467. // }
  468. //
  469. // HUD.flash(.progress)
  470. //
  471. // self.delete?.selectIndexGetDeviceFromGateway(index: index)
  472. // self.assciateDeviceCallBack = { (deviceList : [(address : String ,type : String)]) in
  473. // if deviceList.count > 0{
  474. // self.associatedCountLabel.text = "\(deviceList.count)"
  475. //// self.deviceList = deviceList
  476. // view.associatedDeviceList = deviceList
  477. //
  478. // }
  479. //
  480. // }
  481. }else{
  482. if let notAssociateDeviceList = self.notAssociateDeviceList {
  483. view.notAssociatedDeviceList = notAssociateDeviceList
  484. }
  485. // if let notassciate = self.notAssociatedList {
  486. // view.notAssociatedList = notassciate
  487. // }
  488. // if let deviceList = self.deviceList{
  489. // self.associateGatewayView.notAssociatedDeviceList = deviceList
  490. // }
  491. // HUD.flash(.progress)
  492. // self.delete?.selectIndexFoundDevice(index: index)
  493. // self.notAssciateDeviceCallBack = { (deviceUUidList : [String]) in
  494. //
  495. // if deviceUUidList.count > 0{
  496. // view.notAssociatedDeviceList = deviceUUidList
  497. //
  498. // }
  499. //
  500. // }
  501. // if let notassciateList = self.deviceList{
  502. // view.notAssociatedDeviceList = notassciateList
  503. // }
  504. }
  505. return view
  506. }
  507. }
  508. extension IHConfigGatawayDetailView : IHAssociateGatewayViewDelete{
  509. //开关灯(485/cw)
  510. func controlightOn(_ isTurnON: Bool, _ device: (address: String, type: String)) {
  511. delete?.setLightTurnOn(isTurnON, device)
  512. }
  513. //删除设备
  514. func deviceDisconteGateway(_ deviceAddress: String) {
  515. delete?.deleteDeviceFromGateway(deviceAddress: deviceAddress)
  516. }
  517. //设备添加到网关
  518. func deviceConnectGateway(_ deviceUUId: String) {
  519. HUD.flash(.progress)
  520. delete?.addDeviceToGateway(deviceUUid: deviceUUId)
  521. }
  522. //搜索相关连的和不相关连的设备
  523. func emptyViewSearchDataSegment(_ index: Int) {
  524. if index == 0{
  525. delete?.selectIndexGetDeviceFromGateway(index: index)
  526. }else{
  527. delete?.selectIndexFoundDevice(index: index)
  528. }
  529. }
  530. // func deviceConnectGateway(_ deviceId: String) {
  531. // guard let gateway = self.gateway else { return }
  532. // if let delegate = self.delegate {
  533. // delegate.deviceConnectGateway(deviceId, gatewayId: gateway.gatewayId!)
  534. // }
  535. // }
  536. // func deviceDisconteGateway(_ deviceId: String) {
  537. // guard let gateway = self.gateway else { return }
  538. // if let delegate = self.delegate {
  539. // delegate.deviceDisconteGateway(deviceId, gatewayId: gateway.gatewayId!)
  540. // }
  541. // }
  542. // func controlightOn(_ isTurnON: Bool, lampId: String) {
  543. // guard let gateway = self.gateway else { return }
  544. // if let delegate = self.delegate {
  545. // delegate.controlightOn(lampId: lampId, gatewayId: gateway.gatewayId!, status: isTurnON == false ? "0" : "1")
  546. // }
  547. // }
  548. }