Skip to content

Commit

Permalink
#2162 Edge device loose tags (#2173)
Browse files Browse the repository at this point in the history
- Add missing mappings
- Fix AWSEdgeDeviceService
  • Loading branch information
delager authored and kbeaugrand committed Jun 18, 2023
1 parent 2a8da3b commit 420888e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public AWSDeviceThingProfile()
Name = att.Key,
Value = att.Value
})));

_ = CreateMap<IoTEdgeDevice, CreateThingRequest>()
.ForMember(dest => dest.ThingName, opts => opts.MapFrom(src => src.DeviceName))
.ForPath(dest => dest.AttributePayload.Attributes, opts => opts.MapFrom(src => src.Tags))
.ReverseMap();

_ = CreateMap<IoTEdgeDevice, UpdateThingRequest>()
.ForMember(dest => dest.ThingName, opts => opts.MapFrom(src => src.DeviceName))
.ForPath(dest => dest.AttributePayload.Attributes, opts => opts.MapFrom(src => src.Tags))
.ReverseMap();
}

private static MemoryStream EmptyPayload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class EdgeDeviceProfile : Profile
{
public EdgeDeviceProfile()
{
_ = CreateMap<EdgeDevice, EdgeDevice>();

_ = CreateMap<Twin, EdgeDevice>()
.ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.DeviceId))
.ForMember(dest => dest.Name, opts => opts.MapFrom(src => src.Tags["deviceName"]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AWSEdgeDevicesService : EdgeDevicesServiceBase, IEdgeDevicesService
private readonly IEdgeDeviceModelRepository deviceModelRepository;
private readonly IConfigService configService;
private readonly ConfigHandler configHandler;
private readonly IMapper mapper;

public AWSEdgeDevicesService(
ConfigHandler configHandler,
Expand All @@ -55,6 +56,8 @@ public AWSEdgeDevicesService(

this.unitOfWork = unitOfWork;
this.edgeDeviceRepository = edgeDeviceRepository;

this.mapper = mapper;
}

/// <summary>
Expand All @@ -73,15 +76,13 @@ public async Task<IoTEdgeDevice> CreateEdgeDevice(IoTEdgeDevice edgeDevice)
throw new InvalidOperationException($"Edge model '{edgeDevice.ModelId}' doesn't exist!");
}

var response = await this.awsExternalDevicesService.CreateDevice(new CreateThingRequest
{
ThingName = edgeDevice.DeviceName,
ThingTypeName = model.Name
});
var createThingRequest = this.mapper.Map<CreateThingRequest>(edgeDevice);
createThingRequest.ThingTypeName = model.Name;

var response = await this.awsExternalDevicesService.CreateDevice(createThingRequest);
edgeDevice.DeviceId = response.ThingId;
var result = await base.CreateEdgeDeviceInDatabase(edgeDevice);

var result = await base.CreateEdgeDeviceInDatabase(edgeDevice);
await this.unitOfWork.SaveAsync();

return result;
Expand All @@ -97,7 +98,8 @@ public async Task<IoTEdgeDevice> UpdateEdgeDevice(IoTEdgeDevice edgeDevice)
{
ArgumentNullException.ThrowIfNull(edgeDevice, nameof(edgeDevice));

_ = await this.awsExternalDevicesService.GetDevice(edgeDevice.DeviceName);
var updateThingRequest = this.mapper.Map<UpdateThingRequest>(edgeDevice);
_ = await this.awsExternalDevicesService.UpdateDevice(updateThingRequest);

var result = await UpdateEdgeDeviceInDatabase(edgeDevice);

Expand Down

0 comments on commit 420888e

Please sign in to comment.