123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // IHAssociatedGatewayCell.swift
- // Inhealth
- //
- // Created by weclouds on 2020/8/25.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- class IHAssociatedGatewayCell: UITableViewCell {
-
- var turnonCallback :((Bool)->Void)?
- var disconnectCallback:(()->Void)?
-
- // var gateDevice:GatewayLamp?{
- // didSet{
- // if let data = self.gateDevice {
- // if let devType = data.type,let image = data.image ,let name = data.name,let devId = data.deviceId,let status = data.status{
- // if devType == "0" || devType == "1" {
- // self.lampTurnOnBtn.isHidden = false
- // //ic_ordinary_light
- // self.devIcon.netImage(url: image, placeholder: "全开")
- // }else if devType == "2"{
- // //Sensor ic_sensor
- // self.devIcon.netImage(url: image, placeholder: "Sensor")
- // self.lampTurnOnBtn.isHidden = true
- // }else if devType == "3"{
- // self.lampTurnOnBtn.isHidden = true
- // self.devIcon.netImage(url: image, placeholder: "ic_purifier")
- // }
- // if status == "0" {
- // self.lampTurnOnBtn.isSelected = false
- // }else if status == "1"{
- // self.lampTurnOnBtn.isSelected = true
- // }
- // self.devName.text = name.isBlanck == false ? name : "Unnamed"
- // self.devId.text = devId
- // }
- // }
- // }
- // }
- //
-
- var gateDevice : (address : String ,type : String)?{
- didSet{
- if let gateDevice = gateDevice{
-
- // 0x04: Lamp device(黑板灯)
- // 0x12: panel (面板)
- // 0x31: sensor device(485)(教室灯)
- // 0x40: Curtain device (窗帘)
- // 0x01: CW Lamp (教室灯)
-
- //灯亮的状态
- let defaults = UserDefaults.standard
- let arrDevice = defaults.object(forKey: "saveDeviceList") as? [[String : String]]
- if let arrDevice = arrDevice {
- if arrDevice.count > 0 {
- for subDic in arrDevice {
- let address = subDic["address"]!
- let bright = subDic["bright"]
-
- if gateDevice.address == address && bright != "0" && gateDevice.type != "12" && gateDevice.type != "40" {
- self.lampTurnOnBtn.isSelected = true
- break
- }
- if gateDevice.address == address && bright == "0" && gateDevice.type != "12" && gateDevice.type != "40"{
- self.lampTurnOnBtn.isSelected = false
- break
- }
- if gateDevice.type == "12" {
- self.lampTurnOnBtn.isSelected = false
- self.lampTurnOnBtn.setImage(UIImage.init(named: "面板"), for: .normal)
- }
- if gateDevice.type == "40"{
- self.lampTurnOnBtn.isSelected = false
- self.lampTurnOnBtn.setImage(UIImage.init(named: "窗帘"), for: .normal)
- }
-
- }
- }
-
- }
-
-
-
- self.devId.text = "\(gateDevice.address)"
- switch gateDevice.type {
- case "01":
- self.deviceTypeLabel.text = "教室灯"
-
- case "12":
- self.deviceTypeLabel.text = "面板"
-
- case "31":
- self.deviceTypeLabel.text = "教室灯"
-
- case "04":
- self.deviceTypeLabel.text = "黑板灯"
-
- default:
- self.deviceTypeLabel.text = "窗帘"
-
- }
-
- }
- }
- }
- @IBOutlet weak var devIcon: UIImageView!
-
- @IBOutlet weak var devName: UILabel!
-
- @IBOutlet weak var devId: UILabel!
-
- @IBOutlet weak var lampTurnOnBtn: UIButton!
-
- @IBOutlet weak var deviceTypeLabel: UILabel!
- override func awakeFromNib() {
- super.awakeFromNib()
- let lineView = IHDashView(strokeColor: UIColor(hexString: "C6CDD5", transparency: 0.5)?.cgColor, gap: 3, lineWith: 1)
- lineView.frame = CGRect(x: 20, y: bounds.size.height - 1, width: KSCREENWIDTH - 40 , height: 1)
- addSubview(lineView)
-
- // NotificationCenter.default.addObserver(self, selector: #selector(turnOnLightFalse), name: NSNotification.Name(KNotifiTurnOnLightFalse), object: nil)
- }
-
- // @objc private func turnOnLightFalse(){
- // //关开灯失败
- // self.lampTurnOnBtn.isSelected = !self.lampTurnOnBtn.isSelected
- // }
-
- @IBAction func forbidAction(_ sender: Any) {
- if let block = self.disconnectCallback {
- block()
- }
- }
-
- @IBAction func turnOnOrOff(_ sender: UIButton) {
- sender.isSelected = !sender.isSelected
- log.debug(sender.isSelected)
- if let block = self.turnonCallback {
- block(sender.isSelected)
- }
- }
- }
-
|