Skip to content

Commit

Permalink
v1.2.5
Browse files Browse the repository at this point in the history
- Upgraded to latest MIG
- Added "Color" type to ModuleTypes.cs
  • Loading branch information
genemars committed Jan 12, 2023
1 parent 24ce320 commit 6ec613d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 39 deletions.
2 changes: 1 addition & 1 deletion MIG.HomeAutomation/Commons/ModuleTypes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MIG.Interfaces.HomeAutomation.Commons
{
public enum ModuleTypes_To_Refactor
public enum ModuleTypes
{
Generic = -1,
Program,
Expand Down
2 changes: 1 addition & 1 deletion MIG.HomeAutomation/MIG.HomeAutomation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="CM19Lib" Version="1.2.1" />
<PackageReference Include="MIG" Version="1.2.7" />
<PackageReference Include="MIG" Version="1.2.8" />
<PackageReference Include="SharpZipLib" Version="1.4.1" />
<PackageReference Include="XTenLib" Version="1.1.1" />
<PackageReference Include="ZigBeeNet" Version="1.5.0" />
Expand Down
77 changes: 53 additions & 24 deletions MIG.HomeAutomation/X10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ limitations under the License.
using System.Threading;
using System.Xml.Serialization;

using MIG.Interfaces.HomeAutomation.Commons;
using MIG.Config;
using MIG.Interfaces.HomeAutomation.Commons;

using CM19Lib;
using CM19Lib.X10;

using Newtonsoft.Json;

using XTenLib;

using RfCommandReceivedEventArgs = CM19Lib.Events.RfCommandReceivedEventArgs;
Expand Down Expand Up @@ -134,8 +132,11 @@ public void OnSetOption(Option option)
module.Domain = this.GetDomain();
module.Address = m.Value.Code;
module.Description = m.Value.Description;
module.ModuleType = ModuleTypes.Switch;
module.CustomData = m.Value.Level;
module.CustomData = new X10ModuleData()
{
Level = m.Value.Level,
Type = ModuleTypes.Switch
};
standardModules.Add(module);
}
OnInterfaceModulesChanged(this.GetDomain());
Expand All @@ -161,7 +162,10 @@ public List<InterfaceModule> GetModules()
{
module.Description = "CM19 Transceiver";
}
module.ModuleType = ModuleTypes.Sensor;
module.CustomData = new X10ModuleData()
{
Type = ModuleTypes.Sensor
};
modules.Add(module);
}
// Standard X10 modules
Expand All @@ -170,7 +174,10 @@ public List<InterfaceModule> GetModules()
module = new InterfaceModule();
module.Domain = this.GetDomain();
module.Address = kv.Value.Code;
module.ModuleType = ModuleTypes.Switch;
module.CustomData = new X10ModuleData()
{
Type = ModuleTypes.Switch
};
module.Description = "X10 Module";
modules.Add(module);
}
Expand Down Expand Up @@ -263,28 +270,28 @@ public object InterfaceControl(MigInterfaceCommand request)
{
case Commands.Control_On:
cm19Lib.UnitOn(houseCode, unitCode);
module.CustomData = 1D;
module.CustomData.Level = 1D;
UpdateModuleLevel(module);
break;
case Commands.Control_Off:
cm19Lib.UnitOff(houseCode, unitCode);
module.CustomData = 0D;
module.CustomData.Level = 0D;
UpdateModuleLevel(module);
break;
case Commands.Control_Bright:
cm19Lib.Bright(houseCode);
module.CustomData = module.CustomData + (5 / 100D);
if (module.CustomData > 1) module.CustomData = 1D;
module.CustomData.Level += (5 / 100D);
if (module.CustomData.Level > 1) module.CustomData.Level = 1D;
UpdateModuleLevel(module);
break;
case Commands.Control_Dim:
cm19Lib.Dim(houseCode);
module.CustomData = module.CustomData - (5 / 100D);
if (module.CustomData < 0) module.CustomData = 0D;
module.CustomData.Level -= (5 / 100D);
if (module.CustomData.Level < 0) module.CustomData.Level = 0D;
UpdateModuleLevel(module);
break;
case Commands.Control_Level:
int dimValue = (int.Parse(option) - (int) (module.CustomData * 100.0)) / 5;
int dimValue = (int.Parse(option) - (int) (module.CustomData.Level * 100.0)) / 5;
if (dimValue > 0)
{
cm19Lib.Bright(houseCode);
Expand All @@ -301,11 +308,11 @@ public object InterfaceControl(MigInterfaceCommand request)
cm19Lib.Dim(houseCode);
}
}
module.CustomData = module.CustomData + (dimValue * 5 / 100D);
module.CustomData.Level += (dimValue * 5 / 100D);
UpdateModuleLevel(module);
break;
case Commands.Control_Toggle:
if (module.CustomData == 0D)
if (module.CustomData.Level == 0D)
{
cm19Lib.UnitOn(houseCode, unitCode);
UpdateModuleLevel(module);
Expand Down Expand Up @@ -504,8 +511,11 @@ private InterfaceModule AddSecurityModule(ModuleTypes moduleType, string address
module.Domain = this.GetDomain();
module.Address = address;
module.Description = "X10 Security";
module.ModuleType = moduleType;
module.CustomData = 0D;
module.CustomData = new X10ModuleData()
{
Level = 0D,
Type = moduleType
};
securityModules.Add(module);
SerializeModules(SecurityModulesDb, securityModules);
OnInterfacePropertyChanged(module.Domain, "RF", "X10 RF Receiver", ModuleEvents.Receiver_Status, "Added module " + address + " (" + moduleType + ")");
Expand Down Expand Up @@ -654,21 +664,21 @@ private void Cm19LibOnRfCommandReceived(object sender, RfCommandReceivedEventArg
switch (args.Command)
{
case Function.On:
module.CustomData = 1D;
module.CustomData.Level = 1D;
UpdateModuleLevel(module);
break;
case Function.Off:
module.CustomData = 0D;
module.CustomData.Level = 0D;
UpdateModuleLevel(module);
break;
case Function.Bright:
module.CustomData = module.CustomData + 1D/22D;
if (module.CustomData > 1) module.CustomData = 1D;
module.CustomData.Level += 1D/22D;
if (module.CustomData.Level > 1) module.CustomData.Level = 1D;
UpdateModuleLevel(module);
break;
case Function.Dim:
module.CustomData = module.CustomData - 1D/22D;
if (module.CustomData < 0) module.CustomData = 0D;
module.CustomData.Level -= 1D/22D;
if (module.CustomData.Level < 0) module.CustomData.Level = 0D;
UpdateModuleLevel(module);
break;
case Function.AllLightsOn:
Expand Down Expand Up @@ -782,4 +792,23 @@ protected virtual void OnInterfacePropertyChanged(string domain, string source,
#endregion

}

public class X10ModuleData
{
private double level = 0;
public double Level {
get => level;
set
{
level = value;
if (level != 0)
{
LastLevel = level;
}
}
}
public double LastLevel;
public ModuleTypes Type = ModuleTypes.Generic;
}

}
41 changes: 31 additions & 10 deletions MIG.HomeAutomation/ZWave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,54 +191,57 @@ public List<InterfaceModule> GetModules()
module.Domain = this.GetDomain();
module.Address = node.Id.ToString();
//module.Description = "ZWave Node";
module.ModuleType = ModuleTypes.Generic;
module.CustomData = new ZWaveNodeData()
{
Type = ModuleTypes.Generic
};
if (node.ProtocolInfo.GenericType != (byte)GenericType.None)
{
switch (node.ProtocolInfo.GenericType)
{
case (byte)GenericType.StaticController:
module.Description = "Static Controller";
module.ModuleType = ModuleTypes.Generic;
module.CustomData.Type = ModuleTypes.Generic;
break;

case (byte)GenericType.SwitchBinary:
module.Description = "Binary Switch";
module.ModuleType = ModuleTypes.Switch;
module.CustomData.Type = ModuleTypes.Switch;
break;

case (byte)GenericType.SwitchMultilevel:
module.Description = "Multilevel Switch";
module.ModuleType = ModuleTypes.Dimmer;
module.CustomData.Type = ModuleTypes.Dimmer;
break;

case (byte)GenericType.Thermostat:
module.Description = "Thermostat";
module.ModuleType = ModuleTypes.Thermostat;
module.CustomData.Type = ModuleTypes.Thermostat;
break;

case (byte)GenericType.SensorAlarm:
module.Description = "Alarm Sensor";
module.ModuleType = ModuleTypes.Sensor;
module.CustomData.Type = ModuleTypes.Sensor;
break;

case (byte)GenericType.SensorBinary:
module.Description = "Binary Sensor";
module.ModuleType = ModuleTypes.Sensor;
module.CustomData.Type = ModuleTypes.Sensor;
break;

case (byte)GenericType.SensorMultilevel:
module.Description = "Multilevel Sensor";
module.ModuleType = ModuleTypes.Sensor;
module.CustomData.Type = ModuleTypes.Sensor;
break;

case (byte)GenericType.Meter:
module.Description = "ZWave Meter";
module.ModuleType = ModuleTypes.Sensor;
module.CustomData.Type = ModuleTypes.Sensor;
break;

case (byte)GenericType.EntryControl:
module.Description = "ZWave Door Lock";
module.ModuleType = ModuleTypes.DoorLock;
module.CustomData.Type = ModuleTypes.DoorLock;
break;

}
Expand Down Expand Up @@ -1241,4 +1244,22 @@ protected virtual void OnInterfacePropertyChanged(string domain, string source,
#endregion

}

public class ZWaveNodeData
{
private double level = 0;
public double Level {
get => level;
set
{
level = value;
if (level != 0)
{
LastLevel = level;
}
}
}
public double LastLevel;
public ModuleTypes Type = ModuleTypes.Generic;
}
}
8 changes: 5 additions & 3 deletions MIG.HomeAutomation/ZigBee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ public void AddNode(ZigBeeNode node)
{
Domain = "HomeAutomation.ZigBee",
Address = address,
// TODO: get device type
ModuleType = ModuleTypes.Dimmer,
CustomData = new ZigBeeNodeData()
{
// TODO: get type from device node
Type = ModuleTypes.Dimmer
}
});
lastAddedNode = node.NetworkAddress;
OnInterfacePropertyChanged(this.GetDomain(), "0", "ZigBee Controller", "Controller.Status", "Added node " + node.NetworkAddress);
Expand Down Expand Up @@ -517,7 +519,6 @@ private async Task DiscoverAttributes(ZigBeeEndpoint endpoint)

}


public class ZigBeeNodeData
{
private double level = 0;
Expand All @@ -534,6 +535,7 @@ public double Level {
}
public double LastLevel;
public ushort Transition = 4; // 400ms
public ModuleTypes Type = ModuleTypes.Generic;
}

public class ConsoleCommandListener : IZigBeeCommandListener
Expand Down

0 comments on commit 6ec613d

Please sign in to comment.