Skip to content

Commit

Permalink
Fix #1869 - create and delete dynamic thing group
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed May 24, 2023
1 parent 671ffa6 commit 2c90abc
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public async Task<ExternalDeviceModelDto> CreateDeviceModel(ExternalDeviceModelD
});

var response = await this.amazonIoTClient.CreateThingTypeAsync(createThingTypeRequest);
await this.CreateDynamicGroupForThingType(response.ThingTypeName);

deviceModel.Id = response.ThingTypeId;

return deviceModel;
}
catch (ResourceAlreadyExistsException e)
Expand Down Expand Up @@ -79,7 +81,12 @@ public async Task DeleteDeviceModel(ExternalDeviceModelDto deviceModel)
UndoDeprecate = false
};

_ = await this.amazonIoTClient.DeprecateThingTypeAsync(deprecated);
var response = await this.amazonIoTClient.DeprecateThingTypeAsync(deprecated);

_ = await this.amazonIoTClient.DeleteDynamicThingGroupAsync(new DeleteDynamicThingGroupRequest
{
ThingGroupName = deviceModel.Name
});
}
catch (ResourceNotFoundException e)
{
Expand Down Expand Up @@ -191,5 +198,26 @@ public Task<Twin> UpdateDeviceTwin(Twin twin)
{
throw new NotImplementedException();
}

private async Task CreateDynamicGroupForThingType(string thingTypeName)
{
try
{
var dynamicThingGroup = new DescribeThingGroupRequest
{
ThingGroupName = thingTypeName
};

_ = await this.amazonIoTClient.DescribeThingGroupAsync(dynamicThingGroup);
}
catch (ResourceNotFoundException)
{
_ = await this.amazonIoTClient.CreateDynamicThingGroupAsync(new CreateDynamicThingGroupRequest
{
ThingGroupName = thingTypeName,
QueryString = $"thingTypeName: {thingTypeName}"
});
}
}
}
}

0 comments on commit 2c90abc

Please sign in to comment.