Skip to content

Commit 70039f5

Browse files
committed
Updated as per design review
1 parent e851116 commit 70039f5

File tree

11 files changed

+599
-923
lines changed

11 files changed

+599
-923
lines changed

src/IotHub/IotHub.Test/ScenarioTests/IotHubDPDeviceTests.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ function Test-AzureRmIotHubDeviceLifecycle
6767
$device1twin = Get-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1
6868
Assert-True { $device1twin.DeviceId -eq $device1}
6969

70-
# Update device twin
70+
# Partial update device twin
7171
$tags1 = @{}
7272
$tags1.Add('Test1', '1')
73-
$updateddevice1twin1 = Update-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -tag $tags1
73+
$updateddevice1twin1 = Update-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -tag $tags1 -Partial
7474
Assert-True { $updateddevice1twin1.DeviceId -eq $device1}
7575
Assert-True { $updateddevice1twin1.tags.Count -eq 1}
7676

7777
$tags2 = @{}
7878
$tags2.Add('Test2', '2')
79-
$updateddevice1twin2 = Update-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -tag $tags2
79+
$updateddevice1twin2 = Update-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -tag $tags2 -Partial
8080
Assert-True { $updateddevice1twin2.DeviceId -eq $device1}
8181
Assert-True { $updateddevice1twin2.tags.Count -eq 2}
8282

83-
# Set device twin
83+
# Update device twin
8484
$tags3 = @{}
8585
$tags3.Add('Test3', '3')
86-
$setdevice1twin = Set-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -tag $tags3
87-
Assert-True { $setdevice1twin.DeviceId -eq $device1}
88-
Assert-True { $setdevice1twin.tags.Count -eq 1}
86+
$updateddevice1twin3 = Update-AzIotHubDeviceTwin -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -tag $tags3
87+
Assert-True { $updateddevice1twin3.DeviceId -eq $device1}
88+
Assert-True { $updateddevice1twin3.tags.Count -eq 1}
8989

9090
# Get all devices
9191
$devices = Get-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName

src/IotHub/IotHub.Test/SessionRecords/Microsoft.Azure.Commands.IotHub.Test.ScenarioTests.IotHubDPDeviceTests/TestAzureIotHubDeviceLifecycle.json

Lines changed: 549 additions & 492 deletions
Large diffs are not rendered by default.

src/IotHub/IotHub/Az.IotHub.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ CmdletsToExport = 'Add-AzIotHubKey', 'Get-AzIotHubEventHubConsumerGroup',
101101
'Set-AzIotHubDeviceParent', 'Add-AzIotHubDeviceChildren',
102102
'Remove-AzIotHubDeviceChildren', 'Get-AzIotHubDeviceChildren',
103103
'Get-AzIotHubDistributedTracing', 'Set-AzIotHubDistributedTracing',
104-
'Get-AzIotHubDeviceTwin', 'Update-AzIotHubDeviceTwin', 'Set-AzIotHubDeviceTwin'
104+
'Get-AzIotHubDeviceTwin', 'Update-AzIotHubDeviceTwin'
105105
# Variables to export from this module
106106
# VariablesToExport = @()
107107

src/IotHub/IotHub/ChangeLog.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* Manage IoT device twin configuration, New cmdlets are:
2525
- `Get-AzIotHubDeviceTwin`
2626
- `Update-AzIotHubDeviceTwin`
27-
- `Set-AzIotHubDeviceTwin`
2827

2928
## Version 2.2.0
3029
* Added support to manage devices in an Iot Hub. New Cmdlets are:

src/IotHub/IotHub/IotHub/DataPlane/Device/SetAzIotHubDeviceTwin.cs

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/IotHub/IotHub/IotHub/DataPlane/Device/UpdateAzIotHubDeviceTwin.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public class UpdateAzIotHubDeviceTwin : IotHubBaseCmdlet
7272
[ValidateNotNullOrEmpty]
7373
public Hashtable Desired { get; set; }
7474

75+
[Parameter(Mandatory = false, HelpMessage = "Allows to only partially update the tags and desired properties of a device twin.")]
76+
public SwitchParameter Partial { get; set; }
77+
7578
public override void ExecuteCmdlet()
7679
{
7780
if (ShouldProcess(this.DeviceId, Properties.Resources.UpdateIotHubDeviceTwin))
@@ -116,7 +119,14 @@ public override void ExecuteCmdlet()
116119
deviceTwin.Properties.Desired = new TwinCollection(JsonConvert.SerializeObject(this.Desired));
117120
}
118121

119-
this.WriteObject(registryManager.UpdateTwinAsync(this.DeviceId, deviceTwin, deviceTwin.ETag).GetAwaiter().GetResult());
122+
if (this.Partial.IsPresent)
123+
{
124+
this.WriteObject(registryManager.UpdateTwinAsync(this.DeviceId, deviceTwin, deviceTwin.ETag).GetAwaiter().GetResult());
125+
}
126+
else
127+
{
128+
this.WriteObject(registryManager.ReplaceTwinAsync(this.DeviceId, deviceTwin, deviceTwin.ETag).GetAwaiter().GetResult());
129+
}
120130
}
121131
}
122132
}

src/IotHub/IotHub/Properties/Resources.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/IotHub/IotHub/Properties/Resources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,6 @@
219219
<data name="SetIotHubDistributedTracing" xml:space="preserve">
220220
<value>Update Distributed Tracing</value>
221221
</data>
222-
<data name="SetIotHubDeviceTwin" xml:space="preserve">
223-
<value>Replace Device Twin</value>
224-
</data>
225222
<data name="UpdateIotHubDeviceTwin" xml:space="preserve">
226223
<value>Update Device Twin</value>
227224
</data>

src/IotHub/IotHub/help/Az.IotHub.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ Update an IoT Hub device.
155155
### [Set-AzIotHubDeviceParent](Set-AzIotHubDeviceParent.md)
156156
Set the parent device of the specified device.
157157

158-
### [Set-AzIotHubDeviceTwin](Set-AzIotHubDeviceTwin.md)
159-
Replaces tags and desired properties of a device twin.
160-
161158
### [Set-AzIotHubDistributedTracing](Set-AzIotHubDistributedTracing.md)
162159
Update the distributed tracing options for a device.
163160

0 commit comments

Comments
 (0)