Skip to content

Commit

Permalink
feat: convert device profile request to tedge json format
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Piotrowski <[email protected]>
  • Loading branch information
Ruadhri17 committed Jul 31, 2024
1 parent 51148ff commit 41a8f23
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 1 deletion.
32 changes: 32 additions & 0 deletions crates/core/tedge_api/src/device_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,35 @@ pub enum OperationPayload {
#[serde(rename = "payload")]
Config(ConfigInfo),
}

impl DeviceProfileCmdPayload {
pub fn add_firmware(&mut self, firmware: FirmwareInfo) {
let firmware_operation = DeviceProfileOperation {
operation: OperationType::FirmwareUpdate,
skip: false,
payload: OperationPayload::Firmware(firmware),
};

self.operations.push(firmware_operation);
}

pub fn add_software(&mut self, software: SoftwareInfo) {
let software_operation = DeviceProfileOperation {
operation: OperationType::SoftwareUpdate,
skip: false,
payload: OperationPayload::Software(software),
};

self.operations.push(software_operation);
}

pub fn add_config(&mut self, config: ConfigInfo) {
let config_operation = DeviceProfileOperation {
operation: OperationType::ConfigUpdate,
skip: false,
payload: OperationPayload::Config(config),
};

self.operations.push(config_operation);
}
}
13 changes: 12 additions & 1 deletion crates/extensions/c8y_mapper_ext/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,19 @@ impl CumulocityConverter {
}
C8yDeviceControlOperation::DeviceProfile(request) => {
if self.config.capabilities.device_profile {
vec![]
if let Some(profile_name) = extras.get("profileName") {
self.convert_device_profile_request(
device_xid,
cmd_id,
request,
serde_json::from_value(profile_name.clone())?,
)?
} else {
error!("Received a c8y_DeviceProfile without a profile name");
vec![]
}
} else {
warn!("Received a c8y_DeviceProfile operation, however, device_profile feature is disabled");
vec![]
}
}
Expand Down
Loading

0 comments on commit 41a8f23

Please sign in to comment.