Skip to content

Commit 64000c0

Browse files
committed
Add CI for formatting
1 parent d6f88d3 commit 64000c0

File tree

13 files changed

+180
-70
lines changed

13 files changed

+180
-70
lines changed

.github/workflows/lint.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
# on:
10+
# pull_request:
11+
# types: [opened, reopened, synchronize]
12+
13+
jobs:
14+
validate_format_config:
15+
name: Validate Format Config
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v4
20+
21+
- name: Install apt dependencies
22+
run: apt-get -qq update && apt-get -qq -y install curl
23+
24+
- name: Compare against swift-mmio swift-format config
25+
run: |
26+
curl -sL https://raw.githubusercontent.com/apple/swift-mmio/refs/heads/main/SupportingFiles/Tools/swift-format/.swift-format -o .swift-format-mmio
27+
diff .swift-format .swift-format-mmio
28+
29+
soundness:
30+
name: Soundness
31+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
32+
with:
33+
api_breakage_check_enabled: false
34+
docs_check_enabled: false
35+
license_header_check_enabled: false
36+
license_header_check_project_name: ""
37+
unacceptable_language_check_enabled: false

.swift-format

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lineBreakBeforeControlFlowKeywords" : false,
1212
"lineBreakBeforeEachArgument" : false,
1313
"lineBreakBeforeEachGenericRequirement" : false,
14-
"lineLength" : 160,
14+
"lineLength" : 80,
1515
"maximumBlankLines" : 1,
1616
"multiElementCollectionTrailingCommas" : true,
1717
"noAssignmentInExpressions" : {
@@ -62,6 +62,7 @@
6262
"UseWhereClausesInForLoops" : false,
6363
"ValidateDocumentationComments" : true
6464
},
65+
"spacesBeforeEndOfLineComments": 2,
6566
"spacesAroundRangeFormationOperators" : false,
6667
"tabWidth" : 2,
6768
"version" : 1

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55
let package = Package(
66
name: "swift-matter-examples",
77
products: [
8-
.library(name: "SwiftMatterExamples", targets: ["SwiftMatterExamples"]),
8+
.library(name: "SwiftMatterExamples", targets: ["SwiftMatterExamples"])
99
],
1010
targets: [
1111
.target(name: "SwiftMatterExamples")

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-led-blink/walkthrough-example-led-blink-05.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func app_main() {
2121
sleep(1)
2222
led.enabled.toggle()
2323
if led.enabled {
24-
led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
24+
led.color = .hueSaturation(Int.random(in: 0..<360), 100)
2525
}
2626
}
2727
}

empty-template/main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
espressif/cmake_utilities:
33
version: 0.*
4-
rules: # will add "optional_component" only when all if clauses are True
4+
rules: # will add "optional_component" only when all if clauses are True
55
- if: "idf_version >=5.0"
66
- if: "target in [esp32c2]"

led-blink/main/LED.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ final class LED {
5353
// Hue range is 0 ..< 360.
5454
var hue: Int {
5555
switch self {
56-
case .hueSaturation(let hue, _): return hue
57-
case .temperature: return 0
56+
case .hueSaturation(let hue, _): return hue
57+
case .temperature: return 0
5858
}
5959
}
6060

6161
// Saturation is 0 ... 100.
6262
var saturation: Int {
6363
switch self {
64-
case .hueSaturation(_, let saturation): return saturation
65-
case .temperature: return 0
64+
case .hueSaturation(_, let saturation): return saturation
65+
case .temperature: return 0
6666
}
6767
}
6868
}
6969

7070
var handle: led_driver_handle_t
71-
71+
7272
init() {
7373
var config = led_driver_get_config()
7474
let handle = led_driver_init(&config)

led-blink/main/Main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func app_main() {
2121
sleep(1)
2222
led.enabled.toggle()
2323
if led.enabled {
24-
led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
24+
led.color = .hueSaturation(Int.random(in: 0..<360), 100)
2525
}
2626
}
2727
}

led-blink/main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
espressif/cmake_utilities:
33
version: 0.*
4-
rules: # will add "optional_component" only when all if clauses are True
4+
rules: # will add "optional_component" only when all if clauses are True
55
- if: "idf_version >=5.0"
66
- if: "target in [esp32c2]"

smart-light/Matter/Clusters.swift

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ protocol MatterCluster {
1717

1818
extension MatterCluster {
1919
init?(endpoint: some MatterEndpoint, id: UInt32) {
20-
guard let cluster = esp_matter.cluster.get_shim(endpoint.endpoint, id) else {
20+
guard let cluster = esp_matter.cluster.get_shim(endpoint.endpoint, id)
21+
else {
2122
return nil
2223
}
2324
self.init(cluster)
@@ -35,8 +36,12 @@ struct ClusterID<Cluster: MatterCluster>: RawRepresentable {
3536

3637
static var identify: ClusterID<Identify> { .init(rawValue: 0x0000_0003) }
3738
static var onOff: ClusterID<OnOff> { .init(rawValue: 0x0000_0006) }
38-
static var levelControl: ClusterID<LevelControl> { .init(rawValue: 0x0000_0008) }
39-
static var colorControl: ClusterID<ColorControl> { .init(rawValue: 0x0000_0300) }
39+
static var levelControl: ClusterID<LevelControl> {
40+
.init(rawValue: 0x0000_0008)
41+
}
42+
static var colorControl: ClusterID<ColorControl> {
43+
.init(rawValue: 0x0000_0300)
44+
}
4045
}
4146

4247
struct Cluster: MatterCluster {
@@ -70,7 +75,9 @@ struct Identify: MatterConcreteCluster {
7075
self.cluster = cluster
7176
}
7277

73-
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>) -> Attribute {
78+
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>)
79+
-> Attribute
80+
{
7481
Attribute(attribute: esp_matter.attribute.get_shim(cluster, id.rawValue))
7582
}
7683
}
@@ -91,7 +98,9 @@ struct OnOff: MatterConcreteCluster {
9198
self.cluster = cluster
9299
}
93100

94-
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>) -> Attribute {
101+
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>)
102+
-> Attribute
103+
{
95104
Attribute(attribute: esp_matter.attribute.get_shim(cluster, id.rawValue))
96105
}
97106

@@ -105,7 +114,9 @@ struct LevelControl: MatterConcreteCluster {
105114

106115
init(rawValue: UInt32) { self.rawValue = rawValue }
107116

108-
static var currentLevel: AttributeID<CurrentLevel> { .init(rawValue: 0x0000_0000) }
117+
static var currentLevel: AttributeID<CurrentLevel> {
118+
.init(rawValue: 0x0000_0000)
119+
}
109120
}
110121

111122
var cluster: UnsafeMutablePointer<esp_matter.cluster_t>
@@ -114,7 +125,9 @@ struct LevelControl: MatterConcreteCluster {
114125
self.cluster = cluster
115126
}
116127

117-
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>) -> Attribute {
128+
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>)
129+
-> Attribute
130+
{
118131
Attribute(attribute: esp_matter.attribute.get_shim(cluster, id.rawValue))
119132
}
120133

@@ -128,12 +141,20 @@ struct ColorControl: MatterConcreteCluster {
128141

129142
init(rawValue: UInt32) { self.rawValue = rawValue }
130143

131-
static var currentHue: AttributeID<CurrentHue> { .init(rawValue: 0x0000_0000) }
132-
static var currentSaturation: AttributeID<CurrentSaturation> { .init(rawValue: 0x0000_0001) }
144+
static var currentHue: AttributeID<CurrentHue> {
145+
.init(rawValue: 0x0000_0000)
146+
}
147+
static var currentSaturation: AttributeID<CurrentSaturation> {
148+
.init(rawValue: 0x0000_0001)
149+
}
133150
static var currentX: AttributeID<CurrentX> { .init(rawValue: 0x0000_0003) }
134151
static var currentY: AttributeID<CurrentY> { .init(rawValue: 0x0000_0004) }
135-
static var colorTemperatureMireds: AttributeID<ColorTemperatureMireds> { .init(rawValue: 0x0000_0007) }
136-
static var colorMode: AttributeID<ColorMode> { .init(rawValue: 0x0000_0008) }
152+
static var colorTemperatureMireds: AttributeID<ColorTemperatureMireds> {
153+
.init(rawValue: 0x0000_0007)
154+
}
155+
static var colorMode: AttributeID<ColorMode> {
156+
.init(rawValue: 0x0000_0008)
157+
}
137158
}
138159

139160
var cluster: UnsafeMutablePointer<esp_matter.cluster_t>
@@ -142,18 +163,24 @@ struct ColorControl: MatterConcreteCluster {
142163
self.cluster = cluster
143164
}
144165

145-
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>) -> Attribute {
166+
func attribute<Attribute: MatterAttribute>(_ id: AttributeID<Attribute>)
167+
-> Attribute
168+
{
146169
Attribute(attribute: esp_matter.attribute.get_shim(cluster, id.rawValue))
147170
}
148171

149172
var currentHue: CurrentHue { attribute(.currentHue) }
150173
var currentSaturation: CurrentSaturation { attribute(.currentSaturation) }
151174
var currentX: CurrentX { attribute(.currentX) }
152175
var currentY: CurrentY { attribute(.currentY) }
153-
var colorTemperatureMireds: ColorTemperatureMireds { attribute(.colorTemperatureMireds) }
176+
var colorTemperatureMireds: ColorTemperatureMireds {
177+
attribute(.colorTemperatureMireds)
178+
}
154179
var colorMode: ColorMode { attribute(.colorMode) }
155180

156-
func add(_ config: esp_matter.cluster.color_control.feature.hue_saturation.config_t) {
181+
func add(
182+
_ config: esp_matter.cluster.color_control.feature.hue_saturation.config_t
183+
) {
157184
var cfg = config
158185
esp_matter.cluster.color_control.feature.hue_saturation.add(cluster, &cfg)
159186
}

smart-light/Matter/Matter.swift

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
enum Matter { }
12+
enum Matter {}
1313

1414
extension Matter {
1515
class Node {
@@ -31,14 +31,23 @@ extension Matter {
3131
_ = Unmanaged.passRetained(self)
3232

3333
// Create the actual root node object, wire up callbacks.
34-
innerNode = RootNode(attribute: self.eventHandler, identify: { _, _, _, _ in self.identifyHandler?() })!
34+
innerNode = RootNode(
35+
attribute: self.eventHandler,
36+
identify: { _, _, _, _ in self.identifyHandler?() })!
3537
}
3638

37-
func eventHandler(type: MatterAttributeEvent, endpoint: __idf_main.Endpoint, cluster: Cluster, attribute: UInt32, value: UnsafeMutablePointer<esp_matter_attr_val_t>?) {
39+
func eventHandler(
40+
type: MatterAttributeEvent, endpoint: __idf_main.Endpoint,
41+
cluster: Cluster, attribute: UInt32,
42+
value: UnsafeMutablePointer<esp_matter_attr_val_t>?
43+
) {
3844
guard type == .didSet else { return }
39-
guard let e = self.endpoints.first(where: { $0.id == endpoint.id }) else { return }
45+
guard let e = self.endpoints.first(where: { $0.id == endpoint.id }) else {
46+
return
47+
}
4048
let value: Int = Int(value?.pointee.val.u64 ?? 0)
41-
guard let a = Endpoint.Attribute(cluster: cluster, attribute: attribute) else { return }
49+
guard let a = Endpoint.Attribute(cluster: cluster, attribute: attribute)
50+
else { return }
4251
e.eventHandler?(Endpoint.Event(type: type, attribute: a, value: value))
4352
}
4453
}
@@ -76,27 +85,34 @@ extension Matter {
7685
case OnOff.AttributeID<OnOff.OnOffState>.state.rawValue: self = .onOff
7786
default: return nil
7887
}
79-
}
80-
else
81-
if let _ = cluster.as(LevelControl.self) {
88+
} else if let _ = cluster.as(LevelControl.self) {
8289
switch attribute {
83-
case LevelControl.AttributeID<LevelControl.CurrentLevel>.currentLevel.rawValue: self = .levelControl
90+
case LevelControl.AttributeID<LevelControl.CurrentLevel>.currentLevel
91+
.rawValue:
92+
self = .levelControl
8493
default: return nil
8594
}
86-
}
87-
else
88-
if let _ = cluster.as(ColorControl.self) {
95+
} else if let _ = cluster.as(ColorControl.self) {
8996
switch attribute {
90-
case ColorControl.AttributeID<ColorControl.CurrentHue>.currentHue.rawValue: self = .colorControl(.currentHue)
91-
case ColorControl.AttributeID<ColorControl.CurrentSaturation>.currentSaturation.rawValue: self = .colorControl(.currentSaturation)
92-
case ColorControl.AttributeID<ColorControl.CurrentX>.currentX.rawValue: self = .colorControl(.currentX)
93-
case ColorControl.AttributeID<ColorControl.CurrentY>.currentY.rawValue: self = .colorControl(.currentY)
94-
case ColorControl.AttributeID<ColorControl.ColorTemperatureMireds>.colorTemperatureMireds.rawValue: self = .colorControl(.colorTemperatureMireds)
95-
case ColorControl.AttributeID<ColorControl.ColorMode>.colorMode.rawValue: self = .colorControl(.colorMode)
97+
case ColorControl.AttributeID<ColorControl.CurrentHue>.currentHue
98+
.rawValue:
99+
self = .colorControl(.currentHue)
100+
case ColorControl.AttributeID<ColorControl.CurrentSaturation>
101+
.currentSaturation.rawValue:
102+
self = .colorControl(.currentSaturation)
103+
case ColorControl.AttributeID<ColorControl.CurrentX>.currentX.rawValue:
104+
self = .colorControl(.currentX)
105+
case ColorControl.AttributeID<ColorControl.CurrentY>.currentY.rawValue:
106+
self = .colorControl(.currentY)
107+
case ColorControl.AttributeID<ColorControl.ColorTemperatureMireds>
108+
.colorTemperatureMireds.rawValue:
109+
self = .colorControl(.colorTemperatureMireds)
110+
case ColorControl.AttributeID<ColorControl.ColorMode>.colorMode
111+
.rawValue:
112+
self = .colorControl(.colorMode)
96113
default: return nil
97114
}
98-
}
99-
else {
115+
} else {
100116
self = .unknown(attribute)
101117
}
102118
}
@@ -119,13 +135,17 @@ extension Matter {
119135
lightConfig.on_off.on_off = true
120136
lightConfig.level_control.current_level = .init(64)
121137
lightConfig.level_control.lighting.start_up_current_level = .init(64)
122-
lightConfig.color_control.color_mode = chip.app.Clusters.ColorControl.ColorMode.colorTemperature.rawValue
123-
lightConfig.color_control.enhanced_color_mode = chip.app.Clusters.ColorControl.ColorMode.colorTemperature.rawValue
138+
lightConfig.color_control.color_mode =
139+
chip.app.Clusters.ColorControl.ColorMode.colorTemperature.rawValue
140+
lightConfig.color_control.enhanced_color_mode =
141+
chip.app.Clusters.ColorControl.ColorMode.colorTemperature.rawValue
124142

125-
let light = MatterExtendedColorLight(node.innerNode, configuration: lightConfig)
143+
let light = MatterExtendedColorLight(
144+
node.innerNode, configuration: lightConfig)
126145
self.id = Int(light.id)
127146

128-
var hsv = esp_matter.cluster.color_control.feature.hue_saturation.config_t()
147+
var hsv = esp_matter.cluster.color_control.feature.hue_saturation
148+
.config_t()
129149
hsv.current_hue = 255
130150
hsv.current_saturation = 255
131151
light.colorControl.add(hsv)
@@ -143,9 +163,12 @@ extension Matter {
143163
}
144164

145165
func start() {
146-
func callback(event: UnsafePointer<chip.DeviceLayer.ChipDeviceEvent>?, context: Int) {
166+
func callback(
167+
event: UnsafePointer<chip.DeviceLayer.ChipDeviceEvent>?, context: Int
168+
) {
147169
switch Int(event!.pointee.Type) {
148-
case chip.DeviceLayer.DeviceEventType.kFabricRemoved: recomissionFabric()
170+
case chip.DeviceLayer.DeviceEventType.kFabricRemoved:
171+
recomissionFabric()
149172
default: break
150173
}
151174
}
@@ -165,7 +188,8 @@ func print(_ a: Matter.Endpoint.Attribute) {
165188
case .currentSaturation: print("currentSaturation", terminator: "")
166189
case .currentX: print("currentX", terminator: "")
167190
case .currentY: print("currentY", terminator: "")
168-
case .colorTemperatureMireds: print("colorTemperatureMireds", terminator: "")
191+
case .colorTemperatureMireds:
192+
print("colorTemperatureMireds", terminator: "")
169193
case .colorMode: print("colorMode", terminator: "")
170194
}
171195
print(")")

0 commit comments

Comments
 (0)