Skip to content

Commit 363e901

Browse files
committed
chore: Add file transfer capabilities for devices
Device capabilities can include `file_transfer_stream` and `file_transfer_storage` Signed-off-by: Omar <omar.brbutovic@secomind.com>
1 parent 0893588 commit 363e901

File tree

4 files changed

+177
-3
lines changed

4 files changed

+177
-3
lines changed

backend/lib/edgehog/capabilities.ex

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2022-2024 SECO Mind Srl
4+
# Copyright 2022 - 2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -133,6 +133,62 @@ defmodule Edgehog.Capabilities do
133133
minor: 1
134134
}
135135
],
136+
file_transfer_stream: [
137+
%Astarte.InterfaceID{
138+
name: "io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice",
139+
major: 0,
140+
minor: 1
141+
},
142+
%Astarte.InterfaceID{
143+
name: "io.edgehog.devicemanager.fileTransfer.Progress",
144+
major: 0,
145+
minor: 1
146+
},
147+
%Astarte.InterfaceID{
148+
name: "io.edgehog.devicemanager.fileTransfer.Response",
149+
major: 0,
150+
minor: 1
151+
}
152+
],
153+
file_transfer_storage: [
154+
%Astarte.InterfaceID{
155+
name: "io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice",
156+
major: 0,
157+
minor: 1
158+
},
159+
%Astarte.InterfaceID{
160+
name: "io.edgehog.devicemanager.fileTransfer.Progress",
161+
major: 0,
162+
minor: 1
163+
},
164+
%Astarte.InterfaceID{
165+
name: "io.edgehog.devicemanager.fileTransfer.Response",
166+
major: 0,
167+
minor: 1
168+
},
169+
%Astarte.InterfaceID{
170+
name: "io.edgehog.devicemanager.storage.File",
171+
major: 0,
172+
minor: 1
173+
}
174+
],
175+
file_transfer_read: [
176+
%Astarte.InterfaceID{
177+
name: "io.edgehog.devicemanager.fileTransfer.DeviceToServer",
178+
major: 0,
179+
minor: 1
180+
},
181+
%Astarte.InterfaceID{
182+
name: "io.edgehog.devicemanager.fileTransfer.Progress",
183+
major: 0,
184+
minor: 1
185+
},
186+
%Astarte.InterfaceID{
187+
name: "io.edgehog.devicemanager.fileTransfer.Response",
188+
major: 0,
189+
minor: 1
190+
}
191+
],
136192
hardware_info: [
137193
%Astarte.InterfaceID{
138194
name: "io.edgehog.devicemanager.HardwareInfo",

backend/lib/edgehog/devices/device/types/capability.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2024 SECO Mind Srl
4+
# Copyright 2024 - 2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -27,6 +27,9 @@ defmodule Edgehog.Devices.Device.Types.Capability do
2727
cellular_connection: "The device provides information about its cellular connection.",
2828
commands: "The device supports commands, for example the rebooting command.",
2929
container_management: "The device supports running applications using containers.",
30+
file_transfer_stream: "The device supports streaming files to and from it.",
31+
file_transfer_storage: "The device supports transferring files to and from its storage units.",
32+
file_transfer_read: "The device supports reading files from it.",
3033
geolocation: "The device can be geolocated.",
3134
hardware_info: "The device provides information about its hardware.",
3235
led_behaviors: "The device can be asked to blink its LED in a specific pattern.",

backend/test/edgehog/capabilities_test.exs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ defmodule Edgehog.CapabilitiesTest do
5858
"io.edgehog.devicemanager.SystemStatus" => %InterfaceVersion{major: 0, minor: 1},
5959
"io.edgehog.devicemanager.config.Telemetry" => %InterfaceVersion{major: 0, minor: 1},
6060
"io.edgehog.devicemanager.WiFiScanResults" => %InterfaceVersion{major: 0, minor: 1},
61+
"io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice" => %InterfaceVersion{
62+
major: 0,
63+
minor: 1
64+
},
65+
"io.edgehog.devicemanager.fileTransfer.DeviceToServer" => %InterfaceVersion{
66+
major: 0,
67+
minor: 1
68+
},
69+
"io.edgehog.devicemanager.fileTransfer.Progress" => %InterfaceVersion{major: 0, minor: 1},
70+
"io.edgehog.devicemanager.fileTransfer.Response" => %InterfaceVersion{major: 0, minor: 1},
71+
"io.edgehog.devicemanager.storage.File" => %InterfaceVersion{
72+
major: 0,
73+
minor: 1
74+
},
6175
"io.edgehog.devicemanager.apps.AvailableContainers" => %InterfaceVersion{
6276
major: 0,
6377
minor: 1
@@ -100,6 +114,9 @@ defmodule Edgehog.CapabilitiesTest do
100114
:cellular_connection,
101115
:commands,
102116
:container_management,
117+
:file_transfer_stream,
118+
:file_transfer_storage,
119+
:file_transfer_read,
103120
:geolocation,
104121
:hardware_info,
105122
:led_behaviors,
@@ -208,5 +225,100 @@ defmodule Edgehog.CapabilitiesTest do
208225

209226
assert Enum.sort(expected_capabilities) == Enum.sort(device_capabilities)
210227
end
228+
229+
test "returns file_transfer_stream capability when all required interfaces are present" do
230+
device_introspection = %{
231+
"io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice" => %InterfaceVersion{
232+
major: 0,
233+
minor: 1
234+
},
235+
"io.edgehog.devicemanager.fileTransfer.Progress" => %InterfaceVersion{
236+
major: 0,
237+
minor: 1
238+
},
239+
"io.edgehog.devicemanager.fileTransfer.Response" => %InterfaceVersion{
240+
major: 0,
241+
minor: 1
242+
}
243+
}
244+
245+
expected_capabilities = [
246+
:file_transfer_stream,
247+
:geolocation
248+
]
249+
250+
device_capabilities = Capabilities.from_introspection(device_introspection)
251+
252+
assert Enum.sort(expected_capabilities) == Enum.sort(device_capabilities)
253+
end
254+
255+
test "returns file_transfer_storage capability when all required interfaces are present" do
256+
device_introspection = %{
257+
"io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice" => %InterfaceVersion{
258+
major: 0,
259+
minor: 1
260+
},
261+
"io.edgehog.devicemanager.fileTransfer.Progress" => %InterfaceVersion{
262+
major: 0,
263+
minor: 1
264+
},
265+
"io.edgehog.devicemanager.fileTransfer.Response" => %InterfaceVersion{
266+
major: 0,
267+
minor: 1
268+
},
269+
"io.edgehog.devicemanager.storage.File" => %InterfaceVersion{
270+
major: 0,
271+
minor: 1
272+
}
273+
}
274+
275+
expected_capabilities = [
276+
:file_transfer_storage,
277+
:file_transfer_stream,
278+
:geolocation
279+
]
280+
281+
device_capabilities = Capabilities.from_introspection(device_introspection)
282+
283+
assert Enum.sort(expected_capabilities) == Enum.sort(device_capabilities)
284+
end
285+
286+
test "returns file_transfer_read capability when all required interfaces are present" do
287+
device_introspection = %{
288+
"io.edgehog.devicemanager.fileTransfer.DeviceToServer" => %InterfaceVersion{
289+
major: 0,
290+
minor: 1
291+
},
292+
"io.edgehog.devicemanager.fileTransfer.Progress" => %InterfaceVersion{
293+
major: 0,
294+
minor: 1
295+
},
296+
"io.edgehog.devicemanager.fileTransfer.Response" => %InterfaceVersion{
297+
major: 0,
298+
minor: 1
299+
}
300+
}
301+
302+
expected_capabilities = [
303+
:file_transfer_read,
304+
:geolocation
305+
]
306+
307+
device_capabilities = Capabilities.from_introspection(device_introspection)
308+
309+
assert Enum.sort(expected_capabilities) == Enum.sort(device_capabilities)
310+
end
311+
312+
test "does not return file transfer capabilities when interfaces are missing" do
313+
device_introspection = %{
314+
"io.edgehog.devicemanager.SystemInfo" => %InterfaceVersion{major: 0, minor: 1}
315+
}
316+
317+
device_capabilities = Capabilities.from_introspection(device_introspection)
318+
319+
refute :file_transfer_stream in device_capabilities
320+
refute :file_transfer_storage in device_capabilities
321+
refute :file_transfer_read in device_capabilities
322+
end
211323
end
212324
end

backend/test/edgehog_web/schema/query/device_test.exs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is part of Edgehog.
22
#
3-
# Copyright 2021 - 2025 SECO Mind Srl
3+
# Copyright 2021 - 2026 SECO Mind Srl
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -734,6 +734,9 @@ defmodule EdgehogWeb.Schema.Query.DeviceTest do
734734
"CELLULAR_CONNECTION",
735735
"COMMANDS",
736736
"CONTAINER_MANAGEMENT",
737+
"FILE_TRANSFER_STREAM",
738+
"FILE_TRANSFER_STORAGE",
739+
"FILE_TRANSFER_READ",
737740
"GEOLOCATION",
738741
"HARDWARE_INFO",
739742
"LED_BEHAVIORS",

0 commit comments

Comments
 (0)