mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 12:15:01 +00:00
#605 Adds try/catch and more meaningful messages when adding static assets fails
This commit is contained in:
@@ -30,27 +30,29 @@ namespace PepperDash.Essentials.Fusion
|
|||||||
|
|
||||||
foreach (var display in displays.Values.Cast<DisplayBase>())
|
foreach (var display in displays.Values.Cast<DisplayBase>())
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Setting up Static Asset for {0}", display.Key);
|
var disp = display; // Local scope variable
|
||||||
|
|
||||||
display.UsageTracker = new UsageTracking(display) { UsageIsTracked = true };
|
Debug.Console(2, this, "Setting up Static Asset for {0}", disp.Key);
|
||||||
display.UsageTracker.DeviceUsageEnded += UsageTracker_DeviceUsageEnded;
|
|
||||||
|
disp.UsageTracker = new UsageTracking(disp) { UsageIsTracked = true };
|
||||||
|
disp.UsageTracker.DeviceUsageEnded += UsageTracker_DeviceUsageEnded;
|
||||||
|
|
||||||
var dispPowerOnAction = new Action<bool>(b =>
|
var dispPowerOnAction = new Action<bool>(b =>
|
||||||
{
|
{
|
||||||
if (!b)
|
if (!b)
|
||||||
{
|
{
|
||||||
display.PowerOn();
|
disp.PowerOn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var dispPowerOffAction = new Action<bool>(b =>
|
var dispPowerOffAction = new Action<bool>(b =>
|
||||||
{
|
{
|
||||||
if (!b)
|
if (!b)
|
||||||
{
|
{
|
||||||
display.PowerOff();
|
disp.PowerOff();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var deviceConfig = ConfigReader.ConfigObject.GetDeviceForKey(display.Key);
|
var deviceConfig = ConfigReader.ConfigObject.GetDeviceForKey(disp.Key);
|
||||||
|
|
||||||
FusionAsset tempAsset;
|
FusionAsset tempAsset;
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ namespace PepperDash.Essentials.Fusion
|
|||||||
{
|
{
|
||||||
// Create a new asset
|
// Create a new asset
|
||||||
tempAsset = new FusionAsset(FusionRoomGuids.GetNextAvailableAssetNumber(FusionRoom),
|
tempAsset = new FusionAsset(FusionRoomGuids.GetNextAvailableAssetNumber(FusionRoom),
|
||||||
display.Name, "Display", "");
|
disp.Name, "Display", "");
|
||||||
FusionStaticAssets.Add(deviceConfig.Uid, tempAsset);
|
FusionStaticAssets.Add(deviceConfig.Uid, tempAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,21 +74,21 @@ namespace PepperDash.Essentials.Fusion
|
|||||||
dispAsset.PowerOn.OutputSig.UserObject = dispPowerOnAction;
|
dispAsset.PowerOn.OutputSig.UserObject = dispPowerOnAction;
|
||||||
dispAsset.PowerOff.OutputSig.UserObject = dispPowerOffAction;
|
dispAsset.PowerOff.OutputSig.UserObject = dispPowerOffAction;
|
||||||
|
|
||||||
var defaultTwoWayDisplay = display as IHasPowerControlWithFeedback;
|
var defaultTwoWayDisplay = disp as IHasPowerControlWithFeedback;
|
||||||
if (defaultTwoWayDisplay != null)
|
if (defaultTwoWayDisplay != null)
|
||||||
{
|
{
|
||||||
defaultTwoWayDisplay.PowerIsOnFeedback.LinkInputSig(FusionRoom.DisplayPowerOn.InputSig);
|
defaultTwoWayDisplay.PowerIsOnFeedback.LinkInputSig(FusionRoom.DisplayPowerOn.InputSig);
|
||||||
if (display is IDisplayUsage)
|
if (disp is IDisplayUsage)
|
||||||
{
|
{
|
||||||
(display as IDisplayUsage).LampHours.LinkInputSig(FusionRoom.DisplayUsage.InputSig);
|
(disp as IDisplayUsage).LampHours.LinkInputSig(FusionRoom.DisplayUsage.InputSig);
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultTwoWayDisplay.PowerIsOnFeedback.LinkInputSig(dispAsset.PowerOn.InputSig);
|
defaultTwoWayDisplay.PowerIsOnFeedback.LinkInputSig(dispAsset.PowerOn.InputSig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use extension methods
|
// Use extension methods
|
||||||
dispAsset.TrySetMakeModel(display);
|
dispAsset.TrySetMakeModel(disp);
|
||||||
dispAsset.TryLinkAssetErrorToCommunication(display);
|
dispAsset.TryLinkAssetErrorToCommunication(disp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -1676,20 +1676,46 @@ namespace PepperDash.Essentials.Core.Fusion
|
|||||||
public static FusionStaticAsset CreateStaticAsset(this FusionRoom fr, uint number, string name, string type,
|
public static FusionStaticAsset CreateStaticAsset(this FusionRoom fr, uint number, string name, string type,
|
||||||
string instanceId)
|
string instanceId)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Adding Fusion Static Asset '{0}' to slot {1} with GUID: '{2}'", name, number, instanceId);
|
try
|
||||||
|
{
|
||||||
|
Debug.Console(0, "Adding Fusion Static Asset '{0}' to slot {1} with GUID: '{2}'", name, number, instanceId);
|
||||||
|
|
||||||
fr.AddAsset(eAssetType.StaticAsset, number, name, type, instanceId);
|
fr.AddAsset(eAssetType.StaticAsset, number, name, type, instanceId);
|
||||||
return fr.UserConfigurableAssetDetails[number].Asset as FusionStaticAsset;
|
return fr.UserConfigurableAssetDetails[number].Asset as FusionStaticAsset;
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Error creating Static Asset for device: '{0}'. Check that multiple devices don't have missing or duplicate uid properties in configuration. Error: {1}", name, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(2, "Error creating Static Asset: {0}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FusionOccupancySensor CreateOccupancySensorAsset(this FusionRoom fr, uint number, string name,
|
public static FusionOccupancySensor CreateOccupancySensorAsset(this FusionRoom fr, uint number, string name,
|
||||||
string type, string instanceId)
|
string type, string instanceId)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Adding Fusion Occupancy Sensor Asset '{0}' to slot {1} with GUID: '{2}'", name, number,
|
try
|
||||||
instanceId);
|
{
|
||||||
|
Debug.Console(0, "Adding Fusion Occupancy Sensor Asset '{0}' to slot {1} with GUID: '{2}'", name, number,
|
||||||
|
instanceId);
|
||||||
|
|
||||||
fr.AddAsset(eAssetType.OccupancySensor, number, name, type, instanceId);
|
fr.AddAsset(eAssetType.OccupancySensor, number, name, type, instanceId);
|
||||||
return fr.UserConfigurableAssetDetails[number].Asset as FusionOccupancySensor;
|
return fr.UserConfigurableAssetDetails[number].Asset as FusionOccupancySensor;
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Error creating Static Asset for device: '{0}'. Check that multiple devices don't have missing or duplicate uid properties in configuration. Error: {1}", name, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(2, "Error creating Static Asset: {0}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user