public FrontDoorLockSmartThingsIntegration(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
        {
            var config = _hub.Configuration.GetSection("FrontDoorLock");

            _endpoint  = new Uri(config["SmartThingsIntegrationEndpoint"]);
            _authToken = config["SmartThingsToken"];
        }
예제 #2
0
 public PantryLightAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     _pantryLight =
         _hub.GetDeviceByMappedName <SwitchRelay>("Switch.PantryLight") as SwitchRelay;
     _kitchenSpeaker =
         _hub.GetDeviceByMappedName <Speaker>("Speaker.KitchenSpeaker") as Speaker;
 }
예제 #3
0
        public static async Task Main(string[] args)
        {
            // Read the configuration file
            IConfiguration configuration = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory()) // Directory where the json files are located
                                           .AddJsonFile(APPSETTINGS_FILENAME, optional: false, reloadOnChange: true)
                                           .Build();

            // Create an HttpClient that doesn't validate the server certificate
            HttpClientHandler customHttpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); }
            };

            TelemetryConfiguration telemetryConfig = AppInsights.GetTelemetryConfiguration(configuration);

            using (HttpClient _httpClient = new HttpClient(customHttpClientHandler))
            {
                // Abstraction representing the home automation system
                _hub = new Hubitat(configuration, _httpClient, AutomationFactory.ServiceProvider);

                // Class to manage long-running tasks
                _taskManager = new AutomationTaskManager(configuration);

                // Bind a method to handle the events raised
                // by the Hubitat device
                _hub.AutomationEvent += Hub_AutomationEvent;
                var hubTask = _hub.StartAutomationEventWatcher();

                // Wait forever, this is a daemon process
                await hubTask;
            }
        }
예제 #4
0
        /// <summary>
        /// Figures out the appropriate implementation of IAutomation based on the data in the event and returns it.
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="hub"></param>
        /// <returns>An IEnumerable&lt;IAutomation&gt; containing the automations to be run for this event.</returns>
        public static IEnumerable <IAutomation> GetAutomations(HubEvent evt, HomeAutomationPlatform hub)
        {
            /*
             *  Get the types from the assembly
             *      where the type implements IAutomation and
             *          the type has trigger attributes
             *              where the trigger attribute names a mapped device that matches the device that caused the event
             *                  and the attribute also names a Capability that matches the device that caused the event
             *          and the count of the matching trigger attributes is greater than 0
             */
            IEnumerable <Type> typeCollection = Assembly.LoadFrom(_automationAssembly).GetTypes()
                                                .Where(t => typeof(IAutomation).IsAssignableFrom(t) &&
                                                       (t.GetCustomAttributes <TriggerDeviceAttribute>()
                                                        .Where(a => hub.LookupDeviceId(a.DeviceMappedName) == evt.DeviceId &&
                                                               a.Capability.ToString().ToLower() == evt.Name))
                                                       .Count() > 0);

            foreach (Type automation in typeCollection)
            {
                var thing = Activator.CreateInstance(automation, new Object[] { hub, evt });
                if (thing is IAutomation automationSource)
                {
                    yield return(automationSource);
                }
            }
        }
예제 #5
0
        public NotifyOnExteriorDoorOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
        {
            NotificationDevices =
                new List <Speaker>()
            {
                _hub.GetDeviceByMappedName <Speaker>("Speaker.WebhookNotifier") as Speaker,
                _hub.GetDeviceByMappedName <Speaker>("Speaker.KitchenSpeaker") as Speaker
            };

            HowLong = TimeSpan.FromMinutes(2);
        }
예제 #6
0
 public NotifyOnGatesOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     HowLong             = TimeSpan.Zero;
     NotifyOnClose       = true;
     NotificationDevices =
         new List <Speaker>()
     {
         _hub.GetDeviceByMappedName <Speaker>("Speaker.WebhookNotifier") as Speaker,
         _hub.GetDeviceByMappedName <Speaker>("Speaker.KitchenSpeaker") as Speaker
     };
     NotificationFormat = @"{0} is open.";
 }
예제 #7
0
        /// <summary>
        /// Figures out the appropriate implementation of IAutomation based on the data in the event and returns it.
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="hub"></param>
        /// <returns>An IEnumerable&lt;IAutomation&gt; containing the automations to be run for this event.</returns>
        public static IEnumerable <IAutomation> GetAutomations(HubEvent evt, HomeAutomationPlatform hub)
        {
            /*
             *  Get the types from the assembly
             *      where the type implements IAutomation and
             *          the type has trigger attributes
             *              where the trigger attribute names a mapped device that matches the device that caused the event
             *                  and the attribute also names a Capability that matches the device that caused the event
             *          and the count of the matching trigger attributes is greater than 0
             */


            Dictionary <string, List <Type> > assemblies = MemoryCache.GetOrCreate("Assemblies", entry =>
            {
                Dictionary <string, List <Type> > automationDictionary = new Dictionary <string, List <Type> >();

                var temp = Assembly.LoadFrom(_automationAssembly).GetTypes()
                           .Where(t => typeof(IAutomation).IsAssignableFrom(t));
                foreach (var type in temp)
                {
                    var keys = type.GetCustomAttributes <TriggerDeviceAttribute>().Select(t => $"{hub.LookupDeviceId(t.DeviceMappedName)}|{t.Capability.ToString().ToLower()}");
                    foreach (var key in keys)
                    {
                        if (automationDictionary.ContainsKey(key))
                        {
                            automationDictionary[key].Add(type);
                        }
                        else
                        {
                            automationDictionary.Add(key, new List <Type> {
                                type
                            });
                        }
                    }
                }
                return(automationDictionary);
            });

            foreach (Type automation in assemblies[$"{evt.DeviceId}|{evt.Name}"])
            {
                var thing = Activator.CreateInstance(automation, new Object[] { hub, evt });
                if (thing is IAutomation automationSource)
                {
                    yield return(automationSource);
                }
            }
        }
예제 #8
0
        public static async Task Main(string[] args)
        {
            // Read the configuration file
            IConfiguration configuration = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory()) // Directory where the json files are located
                                           .AddJsonFile(APPSETTINGS_FILENAME, optional: false, reloadOnChange: true)
                                           .Build();

            // Create an HttpClient that doesn't validate the server certificate
            HttpClientHandler customHttpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); }
            };

            TelemetryConfiguration telemetryConfig = AppInsights.GetTelemetryConfiguration(configuration);

            using (AppInsights.InitializeDependencyTracking(telemetryConfig))
                using (AppInsights.InitializePerformanceTracking(telemetryConfig))
                    using (HttpClient _httpClient = new HttpClient(customHttpClientHandler))
                    {
                        _telemetryClient = new TelemetryClient(telemetryConfig);

                        // Abstraction representing the home automation system
                        _hub = new Hubitat(configuration, _httpClient);

                        // Start the MQTT service, if applicable.
                        MqttOptions mqttOptions = configuration.GetSection("MQTT").Get <MqttOptions>();
                        if (mqttOptions?.Enabled ?? false)
                        {
                            _mqtt = new MqttService(await MqttClientFactory.GetClient(mqttOptions), mqttOptions, _hub);
                            await _mqtt.Start();
                        }

                        // Class to manage long-running tasks
                        _taskManager = new AutomationTaskManager(configuration);

                        // Bind a method to handle the events raised
                        // by the Hubitat device
                        _hub.AutomationEvent += Hub_AutomationEvent;
                        var hubTask = _hub.StartAutomationEventWatcher();

                        // Wait forever, this is a daemon process
                        await hubTask;
                    }
        }
예제 #9
0
 public GarageEntryPowerAllowance(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     HowLong = TimeSpan.FromMinutes(30);
 }
예제 #10
0
 public DoorWatcherBase(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #11
0
 public Speaker(HomeAutomationPlatform hub, string id) : base(hub, id)
 {
 }
예제 #12
0
 public DeviceBase(HomeAutomationPlatform hub, string id)
 {
     _hub = hub;
     Id   = id;
 }
예제 #13
0
 public ContactSensor(HomeAutomationPlatform hub, string id) : base(hub, id)
 {
 }
예제 #14
0
 public Weather(IServiceProvider serviceProvider, HomeAutomationPlatform hub, string id) : base(hub, id)
 {
     Data = serviceProvider.GetService <IWeatherData>();
 }
예제 #15
0
 public DimmerSwitchRelay(HomeAutomationPlatform hub, string id) : base(hub, id)
 {
 }
예제 #16
0
 public AutomationBase(HomeAutomationPlatform hub, HubEvent evt)
 {
     _hub = hub;
     _evt = evt;
 }
예제 #17
0
 public LockDevice(HomeAutomationPlatform hub)
 {
     _hub = hub;
 }
예제 #18
0
 public LockFrontDoor(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     _service = new SmartThingsLockService(_hub.Configuration);
 }
예제 #19
0
 public NotifyOnExteriorDoorOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     HowLong = TimeSpan.FromMinutes(2);
 }
예제 #20
0
 public NotifyOnGatesOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     HowLong            = TimeSpan.Zero;
     NotifyOnClose      = true;
     NotificationFormat = @"{0} is open.";
 }
예제 #21
0
 public LivingRoomRemoteControl(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #22
0
 public LivingRoomHolidayAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #23
0
 public BarLights(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #24
0
 public SampleAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #25
0
 public PowerAllowanceBase(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #26
0
 public NotifyOnMailArrival(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #27
0
 public NotifyOnFridgeDoorOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     HowLong = TimeSpan.FromMinutes(1);
     NumberOfNotifications = 2;
 }
예제 #28
0
 public PatioAndFloodlightAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
 public NotifyOnSlidingDoorAndGatesOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
 }
예제 #30
0
 public BasementStairwayPowerAllowance(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt)
 {
     HowLong = TimeSpan.FromMinutes(5);
 }