diff --git a/Enums/ZigbeeEnums.cs b/Enums/ZigbeeEnums.cs index 7427f34..e3c02b2 100644 --- a/Enums/ZigbeeEnums.cs +++ b/Enums/ZigbeeEnums.cs @@ -22,12 +22,12 @@ public enum ZigbeeButtonCommands public enum ZigbeeDeviceName { Unknown = 0, - LivingRoomButton, + MeganBedroomButton, LivingRoomSwitch, LivingRoomOutlet, LivingRoomTable, OfficeButton, HallwaySwitch, - MasterBedroomButton + DaricBedroomButton } } diff --git a/GlobalConfiguration.cs b/GlobalConfiguration.cs index d437ac8..f3e8880 100644 --- a/GlobalConfiguration.cs +++ b/GlobalConfiguration.cs @@ -25,13 +25,13 @@ public static int GetBrightness() public static string GetZigbeeDeviceId(ZigbeeDeviceName device) => device switch { - ZigbeeDeviceName.LivingRoomButton => "00:12:4b:00:25:16:bd:64", ZigbeeDeviceName.LivingRoomSwitch => "84:fd:27:ff:fe:bc:cc:8e", ZigbeeDeviceName.LivingRoomOutlet => "00:12:4b:00:25:3d:67:7f", ZigbeeDeviceName.LivingRoomTable => "00:12:4b:00:25:3d:6a:08", ZigbeeDeviceName.OfficeButton => "00:12:4b:00:25:14:6f:60", ZigbeeDeviceName.HallwaySwitch => "84:fd:27:ff:fe:bc:cc:65", - ZigbeeDeviceName.MasterBedroomButton => "00:12:4b:00:25:16:b2:ca", + ZigbeeDeviceName.MeganBedroomButton => "00:12:4b:00:25:16:bd:64", + ZigbeeDeviceName.DaricBedroomButton => "00:12:4b:00:25:16:b2:ca", _ => "" }; diff --git a/Helpers/ZigbeeEventHelpers.cs b/Helpers/ZigbeeEventHelpers.cs index 9717ccc..9441c0c 100644 --- a/Helpers/ZigbeeEventHelpers.cs +++ b/Helpers/ZigbeeEventHelpers.cs @@ -13,6 +13,15 @@ public static IObservable> Where(this IObservable eve .Where(e => e.Data?.DeviceIeee == deviceId && e.Data?.Command == command); } + public static IObservable> Where(this IObservable eventSource, IEnumerable zigbeeDeviceNames, ZigbeeButtonCommands buttonCommand) + { + var deviceIds = zigbeeDeviceNames.Select(GlobalConfiguration.GetZigbeeDeviceId).ToHashSet(); + + var command = GlobalConfiguration.GetZigbeeCommand(buttonCommand); + return eventSource.Filter("zha_event") + .Where(e => deviceIds.Contains(e.Data?.DeviceIeee ?? "") && e.Data?.Command == command); + } + public static IObservable> Where(this IObservable eventSource, ZigbeeDeviceName zigbeeDeviceName, ZigbeeSwitchCommands switchCommands) { var deviceId = GlobalConfiguration.GetZigbeeDeviceId(zigbeeDeviceName); diff --git a/apps/BedroomAutomation.cs b/apps/BedroomAutomation.cs index e5eeea9..eec9ca2 100644 --- a/apps/BedroomAutomation.cs +++ b/apps/BedroomAutomation.cs @@ -9,7 +9,13 @@ public BedroomAutomation(IScheduler scheduler, IHaContext ha, Entities entities) { var dimmer = new Dimmer(100, 20, 2); - ha.Events.Where(ZigbeeDeviceName.MasterBedroomButton, ZigbeeButtonCommands.LongPress).Subscribe(_ => + var buttons = new List + { + ZigbeeDeviceName.DaricBedroomButton, + ZigbeeDeviceName.MeganBedroomButton + }; + + ha.Events.Where(buttons, ZigbeeButtonCommands.LongPress).Subscribe(_ => { entities.Light.BedroomFan.TurnOff(); entities.Light.BedroomLamp.TurnOff(); @@ -17,14 +23,14 @@ public BedroomAutomation(IScheduler scheduler, IHaContext ha, Entities entities) dimmer.SetStep(1); }); - ha.Events.Where(ZigbeeDeviceName.MasterBedroomButton, ZigbeeButtonCommands.Press).Subscribe(_ => + ha.Events.Where(buttons, ZigbeeButtonCommands.Press).Subscribe(_ => { var brightnessPercentage = dimmer.Next(); entities.Light.BedroomLamp.TurnOn(brightnessPct: brightnessPercentage); entities.Light.BedroomLamp2.TurnOn(brightnessPct: brightnessPercentage); }); - ha.Events.Where(ZigbeeDeviceName.MasterBedroomButton, ZigbeeButtonCommands.DoublePress).Subscribe(_ => + ha.Events.Where(buttons, ZigbeeButtonCommands.DoublePress).Subscribe(_ => { entities.Light.BedroomFan.Toggle(); });