Skip to content

Commit

Permalink
Add device friendly name (#242)
Browse files Browse the repository at this point in the history
* Fix #177 - Add device friendly name

* Add conscistency between device name and concentrator name fields in tags

Co-authored-by: crib <[email protected]>
Co-authored-by: Beaugrand, Kevin <[email protected]>
  • Loading branch information
3 people authored Feb 11, 2022
1 parent 01d412f commit 0078fab
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void CreateDeviceDetails_StateUnderTest_ExpectedBehavior()
};

twin.Tags[nameof(Concentrator.DeviceType).ToCamelCase()] = Guid.NewGuid().ToString();
twin.Tags[nameof(Concentrator.DeviceFriendlyName).ToCamelCase()] = Guid.NewGuid().ToString();
twin.Tags[nameof(Concentrator.DeviceName).ToCamelCase()] = Guid.NewGuid().ToString();
twin.Tags[nameof(Concentrator.LoraRegion).ToCamelCase()] = Guid.NewGuid().ToString();

twin.Properties.Reported["DevAddr"] = Guid.NewGuid().ToString();
Expand All @@ -70,7 +70,7 @@ public void CreateDeviceDetails_StateUnderTest_ExpectedBehavior()
Assert.IsFalse(result.IsConnected);
Assert.IsFalse(result.IsEnabled);

Assert.AreEqual(twin.Tags[nameof(Concentrator.DeviceFriendlyName).ToCamelCase()].ToString(), result.DeviceFriendlyName);
Assert.AreEqual(twin.Tags[nameof(Concentrator.DeviceName).ToCamelCase()].ToString(), result.DeviceName);
Assert.AreEqual(twin.Tags[nameof(Concentrator.LoraRegion).ToCamelCase()].ToString(), result.LoraRegion);
Assert.AreEqual(twin.Tags[nameof(Concentrator.DeviceType).ToCamelCase()].ToString(), result.DeviceType);

Expand All @@ -91,7 +91,7 @@ public void UpdateTwin_StateUnderTest_ExpectedBehavior()
Concentrator item = new Concentrator
{
LoraRegion = Guid.NewGuid().ToString(),
DeviceFriendlyName = Guid.NewGuid().ToString(),
DeviceName = Guid.NewGuid().ToString(),
DeviceType = Guid.NewGuid().ToString(),
ClientCertificateThumbprint = Guid.NewGuid().ToString(),
IsConnected = false,
Expand All @@ -110,7 +110,7 @@ public void UpdateTwin_StateUnderTest_ExpectedBehavior()
// .ReturnsAsync((HttpRequestMessage req, CancellationToken token) => deviceResponseMock)
// .Verifiable();

Helpers.DeviceHelper.SetTagValue(twin, nameof(item.DeviceFriendlyName), item.DeviceFriendlyName);
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.DeviceName), item.DeviceName);
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.DeviceType), item.DeviceType);
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.LoraRegion), item.LoraRegion);

Expand All @@ -120,7 +120,7 @@ public void UpdateTwin_StateUnderTest_ExpectedBehavior()
concentratorTwinMapper.UpdateTwin(twin, item);

// Assert
Assert.AreEqual(item.DeviceFriendlyName, twin.Tags[nameof(Concentrator.DeviceFriendlyName).ToCamelCase()].ToString());
Assert.AreEqual(item.DeviceName, twin.Tags[nameof(Concentrator.DeviceName).ToCamelCase()].ToString());
Assert.AreEqual(item.DeviceType, twin.Tags[nameof(Concentrator.DeviceType).ToCamelCase()].ToString());
Assert.AreEqual(item.LoraRegion, twin.Tags[nameof(Concentrator.LoraRegion).ToCamelCase()].ToString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
HelperText="DeviceID must contain 16 hexadecimal characters (numbers from 0 to 9 and/or letters from A to F)"
/>
</MudItem>
<MudItem xs="12">
<MudTextField @bind-Value="@Device.DeviceName"
Label="Device name"
Variant="Variant.Outlined"
For="@(()=> Device.DeviceName)"
Required="true"
/>
</MudItem>
<MudItem xs="12" md="6">
<MudSelect T="string" @bind-Value="@Device.DeviceType"
Dense="true" Variant="Variant.Outlined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
</CardHeaderContent>
</MudCardHeader>
<MudCardContent>
<MudGrid>
<MudGrid>
<MudItem xs="12">
<MudTextField @bind-Value="@Device.DeviceName" Label="Device name" Required="true" Variant="Variant.Outlined" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@Device.AssetId" Label="IoT Asset ID" Variant="Variant.Outlined" />
</MudItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<img height="25" src="@context.ImageUrl" />
</MudTd>
<MudTd DataLabel="Device" Style="word-break: break-all;">
<a href="devices/@context.DeviceID">@context.DeviceID</a>
<a href="devices/@context.DeviceID">@context.DeviceName</a>
</MudTd>

<MudTd DataLabel="Status" Style="text-align: center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
</MudCardHeader>
<MudCardContent>
<MudGrid>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@concentrator.DeviceFriendlyName" Label="Device Friendly Name" Variant="Variant.Outlined" />
<MudItem xs="12">
<MudTextField @bind-Value="@concentrator.DeviceName" Label="Device name" Variant="Variant.Outlined" Required="true" />
</MudItem>

<MudItem xs="12" md="6">
<MudTextField @bind-Value="@concentrator.ClientCertificateThumbprint" Label="Client Certificate Thumbprint" Variant="Variant.Outlined" Required="true" />
</MudItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
<MudItem xs="12">
<MudTable Items="@concentrators" Dense=true Breakpoint="Breakpoint.Sm" Hover=true Bordered=true Striped=true>
<ColGroup>
<col style="width: 15%;" />
<col style="width: 40%;" />
<col style="width: 60%;" />
<col style="width: 10%;" />
<col style="width: 10%;" />
<col style="width: 10%;" />
Expand All @@ -35,19 +34,15 @@
<MudIconButton Icon="@Icons.Material.Filled.Add" Size="Size.Medium" OnClick="AddDevice" Class="ma-2"></MudIconButton>
</ToolBarContent>
<HeaderContent>
<MudTh Style="text-align: center">Name</MudTh>
<MudTh>Device Id</MudTh>
<MudTh>Device</MudTh>
<MudTh Style="text-align: center">Status</MudTh>
<MudTh Style="text-align: center">Connection state</MudTh>
<MudTh Style="text-align: center">See details</MudTh>
<MudTh Style="text-align: center">Delete</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Device" Style="word-break: break-all;">
<a href="lorawan/concentrators/@context.DeviceId">@context.DeviceFriendlyName</a>
</MudTd>
<MudTd DataLabel="Device" Style="word-break: break-all;">
<a href="lorawan/concentrators/@context.DeviceId">@context.DeviceId</a>
<a href="lorawan/concentrators/@context.DeviceId">@context.DeviceName</a>
</MudTd>
<MudTd DataLabel="Status" Style="text-align: center">
@if (context.IsEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</MudCardHeader>
<MudCardContent>
<MudGrid>
<MudItem xs="12" md="6">
<MudItem xs="12">
<MudTextField @bind-Value="@concentrator.DeviceId"
Label="Device Id"
Variant="Variant.Outlined"
Expand All @@ -32,8 +32,10 @@
/>
</MudItem>

<MudItem xs="12" md="6">
<MudTextField @bind-Value="@concentrator.DeviceFriendlyName" Label="Friendly tag name" Variant="Variant.Outlined" Required="true"/>
<MudItem xs="12">
<MudTextField @bind-Value="@concentrator.DeviceName"
For="@(()=> concentrator.DeviceName)"
Label="Device name" Variant="Variant.Outlined" Required="true"/>
</MudItem>

<MudItem xs="12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Concentrator CreateDeviceDetails(Twin twin)
return new Concentrator
{
DeviceId = twin.DeviceId,
DeviceFriendlyName = DeviceHelper.RetrieveTagValue(twin, nameof(Concentrator.DeviceFriendlyName)),
DeviceName = DeviceHelper.RetrieveTagValue(twin, nameof(Concentrator.DeviceName)),
LoraRegion = DeviceHelper.RetrieveTagValue(twin, nameof(Concentrator.LoraRegion)),
ClientCertificateThumbprint = DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(Concentrator.ClientCertificateThumbprint)),
IsEnabled = twin.Status == DeviceStatus.Enabled,
Expand All @@ -37,7 +37,7 @@ public Concentrator CreateDeviceDetails(Twin twin)

public void UpdateTwin(Twin twin, Concentrator item)
{
DeviceHelper.SetTagValue(twin, nameof(item.DeviceFriendlyName), item.DeviceFriendlyName);
DeviceHelper.SetTagValue(twin, nameof(item.DeviceName), item.DeviceName);
DeviceHelper.SetTagValue(twin, nameof(item.LoraRegion), item.LoraRegion);
DeviceHelper.SetTagValue(twin, nameof(item.DeviceType), item.DeviceType);

Expand Down
3 changes: 3 additions & 0 deletions src/AzureIoTHub.Portal/Server/Mappers/DeviceTwinMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public DeviceDetails CreateDeviceDetails(Twin twin)
{
DeviceID = twin.DeviceId,
ModelId = modelId,
DeviceName = Helpers.DeviceHelper.RetrieveTagValue(twin, nameof(DeviceDetails.DeviceName)),
AlreadyLoggedInOnce = Helpers.DeviceHelper.RetrieveReportedPropertyValue(twin, "DevAddr") != null,
ImageUrl = this.deviceModelImageManager.ComputeImageUri(modelId),
IsConnected = twin.ConnectionState == DeviceConnectionState.Connected,
Expand All @@ -51,6 +52,7 @@ public DeviceListItem CreateDeviceListItem(Twin twin)
return new DeviceListItem
{
DeviceID = twin.DeviceId,
DeviceName = Helpers.DeviceHelper.RetrieveTagValue(twin, nameof(DeviceDetails.DeviceName)),
ImageUrl = this.deviceModelImageManager.ComputeImageUri(Helpers.DeviceHelper.RetrieveTagValue(twin, nameof(DeviceDetails.ModelId))),
IsConnected = twin.ConnectionState == DeviceConnectionState.Connected,
IsEnabled = twin.Status == DeviceStatus.Enabled,
Expand All @@ -62,6 +64,7 @@ public DeviceListItem CreateDeviceListItem(Twin twin)
public void UpdateTwin(Twin twin, DeviceDetails item)
{
// Update the twin properties
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.DeviceName), item.DeviceName);
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.LocationCode), item.LocationCode);
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.AssetId), item.AssetId);
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.DeviceType), item.DeviceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Concentrator
public string DeviceId { get; set; }

[Required]
public string DeviceFriendlyName { get; set; }
public string DeviceName { get; set; }

[Required]
public string LoraRegion { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/AzureIoTHub.Portal/Shared/Models/Device/DeviceDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class DeviceDetails
[RegularExpression("^[A-F0-9]{16}$", ErrorMessage = "DeviceID must contain 16 hexadecimal characters (numbers from 0 to 9 and/or letters from A to F)")]
public string DeviceID { get; set; }

[Required]
public string DeviceName { get; set; }

public string ImageUrl { get; set; }

public bool IsConnected { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/AzureIoTHub.Portal/Shared/Models/Device/DeviceListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class DeviceListItem
{
public string DeviceID { get; set; }

public string DeviceName { get; set; }

public string ImageUrl { get; set; }

public bool IsConnected { get; set; }
Expand Down

0 comments on commit 0078fab

Please sign in to comment.