-
Notifications
You must be signed in to change notification settings - Fork 278
/
SensorDetailViewController.swift
70 lines (58 loc) · 1.92 KB
/
SensorDetailViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Foundation
import Shared
import Eureka
import UIKit
class SensorDetailViewController: FormViewController {
private(set) var sensor: WebhookSensor
init(sensor: WebhookSensor) {
self.sensor = sensor
super.init(style: .grouped)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
updateModels()
}
private func updateModels() {
title = sensor.Name
form.removeAll()
let baseSection = Section()
baseSection <<< LabelRow {
$0.title = L10n.SettingsSensors.Detail.uniqueId
$0.value = sensor.UniqueID
}
baseSection <<< LabelRow {
$0.title = L10n.SettingsSensors.Detail.state
$0.value = sensor.StateDescription
}
if let deviceClass = sensor.DeviceClass {
baseSection <<< LabelRow {
$0.title = L10n.SettingsSensors.Detail.deviceClass
$0.value = deviceClass.rawValue
}
}
if let icon = sensor.Icon {
baseSection <<< LabelRow {
$0.title = L10n.SettingsSensors.Detail.icon
$0.value = icon
}
}
form +++ baseSection
if let attributes = sensor.Attributes {
let attributesSection = Section(header: L10n.SettingsSensors.Detail.attributes, footer: nil)
let attributeRows = attributes
.sorted(by: { lhs, rhs in lhs.0 < rhs.0 })
.map(Self.row(attribute:value:))
attributesSection.append(contentsOf: attributeRows)
form.append(attributesSection)
}
}
class func row(attribute: String, value: Any) -> BaseRow {
return LabelRow { row in
row.title = attribute
row.value = String(describing: value)
}
}
}