Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct StatusStruct {
- let temp: String
- let mode: Mode
- let fanSpeed: FanSpeed
- let power: Power
- }
- enum Mode: String {
- case cold = "Cold"
- case heat = "Heat"
- case unknown = "Unknown"
- }
- enum Power: String {
- case on = "On"
- case off = "Off"
- case unknown = "Unknown"
- }
- enum FanSpeed: String {
- case night = "Night"
- case one = "1"
- case two = "2"
- case three = "3"
- case four = "4"
- case five = "5"
- case unknown = "Unknown"
- }
- func currentStatus(airconIp: String) {
- var temp = ""
- var mode = Mode.unknown
- var fanSpeed = FanSpeed.unknown
- var power = Power.unknown
- let modeMap = ["3": Mode.cold, "4": Mode.heat]
- let powerMap = ["1": Power.on, "0": Power.off]
- let fanMap = ["B": FanSpeed.night, "3": FanSpeed.one, "4": FanSpeed.two, "5": FanSpeed.three, "6": FanSpeed.four, "7": FanSpeed.five]
- for value in getCurrentStatus(airconIp) {
- if value.contains("stemp") {
- temp = value.split(separator: "=")[1]
- }
- if let modeValue = value.split(separator: "=").last, let modeEnum = modeMap[String(modeValue)] {
- mode = modeEnum
- }
- if let powerValue = value.split(separator: "=").last, let powerEnum = powerMap[String(powerValue)] {
- power = powerEnum
- }
- if let fanValue = value.split(separator: "=").last, let fanEnum = fanMap[String(fanValue)] {
- fanSpeed = fanEnum
- }
- }
- print(StatusStruct(temp: temp, mode: mode, fanSpeed: fanSpeed, power: power))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement