Skip to content

Commit

Permalink
AppEUI moved from DeviceModel to DeviceDetails (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
audserraCGI authored Jul 22, 2022
1 parent f068699 commit 5229998
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void CreateDeviceModelStateUnderTestExpectedBehavior(bool isBuiltin, bool
entity[nameof(LoRaDeviceModel.SupportLoRaFeatures)] = supportLora;
entity[nameof(LoRaDeviceModel.Name)] = "FAKE DEVICE";
entity[nameof(LoRaDeviceModel.Description)] = "FAKE DESCRIPTION";
entity[nameof(LoRaDeviceModel.AppEUI)] = "FAKE APP EUI";
entity[nameof(LoRaDeviceModel.SensorDecoder)] = "FAKE SENSORDECODERURL";

// Act
Expand All @@ -98,7 +97,6 @@ public void CreateDeviceModelStateUnderTestExpectedBehavior(bool isBuiltin, bool
Assert.AreEqual(entity.RowKey, result.ModelId);
Assert.AreEqual(entity[nameof(LoRaDeviceModel.Name)], result.Name);
Assert.AreEqual(entity[nameof(LoRaDeviceModel.Description)], result.Description);
Assert.AreEqual(entity[nameof(LoRaDeviceModel.AppEUI)], result.AppEUI);
Assert.AreEqual(entity[nameof(LoRaDeviceModel.SensorDecoder)], result.SensorDecoder);
Assert.AreEqual(entity[nameof(LoRaDeviceModel.SupportLoRaFeatures)], supportLora);
Assert.AreEqual(entity[nameof(LoRaDeviceModel.IsBuiltin)], isBuiltin);
Expand All @@ -118,7 +116,6 @@ public void UpdateTableEntityStateUnderTestExpectedBehavior(bool isBuiltin, bool
{
ModelId = entity.RowKey,
Name = Guid.NewGuid().ToString(),
AppEUI = Guid.NewGuid().ToString(),
Description = Guid.NewGuid().ToString(),
ImageUrl = new Uri("http://fake.local"),
SensorDecoder = Guid.NewGuid().ToString(),
Expand All @@ -138,7 +135,6 @@ public void UpdateTableEntityStateUnderTestExpectedBehavior(bool isBuiltin, bool
Assert.AreEqual(model.Description, entity[nameof(LoRaDeviceModel.Description)]);
Assert.AreEqual(supportLora, entity[nameof(LoRaDeviceModel.SupportLoRaFeatures)]);
Assert.AreEqual(isBuiltin, entity[nameof(LoRaDeviceModel.IsBuiltin)]);
Assert.AreEqual(model.AppEUI, entity[nameof(LoRaDeviceModel.AppEUI)]);
Assert.AreEqual(model.SensorDecoder, entity[nameof(LoRaDeviceModel.SensorDecoder)]);
this.mockRepository.VerifyAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void UpdateTwinStateUnderTestExpectedBehavior()
Assert.AreEqual(item.Tags[tagName], DeviceHelper.RetrieveTagValue(twin, tagName));
}

Assert.AreEqual(item.AppEUI, twin.Properties.Desired[nameof(LoRaDeviceDetails.AppEUI)].ToString());
Assert.AreEqual(item.AppKey, twin.Properties.Desired[nameof(LoRaDeviceDetails.AppKey)].ToString());

this.mockRepository.VerifyAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ public void ClickOnSaveShouldPostLoRaDeviceModelData()

cut.WaitForElement($"#{nameof(DeviceModel.Name)}").Change(modelName);
cut.WaitForElement($"#{nameof(DeviceModel.Description)}").Change(description);
(cut.Instance.Model as LoRaDeviceModel).AppEUI = "AppEUI";

saveButton.Click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace AzureIoTHub.Portal.Server.Tests.Unit.Validators
{
using System;
using AzureIoTHub.Portal.Client.Validators;
using AzureIoTHub.Portal.Models.v10.LoRaWAN;
using NUnit.Framework;
Expand All @@ -19,7 +18,7 @@ public void ValidateValidOTAAModel()
var loraModel = new LoRaDeviceModel()
{
UseOTAA = true,
AppEUI = Guid.NewGuid().ToString(),
//AppEUI = Guid.NewGuid().ToString(),
};

// Act
Expand All @@ -30,26 +29,26 @@ public void ValidateValidOTAAModel()
Assert.AreEqual(0, loraModelValidation.Errors.Count);
}

[Test]
public void ValidateMissingAppEUIFieldShouldReturnError()
{
//[Test]
//public void ValidateMissingAppEUIFieldShouldReturnError()
//{

// Arrange
var loraModelValidator = new LoRaDeviceModelValidator();
var loraModel = new LoRaDeviceModel()
{
UseOTAA = true,
AppEUI = "",
};
// // Arrange
// var loraModelValidator = new LoRaDeviceModelValidator();
// var loraModel = new LoRaDeviceModel()
// {
// UseOTAA = true,
// //AppEUI = "",
// };

// Act
var loraModelValidation = loraModelValidator.Validate(loraModel);
// // Act
// var loraModelValidation = loraModelValidator.Validate(loraModel);

// Assert
Assert.IsFalse(loraModelValidation.IsValid);
Assert.AreEqual(1, loraModelValidation.Errors.Count);
Assert.AreEqual(loraModelValidation.Errors[0].ErrorMessage, "AppEUI is required.");
// // Assert
// Assert.IsFalse(loraModelValidation.IsValid);
// Assert.AreEqual(1, loraModelValidation.Errors.Count);
// Assert.AreEqual(loraModelValidation.Errors[0].ErrorMessage, "AppEUI is required.");

}
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@
{
var loraDeviceModel = Model as LoRaDeviceModel;

if (!loraDeviceModel.UseOTAA)
{
loraDeviceModel.AppEUI = null;
}

loraDeviceModel.SupportLoRaFeatures = true;

await LoRaWanDeviceModelsClientService.CreateDeviceModel(loraDeviceModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
<MudSwitch id="@nameof(LoRaDeviceModel.UseOTAA)" @bind-Checked="@LoRaDeviceModel.UseOTAA" Color="Color.Primary" Label="Support OTAA/ABP setting"></MudSwitch>
<MudText Typo="Typo.subtitle1" Class="mud-input-helper-text">@(LoRaDeviceModel.UseOTAA ? "OTAA setting" : "ABP setting") <b>is</b> used</MudText>
</MudItem>
@if (!LoRaDeviceModel.UseOTAA)
{
<MudItem md="6" xs="12">
@if (!LoRaDeviceModel.UseOTAA)
{
<MudCheckBox id="@nameof(LoRaDeviceModel.ABPRelaxMode)" @bind-Checked="@LoRaDeviceModel.ABPRelaxMode" For="@(() => LoRaDeviceModel.ABPRelaxMode)" Label="Disable ABP relax mode" Color="Color.Primary"></MudCheckBox>
}
</MudItem>

}
<MudItem md="3" xs="6">
<MudSelect id="@nameof(LoRaDeviceModel.ClassType)"
@bind-Value="@LoRaDeviceModel.ClassType"
Expand All @@ -45,12 +44,6 @@
</MudItem>
<MudItem md="6" xs=12>
<MudGrid>
@if (LoRaDeviceModel.UseOTAA)
{
<MudItem xs="12">
<MudTextField id="@nameof(LoRaDeviceModel.AppEUI)" @bind-Value="@LoRaDeviceModel.AppEUI" Label="OTAA AppEUI" For="@(() => LoRaDeviceModel.AppEUI)" Variant="Variant.Outlined" Required="true"></MudTextField>
</MudItem>
}
<MudItem xs="12">
<MudTextField id="@nameof(LoRaDeviceModel.SensorDecoder)" @bind-Value="@LoRaDeviceModel.SensorDecoder" Label="Sensor Decoder URL" For="@(() => LoRaDeviceModel.SensorDecoder)" Variant="Variant.Outlined"></MudTextField>
</MudItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<MudSwitch @bind-Checked="@LoRaDeviceModel.UseOTAA" Disabled="true" Label="Support OTAA/ABP setting"></MudSwitch>
<MudText Typo="Typo.subtitle1" Class="mud-input-helper-text">@(LoRaDeviceModel.UseOTAA ? "OTAA setting" : "ABP setting") <b>is</b> used</MudText>
</MudItem>
@if (!LoRaDeviceModel.UseOTAA)
{
<MudItem md="6" xs="12">
@if (!LoRaDeviceModel.UseOTAA)
{
<MudCheckBox id="@nameof(LoRaDeviceModel.ABPRelaxMode)" @bind-Checked="@LoRaDeviceModel.ABPRelaxMode" For="@(() => LoRaDeviceModel.ABPRelaxMode)" Label="Disable ABP relax mode" Color="Color.Primary"></MudCheckBox>
}
</MudItem>
}
<MudItem md="3" xs="6">
<MudSelect id="@nameof(LoRaDeviceModel.ClassType)"
@bind-Value="@LoRaDeviceModel.ClassType"
Expand All @@ -44,12 +44,6 @@
</MudItem>
<MudItem md="6" xs=12>
<MudGrid>
@if (LoRaDeviceModel.UseOTAA)
{
<MudItem xs="12">
<MudTextField @bind-Value="@LoRaDeviceModel.AppEUI" Label="OTAA AppEUI" For="@(() => LoRaDeviceModel.AppEUI)" Variant="Variant.Outlined" Required="true"></MudTextField>
</MudItem>
}
<MudItem xs="12">
<MudTextField @bind-Value="@LoRaDeviceModel.SensorDecoder" Label="Sensor Decoder URL" For="@(() => LoRaDeviceModel.SensorDecoder)" Variant="Variant.Outlined"></MudTextField>
</MudItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@

var loRaDeviceModelResult = await LoRaWanDeviceModelsClientService.GetDeviceModel(model.ModelId);

device.AppEUI = loRaDeviceModelResult.AppEUI;
device.SensorDecoder = loRaDeviceModelResult.SensorDecoder;
device.UseOTAA = loRaDeviceModelResult.UseOTAA;
loRaDeviceModel = loRaDeviceModelResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
Label="OTAA AppEUI"
Variant="Variant.Outlined"
For="@(()=> LoRaDevice.AppEUI)"
ReadOnly="true"
Required="true"
HelperText="OTAA AppEUI is automatically set from the selected model" />
Required="true" />
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@LoRaDevice.AppKey"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@if (LoRaDeviceModel.UseOTAA)
{
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@LoRaDevice.AppEUI" Label="OTAA App EUI" For="@(() => LoRaDevice.AppEUI)" ReadOnly="true" Variant="Variant.Outlined" Required="true"></MudTextField>
<MudTextField @bind-Value="@LoRaDevice.AppEUI" Label="OTAA App EUI" For="@(() => LoRaDevice.AppEUI)" Variant="Variant.Outlined" Required="true"></MudTextField>
</MudItem>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@LoRaDevice.AppKey" Label="OTAA App Key" For="@(() => LoRaDevice.AppKey)" Variant="Variant.Outlined" Required="true"></MudTextField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,5 @@ namespace AzureIoTHub.Portal.Client.Validators

public class LoRaDeviceModelValidator : AbstractValidator<LoRaDeviceModel>
{
public LoRaDeviceModelValidator()
{
_ = RuleFor(x => x.AppEUI)
.NotEmpty()
//.Length(1, 100)
.When(x => x.UseOTAA)
.WithMessage("AppEUI is required.");
}
}
}
1 change: 1 addition & 0 deletions src/AzureIoTHub.Portal/Server/Mappers/LoRaDeviceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void UpdateTwin(Twin twin, LoRaDeviceDetails item)
Helpers.DeviceHelper.SetTagValue(twin, nameof(item.ModelId), item.ModelId);

// Update OTAA settings
Helpers.DeviceHelper.SetDesiredProperty(twin, nameof(item.AppEUI), item.AppEUI);
Helpers.DeviceHelper.SetDesiredProperty(twin, nameof(item.AppKey), item.AppKey);

// Update ABP settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public LoRaDeviceModel CreateDeviceModel(TableEntity entity)
ImageUrl = this.deviceModelImageManager.ComputeImageUri(entity.RowKey),
Name = entity[nameof(LoRaDeviceModel.Name)]?.ToString(),
Description = entity[nameof(LoRaDeviceModel.Description)]?.ToString(),
AppEUI = entity[nameof(LoRaDeviceModel.AppEUI)]?.ToString(),
SensorDecoder = entity[nameof(LoRaDeviceModel.SensorDecoder)]?.ToString(),
SupportLoRaFeatures = true,
UseOTAA = bool.Parse(entity[nameof(LoRaDeviceModel.UseOTAA)]?.ToString() ?? "true"),
Expand Down Expand Up @@ -79,11 +78,6 @@ public Dictionary<string, object> UpdateTableEntity(TableEntity entity, LoRaDevi

var desiredProperties = new Dictionary<string, object>();

if (model.UseOTAA)
{
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.AppEUI), model.AppEUI, desiredProperties);
}

AddOptionnalProperties(entity, nameof(LoRaDeviceModel.SensorDecoder), model.SensorDecoder, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.Supports32BitFCnt), model.Supports32BitFCnt, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.ABPRelaxMode), model.ABPRelaxMode, desiredProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ public class LoRaDeviceBase : DeviceDetails
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool UseOTAA { get; set; }

/// <summary>
/// The device OTAA Application eui.
/// </summary>
// [Required(ErrorMessage = "The OTAA App EUI is required.")]
public string AppEUI { get; set; }

/// <summary>
/// The sensor decoder API Url.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public class LoRaDeviceDetails : LoRaDeviceBase
// [Required(ErrorMessage = "The LoRa Device OTAA App Key is required.")]
public string AppKey { get; set; }

/// <summary>
/// The device OTAA Application EUI.
/// </summary>
// [Required(ErrorMessage = "The OTAA App EUI is required.")]
public string AppEUI { get; set; }

/// <summary>
/// The ABP AppSKey.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public class LoRaDeviceModelBase : DeviceModel
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool UseOTAA { get; set; }

/// <summary>
/// The device OTAA Application eui.
/// </summary>
// [Required(ErrorMessage = "The OTAA App EUI is required.")]
public string AppEUI { get; set; }

/// <summary>
/// The sensor decoder API Url.
/// </summary>
Expand Down

0 comments on commit 5229998

Please sign in to comment.