123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //
- // IHRoomLightManager.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/16.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- class IHRoomLightManager: NSObject ,IHViewManagerProtocolDelegate{
-
- var energyConsumptionData :ReportData?
- lazy var mainView: IHRoomLightView = {
- let mainView = IHRoomLightView()
- mainView.delegate = self
- return mainView
- }()
- // private var vc = UIViewController()
-
- private weak var vc : UIViewController?
-
- override init() {
- super.init()
- NotificationCenter.default.addObserver(self, selector: #selector(reloadNotify), name: NSNotification.Name(kNotificationIHNewEquipmentManagerEditEquipmentReload), object: nil)
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- @objc func reloadNotify(_ notif:Notification){
- let lightVC = self.vc as! IHRoomLightVCtr
- requestData((lightVC.dataSource?.id!)!)
- self.vc?.navigationBarTitle = notif.object as? String
- }
-
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- createUI()
- }
- func createUI() {
-
- mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight)
- self.vc!.view.addSubview(mainView)
- setNavigationBar()
- let lightVC = self.vc as! IHRoomLightVCtr
- self.vc?.navigationBarTitle = lightVC.dataSource?.name
-
- requestData((lightVC.dataSource?.id!)!)
- }
-
-
- func requestData(_ lightId:String) {
- // HUD.show(.progress)
- // HUD.hide(afterDelay: 20) { (isSuccess) in
- // if isSuccess == true{
- // g_showHUD("Request timeout")
- // }
- // }
- let queue = DispatchQueue.global()
- let group = DispatchGroup()
- queue.async(group: group, qos: .default, flags: []) {
- IHRoomLightService.share.getLightInfo(lightId, requestSuccess: { (data) in
- self.mainView.lightData = data
-
- }) {
-
- }
- }
-
- queue.async(group: group, qos: .default, flags: []) {
- IHRoomLightService.share.getLampReport(lightId, dateType: "0", dataType: "0", date: nil, requestSuccess: { (data) in
- self.mainView.reportData = data
- self.energyConsumptionData = data
- }) {
-
- }
- }
- group.notify(queue: queue) {
- log.debug("结束了")
- // HUD.hide()
- }
- }
- func setNavigationBar() {
- //导航栏的渲染方式
- let searchItem = UIBarButtonItem(image: UIImage(named: "历史数据")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
- let setItem = UIBarButtonItem(image: UIImage(named: "设置")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(modeSetAction))
- self.vc?.navigationItem.rightBarButtonItems = [searchItem,setItem]
- }
-
- @objc func modeSetAction() {
- let eqment = IHNewEquipmentVCtr()
- eqment.roomStyle = .equipmentEdit
- let aVC = self.vc as! IHRoomLightVCtr
- eqment.devData = aVC.dataSource
- eqment.navigationBarTitle = aVC.dataSource?.name
- self.vc?.navigationController?.pushViewController(eqment, animated: true)
-
- }
- @objc func mapAction1(){
- log.debug("点击了")
- let history = IHRoomLightHistoryVCtr()
- let lightVC = self.vc as! IHRoomLightVCtr
- let lightId = lightVC.dataSource?.id!
- history.devId = lightId
- history.devType = lightVC.dataSource?.devType
-
- IHRoomLightService.share.getLampReport(lightId!, dateType: "0", dataType: "1", date: nil, requestSuccess: { (data) in
- let lampHistory = (energy_consumption:self.energyConsumptionData,lighting_use_schedule:data)
- log.debug("self.lampHistory - \(lampHistory)")
- history.lampHistory = lampHistory as! (energy_consumption: ReportData, lighting_use_schedule: ReportData)
- self.vc?.navigationController?.pushViewController(history, animated: true)
- }) {
-
- }
-
-
- }
-
-
- }
- extension IHRoomLightManager: IHRoomLightViewDelegate{
- func rl_switchDataType(_ index: Int) {
- let lightVC = self.vc as! IHRoomLightVCtr
- let lightId = lightVC.dataSource?.id!
-
- var dateType = "0"
- if index == 0 {
- dateType = "0"
- }else if index == 1 {
- dateType = "4"
- }else if index == 2 {
- dateType = "1"
- }
- else if index == 3 {
- dateType = "2"
- }
- IHRoomLightService.share.getLampReport(lightId!, dateType: dateType, dataType: "0", date: nil, requestSuccess: { (data) in
- self.mainView.reportData = data
- }) {
-
- }
- }
-
- func rl_controlSwitch(_ status: String) {
- let lightVC = self.vc as! IHRoomLightVCtr
- let lightId = lightVC.dataSource?.id!
- IHRoomListService.share.setLampTurn(lightId: lightId!, status: status, requestSuccess: { (isSuccess) in
- self.requestLightInfo(lightId!)
- NotificationCenter.default.post(name: NSNotification.Name(kIHRoomListManagerNoticationReloadData), object: nil)
- }) {
-
- }
- }
-
- func rl_adjustBrightness(_ light: Int) {
- let lightVC = self.vc as! IHRoomLightVCtr
- let lightId = lightVC.dataSource?.id!
- IHRoomLightService.share.individualDimming(lightId: lightId!, light: "\(light)", requestSuccess: { (isSuccess) in
- self.requestLightInfo(lightId!)
- NotificationCenter.default.post(name: NSNotification.Name(kIHRoomListManagerNoticationReloadData), object: nil)
- }) {
-
- }
- }
-
- func rl_adjustColorTemperature(_ color: Int) {
- let lightVC = self.vc as! IHRoomLightVCtr
- let lightId = lightVC.dataSource?.id!
- IHRoomLightService.share.setLampColor(lightId: lightId!, color: "\(color)", requestSuccess: { (isSuccess) in
- self.requestLightInfo(lightId!)
- NotificationCenter.default.post(name: NSNotification.Name(kIHRoomListManagerNoticationReloadData), object: nil)
- }) {
-
- }
- }
-
- func rl_adjustColor(_ red: Int, green: Int, blue: Int) {
- let lightVC = self.vc as! IHRoomLightVCtr
- let lightId = lightVC.dataSource?.id!
- IHRoomLightService.share.setLampColorRGB(lightId!, colorR: "\(red)", colorG: "\(green)", colorB: "\(blue)", requestSuccess: { (isSuccess) in
- self.requestLightInfo(lightId!)
- NotificationCenter.default.post(name: NSNotification.Name(kIHRoomListManagerNoticationReloadData), object: nil)
- }) {
- }
- }
-
-
-
-
- func requestLightInfo(_ lightId:String) {
- log.debug("requestLightInfo")
- IHRoomLightService.share.getLightInfo(lightId, requestSuccess: { (data) in
- self.mainView.lightData = data
- }) {
- }
- }
-
- }
|