/// <summary> /// Adds a hub to the model /// </summary> /// <param name="hubType"></param> /// <param name="devices"></param> /// <returns></returns> private DeploymentModelBuilder AddHub(DeploymentHubModel hubModel) { _hubs.Add(hubModel); return(this); }
/// <summary> /// Verify a given Hub (protocol + hubId) aganinst a HubModel /// </summary> /// <param name="protocol"></param> /// <param name="hubId"></param> /// <param name="hubModel"></param> /// <returns></returns> public DeploymentModelError[] Verify(IPoweredUpProtocol protocol, byte hubId, DeploymentHubModel hubModel) { if (protocol is null) { throw new ArgumentNullException(nameof(protocol)); } if (hubModel is null) { throw new ArgumentNullException(nameof(hubModel)); } var result = new List <DeploymentModelError>(); var hubInfo = protocol.Knowledge.Hub(hubId); if (hubModel.HubType != null && hubModel.HubType != hubInfo.SystemType) { result.Add(new DeploymentModelError(1002, hubInfo.HubId, null, $"Hub {hubInfo.HubId} with system type {hubInfo.SystemType} does not match expected {hubModel.HubType}.")); } result.AddRange( hubModel.Devices.Select(Device => { var PortInfo = protocol.Knowledge.Port(hubId, Device.PortId); return(Device, PortInfo); }) .Select(t => t switch { (var Device, var PortInfo)when !PortInfo.IsDeviceConnected => (Error: 1000, t.Device, t.PortInfo), // no device connected (var Device, var PortInfo)when Device.DeviceType != null && PortInfo.IOTypeId != Device.DeviceType => (Error: 1001, t.Device, t.PortInfo), // wrong device connected _ => (Error: 0, t.Device, t.PortInfo), })