IHSensorManager.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // IHSensorManager.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/17.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import PKHUD
  10. class IHSensorManager: NSObject ,IHViewManagerProtocolDelegate{
  11. lazy var mainView: IHSensorView = {
  12. let mainView = IHSensorView()
  13. return mainView
  14. }()
  15. // private var vc = UIViewController()
  16. private weak var vc : UIViewController?
  17. override init() {
  18. super.init()
  19. NotificationCenter.default.addObserver(self, selector: #selector(reloadNotify), name: NSNotification.Name(kNotificationIHNewEquipmentManagerEditEquipmentReload), object: nil)
  20. }
  21. deinit {
  22. NotificationCenter.default.removeObserver(self)
  23. }
  24. @objc func reloadNotify(_ notif:Notification){
  25. let sensor = self.vc as! IHSensorVCtr
  26. sensor.navigationBarTitle = notif.object as? String
  27. requestData(sensor.devId!)
  28. }
  29. func bindController(_ vc: UIViewController) {
  30. self.vc = vc
  31. //IHSensorDeviceCell2
  32. NotificationCenter.default.addObserver(self, selector: #selector(changeSensorStatus), name: NSNotification.Name(KNotifiIHSensorDeviceCell2SetStatus), object: nil)
  33. let sensor = self.vc as! IHSensorVCtr
  34. requestData(sensor.devId!)
  35. createUI()
  36. }
  37. @objc private func changeSensorStatus(noti : Notification){
  38. let status = noti.userInfo?["setStatus"] as? String
  39. let sensor = self.vc as! IHSensorVCtr
  40. //开关探头3秒巡检指令
  41. HUD.flash(.progress, onView: nil, delay: 15) { (_) in
  42. HUD.flash(.label("Request timeout"), delay: 0.7)
  43. }
  44. IHSensorService.share.sensorSet_status(sensor.devId!, status: status!) { (msg, code) in
  45. if code != "0000"{
  46. DispatchQueue.main.async {
  47. HUD.flash(.label(msg), delay: 0.8)
  48. }
  49. self.requestData(sensor.devId!)
  50. }
  51. }
  52. }
  53. func requestData(_ devId:String) {
  54. IHSensorService.share.getSensorData(sensorId: devId, requestSuccess: { (sensordata) in
  55. self.mainView.sensorData = sensordata
  56. }) {
  57. }
  58. }
  59. func createUI() {
  60. // self.vc.navigationBarTitle = "Sensor-A"
  61. mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight)
  62. self.vc?.view.addSubview(mainView)
  63. setNavigationBar()
  64. }
  65. func setNavigationBar() {
  66. //导航栏的渲染方式
  67. let searchItem = UIBarButtonItem(image: UIImage(named: "历史数据")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
  68. let setItem = UIBarButtonItem(image: UIImage(named: "设置")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(modeSetAction))
  69. self.vc?.navigationItem.rightBarButtonItems = [searchItem,setItem]
  70. }
  71. @objc func modeSetAction() {
  72. let eqment = IHNewEquipmentVCtr()
  73. eqment.roomStyle = .equipmentEdit
  74. let aVC = self.vc as! IHSensorVCtr
  75. eqment.devData = aVC.dataSource
  76. eqment.navigationBarTitle = aVC.dataSource?.name
  77. self.vc?.navigationController?.pushViewController(eqment, animated: true)
  78. }
  79. @objc func mapAction1(){
  80. log.debug("点击了")
  81. HUD.show(.progress)
  82. HUD.hide(afterDelay: 20) { (isSuccess) in
  83. if isSuccess == true{
  84. g_showHUD("请求超时")
  85. }
  86. }
  87. let historyvc = IHRoomLightHistoryVCtr()
  88. let sensor = self.vc as! IHSensorVCtr
  89. historyvc.devId = sensor.devId!
  90. historyvc.devType = "3"
  91. IHSensorService.share.getSensorHistory(sensor.devId!, date_type: "0", requestSuccess: { (history) in
  92. HUD.hide()
  93. historyvc.sensorHistory = history
  94. self.vc?.navigationController?.pushViewController(historyvc, animated: true)
  95. }) {
  96. g_showHUD("该感应器没有历史数据")
  97. }
  98. }
  99. }