public FrontDoorLockSmartThingsIntegration(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { var config = _hub.Configuration.GetSection("FrontDoorLock"); _endpoint = new Uri(config["SmartThingsIntegrationEndpoint"]); _authToken = config["SmartThingsToken"]; }
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; }
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; } }
/// <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<IAutomation> 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); } } }
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); }
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."; }
/// <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<IAutomation> 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); } } }
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; } }
public GarageEntryPowerAllowance(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { HowLong = TimeSpan.FromMinutes(30); }
public DoorWatcherBase(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public Speaker(HomeAutomationPlatform hub, string id) : base(hub, id) { }
public DeviceBase(HomeAutomationPlatform hub, string id) { _hub = hub; Id = id; }
public ContactSensor(HomeAutomationPlatform hub, string id) : base(hub, id) { }
public Weather(IServiceProvider serviceProvider, HomeAutomationPlatform hub, string id) : base(hub, id) { Data = serviceProvider.GetService <IWeatherData>(); }
public DimmerSwitchRelay(HomeAutomationPlatform hub, string id) : base(hub, id) { }
public AutomationBase(HomeAutomationPlatform hub, HubEvent evt) { _hub = hub; _evt = evt; }
public LockDevice(HomeAutomationPlatform hub) { _hub = hub; }
public LockFrontDoor(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { _service = new SmartThingsLockService(_hub.Configuration); }
public NotifyOnExteriorDoorOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { HowLong = TimeSpan.FromMinutes(2); }
public NotifyOnGatesOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { HowLong = TimeSpan.Zero; NotifyOnClose = true; NotificationFormat = @"{0} is open."; }
public LivingRoomRemoteControl(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public LivingRoomHolidayAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public BarLights(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public SampleAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public PowerAllowanceBase(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public NotifyOnMailArrival(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public NotifyOnFridgeDoorOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { HowLong = TimeSpan.FromMinutes(1); NumberOfNotifications = 2; }
public PatioAndFloodlightAutomation(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public NotifyOnSlidingDoorAndGatesOpen(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { }
public BasementStairwayPowerAllowance(HomeAutomationPlatform hub, HubEvent evt) : base(hub, evt) { HowLong = TimeSpan.FromMinutes(5); }