mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-01 05:44:55 +00:00
refactor: make messenger constructors more consistent
Some constructors for messengers were taking Device rather than the specific type they needed.
This commit is contained in:
@@ -8,9 +8,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
{
|
||||
private readonly IChannel channelDevice;
|
||||
|
||||
public IChannelMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public IChannelMessenger(string key, string messagePath, IChannel device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
channelDevice = device as IChannel;
|
||||
channelDevice = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class IColorMessenger : MessengerBase
|
||||
{
|
||||
private readonly IColor colorDevice;
|
||||
public IColorMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public IColorMessenger(string key, string messagePath, IColor device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
colorDevice = device as IColor;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class IDPadMessenger : MessengerBase
|
||||
{
|
||||
private readonly IDPad dpadDevice;
|
||||
public IDPadMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public IDPadMessenger(string key, string messagePath, IDPad device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
dpadDevice = device as IDPad;
|
||||
dpadDevice = device;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class IDvrMessenger : MessengerBase
|
||||
{
|
||||
private readonly IDvr dvrDevice;
|
||||
public IDvrMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public IDvrMessenger(string key, string messagePath, IDvr device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
dvrDevice = device as IDvr;
|
||||
dvrDevice = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class IHasPowerMessenger : MessengerBase
|
||||
{
|
||||
private readonly IHasPowerControl powerDevice;
|
||||
public IHasPowerMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public IHasPowerMessenger(string key, string messagePath, IHasPowerControl device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
powerDevice = device as IHasPowerControl;
|
||||
powerDevice = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class INumericKeypadMessenger : MessengerBase
|
||||
{
|
||||
private readonly INumericKeypad keypadDevice;
|
||||
public INumericKeypadMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public INumericKeypadMessenger(string key, string messagePath, INumericKeypad device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
keypadDevice = device as INumericKeypad;
|
||||
keypadDevice = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class ISetTopBoxControlsMessenger : MessengerBase
|
||||
{
|
||||
private readonly ISetTopBoxControls stbDevice;
|
||||
public ISetTopBoxControlsMessenger(string key, string messagePath, IKeyName device) : base(key, messagePath, device)
|
||||
public ISetTopBoxControlsMessenger(string key, string messagePath, ISetTopBoxControls device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
stbDevice = device as ISetTopBoxControls;
|
||||
stbDevice = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PepperDash.Essentials.Room.MobileControl
|
||||
public class ITransportMessenger : MessengerBase
|
||||
{
|
||||
private readonly ITransport transportDevice;
|
||||
public ITransportMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
|
||||
public ITransportMessenger(string key, string messagePath, ITransport device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
transportDevice = device as ITransport;
|
||||
transportDevice = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly IEssentialsRoomCombiner _roomCombiner;
|
||||
|
||||
public IEssentialsRoomCombinerMessenger(string key, string messagePath, IEssentialsRoomCombiner roomCombiner)
|
||||
: base(key, messagePath, roomCombiner as Device)
|
||||
: base(key, messagePath, roomCombiner as IKeyName)
|
||||
{
|
||||
_roomCombiner = roomCombiner;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly IHasPowerControlWithFeedback _powerControl;
|
||||
|
||||
public IHasPowerControlWithFeedbackMessenger(string key, string messagePath, IHasPowerControlWithFeedback powerControl)
|
||||
: base(key, messagePath, powerControl as Device)
|
||||
: base(key, messagePath, powerControl as IKeyName)
|
||||
{
|
||||
_powerControl = powerControl;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
public IHasScheduleAwareness ScheduleSource { get; private set; }
|
||||
|
||||
public IHasScheduleAwarenessMessenger(string key, IHasScheduleAwareness scheduleSource, string messagePath)
|
||||
: base(key, messagePath, scheduleSource as Device)
|
||||
: base(key, messagePath, scheduleSource as IKeyName)
|
||||
{
|
||||
ScheduleSource = scheduleSource ?? throw new ArgumentNullException("scheduleSource");
|
||||
ScheduleSource.CodecSchedule.MeetingsListHasChanged += new EventHandler<EventArgs>(CodecSchedule_MeetingsListHasChanged);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly IHumiditySensor device;
|
||||
|
||||
public IHumiditySensorMessenger(string key, IHumiditySensor device, string messagePath)
|
||||
: base(key, messagePath, device as Device)
|
||||
: base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
public class ILevelControlsMessenger : MessengerBase
|
||||
{
|
||||
private ILevelControls levelControlsDevice;
|
||||
public ILevelControlsMessenger(string key, string messagePath, ILevelControls device) : base(key, messagePath, device as Device)
|
||||
public ILevelControlsMessenger(string key, string messagePath, ILevelControls device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
levelControlsDevice = device;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
public class IMatrixRoutingMessenger : MessengerBase
|
||||
{
|
||||
private readonly IMatrixRouting matrixDevice;
|
||||
public IMatrixRoutingMessenger(string key, string messagePath, IMatrixRouting device) : base(key, messagePath, device as Device)
|
||||
public IMatrixRoutingMessenger(string key, string messagePath, IMatrixRouting device) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
matrixDevice = device;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly IProjectorScreenLiftControl device;
|
||||
|
||||
public IProjectorScreenLiftControlMessenger(string key, string messagePath, IProjectorScreenLiftControl screenLiftDevice)
|
||||
: base(key, messagePath, screenLiftDevice as Device)
|
||||
: base(key, messagePath, screenLiftDevice as IKeyName)
|
||||
{
|
||||
device = screenLiftDevice;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
public IRunRouteAction RoutingDevice { get; private set; }
|
||||
|
||||
public RunRouteActionMessenger(string key, IRunRouteAction routingDevice, string messagePath)
|
||||
: base(key, messagePath, routingDevice as Device)
|
||||
: base(key, messagePath, routingDevice as IKeyName)
|
||||
{
|
||||
RoutingDevice = routingDevice ?? throw new ArgumentNullException("routingDevice");
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
public class ISelectableItemsMessenger<TKey> : MessengerBase
|
||||
{
|
||||
private static readonly JsonSerializer serializer = new JsonSerializer { Converters = { new StringEnumConverter() } };
|
||||
private ISelectableItems<TKey> itemDevice;
|
||||
private readonly ISelectableItems<TKey> itemDevice;
|
||||
|
||||
private readonly string _propName;
|
||||
public ISelectableItemsMessenger(string key, string messagePath, ISelectableItems<TKey> device, string propName) : base(key, messagePath, device as Device)
|
||||
public ISelectableItemsMessenger(string key, string messagePath, ISelectableItems<TKey> device, string propName) : base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
itemDevice = device;
|
||||
_propName = propName;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly IShutdownPromptTimer _room;
|
||||
|
||||
public IShutdownPromptTimerMessenger(string key, string messagePath, IShutdownPromptTimer room)
|
||||
: base(key, messagePath, room as Device)
|
||||
: base(key, messagePath, room as IKeyName)
|
||||
{
|
||||
_room = room;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly ISwitchedOutput device;
|
||||
|
||||
public ISwitchedOutputMessenger(string key, ISwitchedOutput device, string messagePath)
|
||||
: base(key, messagePath, device as Device)
|
||||
: base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly ITechPassword _room;
|
||||
|
||||
public ITechPasswordMessenger(string key, string messagePath, ITechPassword room)
|
||||
: base(key, messagePath, room as Device)
|
||||
: base(key, messagePath, room as IKeyName)
|
||||
{
|
||||
_room = room;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly ITemperatureSensor device;
|
||||
|
||||
public ITemperatureSensorMessenger(string key, ITemperatureSensor device, string messagePath)
|
||||
: base(key, messagePath, device as Device)
|
||||
: base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
protected ILightingScenes Device { get; private set; }
|
||||
|
||||
public ILightingScenesMessenger(string key, ILightingScenes device, string messagePath)
|
||||
: base(key, messagePath, device as Device)
|
||||
: base(key, messagePath, device as IKeyName)
|
||||
{
|
||||
Device = device ?? throw new ArgumentNullException("device");
|
||||
Device.LightingSceneChange += new EventHandler<LightingSceneChangeEventArgs>(LightingDevice_LightingSceneChange);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
|
||||
|
||||
public RoomEventScheduleMessenger(string key, string messagePath, IRoomEventSchedule room)
|
||||
: base(key, messagePath, room as Device)
|
||||
: base(key, messagePath, room as IKeyName)
|
||||
{
|
||||
_room = room;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
private readonly IShadesOpenCloseStop device;
|
||||
|
||||
public IShadesOpenCloseStopMessenger(string key, IShadesOpenCloseStop shades, string messagePath)
|
||||
: base(key, messagePath, shades as Device)
|
||||
: base(key, messagePath, shades as IKeyName)
|
||||
{
|
||||
device = shades;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
{
|
||||
private readonly TwoWayDisplayBase _display;
|
||||
|
||||
public TwoWayDisplayBaseMessenger(string key, string messagePath) : base(key, messagePath)
|
||||
{
|
||||
}
|
||||
|
||||
public TwoWayDisplayBaseMessenger(string key, string messagePath, TwoWayDisplayBase display)
|
||||
: this(key, messagePath)
|
||||
: base(key, messagePath, display)
|
||||
{
|
||||
_display = display;
|
||||
}
|
||||
|
||||
@@ -566,18 +566,16 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is ISetTopBoxControls)
|
||||
if (device is ISetTopBoxControls stbDevice)
|
||||
{
|
||||
this.LogVerbose(
|
||||
"Adding ISetTopBoxControlMessenger for {deviceKey}"
|
||||
);
|
||||
|
||||
var dev = device as Device;
|
||||
);
|
||||
|
||||
var messenger = new ISetTopBoxControlsMessenger(
|
||||
$"{device.Key}-stb-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
stbDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -585,18 +583,16 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is IChannel)
|
||||
if (device is IChannel channelDevice)
|
||||
{
|
||||
this.LogVerbose(
|
||||
"Adding IChannelMessenger for {deviceKey}", device.Key
|
||||
);
|
||||
|
||||
var dev = device as PepperDash.Core.Device;
|
||||
);
|
||||
|
||||
var messenger = new IChannelMessenger(
|
||||
$"{device.Key}-channel-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
channelDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -604,16 +600,14 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is IColor)
|
||||
if (device is IColor colorDevice)
|
||||
{
|
||||
this.LogVerbose("Adding IColorMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var dev = device as PepperDash.Core.Device;
|
||||
this.LogVerbose("Adding IColorMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var messenger = new IColorMessenger(
|
||||
$"{device.Key}-color-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
colorDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -621,16 +615,14 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is IDPad)
|
||||
if (device is IDPad dPadDevice)
|
||||
{
|
||||
this.LogVerbose("Adding IDPadMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var dev = device as PepperDash.Core.Device;
|
||||
this.LogVerbose("Adding IDPadMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var messenger = new IDPadMessenger(
|
||||
$"{device.Key}-dPad-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
dPadDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -638,16 +630,14 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is INumericKeypad)
|
||||
if (device is INumericKeypad nkDevice)
|
||||
{
|
||||
this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var dev = device as PepperDash.Core.Device;
|
||||
this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var messenger = new INumericKeypadMessenger(
|
||||
$"{device.Key}-numericKeypad-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
nkDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -655,16 +645,14 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is IHasPowerControl)
|
||||
if (device is IHasPowerControl pcDevice)
|
||||
{
|
||||
this.LogVerbose("Adding IHasPowerControlMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var dev = device as PepperDash.Core.Device;
|
||||
this.LogVerbose("Adding IHasPowerControlMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var messenger = new IHasPowerMessenger(
|
||||
$"{device.Key}-powerControl-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
pcDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -689,18 +677,16 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is ITransport)
|
||||
if (device is ITransport transportDevice)
|
||||
{
|
||||
this.LogVerbose(
|
||||
"Adding ITransportMessenger for {deviceKey}", device.Key
|
||||
);
|
||||
);
|
||||
|
||||
var dev = device as PepperDash.Core.Device;
|
||||
|
||||
var messenger = new IChannelMessenger(
|
||||
var messenger = new ITransportMessenger(
|
||||
$"{device.Key}-transport-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
dev
|
||||
transportDevice
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -708,14 +694,14 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is IHasCurrentSourceInfoChange)
|
||||
if (device is IHasCurrentSourceInfoChange csiChange)
|
||||
{
|
||||
this.LogVerbose("Adding IHasCurrentSourceInfoMessenger for {deviceKey}", device.Key);
|
||||
|
||||
var messenger = new IHasCurrentSourceInfoMessenger(
|
||||
$"{device.Key}-currentSource-{Key}",
|
||||
$"/device/{device.Key}",
|
||||
device as IHasCurrentSourceInfoChange
|
||||
csiChange
|
||||
);
|
||||
|
||||
AddDefaultDeviceMessenger(messenger);
|
||||
@@ -723,7 +709,7 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
if (device is ISwitchedOutput)
|
||||
if (device is ISwitchedOutput switchedDevice)
|
||||
{
|
||||
this.LogVerbose(
|
||||
"Adding ISwitchedOutputMessenger for {deviceKey}", device.Key
|
||||
@@ -731,7 +717,7 @@ namespace PepperDash.Essentials
|
||||
|
||||
var messenger = new ISwitchedOutputMessenger(
|
||||
$"{device.Key}-switchedOutput-{Key}",
|
||||
device as ISwitchedOutput,
|
||||
switchedDevice,
|
||||
$"/device/{device.Key}"
|
||||
);
|
||||
|
||||
@@ -773,40 +759,6 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
// This will work if TKey and TSelector are both string types.
|
||||
// Otherwise plugin device needs to instantiate ISelectableItemsMessenger and add it to the controller.
|
||||
//if (device is IHasInputs<string, string> inputs)
|
||||
//{
|
||||
// this.LogVerbose("Adding InputsMessenger<string,string> for {deviceKey}", device.Key);
|
||||
|
||||
// var messenger = new ISelectableItemsMessenger<string>(
|
||||
// $"{device.Key}-inputs-{Key}",
|
||||
// $"/device/{device.Key}",
|
||||
// inputs.Inputs,
|
||||
// "inputs"
|
||||
// );
|
||||
|
||||
// AddDefaultDeviceMessenger(messenger);
|
||||
|
||||
// messengerAdded = true;
|
||||
//}
|
||||
|
||||
//if (device is IHasInputs<byte, int> byteIntInputs)
|
||||
//{
|
||||
// this.LogVerbose("Adding InputsMessenger<byte, int> for {deviceKey}", device.Key);
|
||||
|
||||
// var messenger = new ISelectableItemsMessenger<byte>(
|
||||
// $"{device.Key}-inputs-{Key}",
|
||||
// $"/device/{device.Key}",
|
||||
// byteIntInputs.Inputs,
|
||||
// "inputs"
|
||||
// );
|
||||
|
||||
// AddDefaultDeviceMessenger(messenger);
|
||||
|
||||
// messengerAdded = true;
|
||||
//}
|
||||
|
||||
if (device is IHasInputs<string> stringInputs)
|
||||
{
|
||||
this.LogVerbose("Adding InputsMessenger<string> for {deviceKey}", device.Key);
|
||||
@@ -855,7 +807,6 @@ namespace PepperDash.Essentials
|
||||
messengerAdded = true;
|
||||
}
|
||||
|
||||
|
||||
if (device is IMatrixRouting matrix)
|
||||
{
|
||||
this.LogVerbose(
|
||||
|
||||
Reference in New Issue
Block a user