public TelegramBotService( ISettingsService settingsService, IPersonalAgentService personalAgentService, ISystemInformationService systemInformationService, ILogService logService, IScriptingService scriptingService) { if (settingsService == null) { throw new ArgumentNullException(nameof(settingsService)); } if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _personalAgentService = personalAgentService ?? throw new ArgumentNullException(nameof(personalAgentService)); _log = logService.CreatePublisher(nameof(TelegramBotService)); settingsService.CreateSettingsMonitor <TelegramBotServiceSettings>(s => Settings = s.NewSettings); systemInformationService.Set("TelegramBotService/IsConnected", () => _isConnected); scriptingService.RegisterScriptProxy(s => new TelegramBotScriptProxy(this)); }
public AreaRegistryService( IComponentRegistryService componentService, IAutomationRegistryService automationService, ISystemInformationService systemInformationService, IApiDispatcherService apiService, ISettingsService settingsService, IScriptingService scriptingService) { if (systemInformationService == null) { throw new ArgumentNullException(nameof(systemInformationService)); } if (apiService == null) { throw new ArgumentNullException(nameof(apiService)); } if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _componentService = componentService ?? throw new ArgumentNullException(nameof(componentService)); _automationService = automationService ?? throw new ArgumentNullException(nameof(automationService)); _settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService)); apiService.ConfigurationRequested += HandleApiConfigurationRequest; systemInformationService.Set("Areas/Count", () => _areas.Count); scriptingService.RegisterScriptProxy(s => new AreaRegistryScriptProxy(this)); }
public ComponentRegistryService( ISystemInformationService systemInformationService, IApiDispatcherService apiService, ISettingsService settingsService, IScriptingService scriptingService, ILogService logService) { if (systemInformationService == null) { throw new ArgumentNullException(nameof(systemInformationService)); } if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _log = logService.CreatePublisher(nameof(ComponentRegistryService)); _apiService = apiService ?? throw new ArgumentNullException(nameof(apiService)); _settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService)); apiService.StatusRequested += HandleApiStatusRequest; systemInformationService.Set("Components/Count", () => _components.Count); scriptingService.RegisterScriptProxy(s => new ComponentRegistryScriptProxy(this, s)); }
public SystemInformationService(IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } scriptingService.RegisterScriptProxy(s => new SystemInformationScriptProxy(this)); }
public DateTimeService(IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } scriptingService.RegisterScriptProxy(s => new DateTimeScriptProxy(this)); }
public MessageBrokerService(ILogService logService, IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _log = logService?.CreatePublisher(nameof(MessageBrokerService)) ?? throw new ArgumentNullException(nameof(logService)); scriptingService.RegisterScriptProxy(s => new MessageBrokerScriptProxy(this, s)); }
public I2CBusService(ILogService logService, IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _log = logService?.CreatePublisher(nameof(I2CBusService)) ?? throw new ArgumentNullException(nameof(logService)); _busId = GetBusId(); scriptingService.RegisterScriptProxy(s => new I2CBusScriptProxy(this)); }
public SchedulerService(IDateTimeService dateTimeService, ILogService logService, IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _dateTimeService = dateTimeService ?? throw new ArgumentNullException(nameof(dateTimeService)); _log = logService?.CreatePublisher(nameof(SchedulerService)) ?? throw new ArgumentNullException(nameof(logService)); scriptingService.RegisterScriptProxy(s => new SchedulerScriptProxy(this, s)); ThreadPoolTimer.CreatePeriodicTimer(ExecuteSchedules, TimeSpan.FromMilliseconds(250)); }
public DaylightService(IDateTimeService dateTimeService, IApiDispatcherService apiService, IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _dateTimeService = dateTimeService ?? throw new ArgumentNullException(nameof(dateTimeService)); apiService.StatusRequested += (s, e) => { e.ApiContext.Result.Merge(JObject.FromObject(this)); }; scriptingService.RegisterScriptProxy(s => new DaylightScriptProxy(this, dateTimeService)); }
public TwitterClientService(ISettingsService settingsService, ILogService logService, IScriptingService scriptingService) { if (settingsService == null) { throw new ArgumentNullException(nameof(settingsService)); } if (logService == null) { throw new ArgumentNullException(nameof(logService)); } if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } settingsService.CreateSettingsMonitor <TwitterClientServiceSettings>(s => Settings = s.NewSettings); _log = logService.CreatePublisher(nameof(TwitterClientService)); scriptingService.RegisterScriptProxy(s => new TwitterClientScriptProxy(this)); }
public DeviceMessageBrokerService(ILogService logService, IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _log = logService?.CreatePublisher(nameof(DeviceMessageBrokerService)) ?? throw new ArgumentNullException(nameof(logService)); MqttTrace.TraceMessagePublished += (s, e) => { if (e.Level == MqttTraceLevel.Warning) { _log.Warning(e.Exception, e.Message); } else if (e.Level == MqttTraceLevel.Error) { _log.Error(e.Exception, e.Message); } }; var channelA = new MqttCommunicationAdapter(); _clientCommunicationAdapter = new MqttCommunicationAdapter(); channelA.Partner = _clientCommunicationAdapter; _clientCommunicationAdapter.Partner = channelA; var mqttClientOptions = new MqttClientOptions { ClientId = "HA4IoT.Loopback", KeepAlivePeriod = TimeSpan.FromHours(1) }; _client = new MqttClient(mqttClientOptions, channelA); _client.ApplicationMessageReceived += ProcessIncomingMessage; var mqttServerOptions = new MqttServerOptions(); _server = new MqttServerFactory().CreateMqttServer(mqttServerOptions); _server.ClientConnected += (s, e) => _log.Info($"MQTT client '{e.Identifier}' connected."); scriptingService.RegisterScriptProxy(s => new DeviceMessageBrokerScriptProxy(this, s)); }
public NotificationService( IDateTimeService dateTimeService, IApiDispatcherService apiService, ISchedulerService schedulerService, ISettingsService settingsService, IStorageService storageService, IResourceService resourceService, IScriptingService scriptingService, ILogService logService) { if (apiService == null) { throw new ArgumentNullException(nameof(apiService)); } if (schedulerService == null) { throw new ArgumentNullException(nameof(schedulerService)); } if (settingsService == null) { throw new ArgumentNullException(nameof(settingsService)); } if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _dateTimeService = dateTimeService ?? throw new ArgumentNullException(nameof(dateTimeService)); _storageService = storageService ?? throw new ArgumentNullException(nameof(storageService)); _resourceService = resourceService ?? throw new ArgumentNullException(nameof(resourceService)); _log = logService.CreatePublisher(nameof(NotificationService)); settingsService.CreateSettingsMonitor <NotificationServiceSettings>(s => Settings = s.NewSettings); apiService.StatusRequested += HandleApiStatusRequest; schedulerService.Register("NotificationCleanup", TimeSpan.FromMinutes(15), () => Cleanup()); scriptingService.RegisterScriptProxy(s => new NotificationScriptProxy(this)); }
public DeviceMessageBrokerService(ILogService logService, IScriptingService scriptingService) { if (scriptingService == null) { throw new ArgumentNullException(nameof(scriptingService)); } _log = logService?.CreatePublisher(nameof(DeviceMessageBrokerService)) ?? throw new ArgumentNullException(nameof(logService)); MqttNetGlobalLogger.LogMessagePublished += (s, e) => { if (e.TraceMessage.Level == MqttNetLogLevel.Warning) { _log.Warning(e.TraceMessage.Exception, e.TraceMessage.ToString()); } else if (e.TraceMessage.Level == MqttNetLogLevel.Error) { _log.Error(e.TraceMessage.Exception, e.TraceMessage.ToString()); } else if (e.TraceMessage.Level == MqttNetLogLevel.Info) { _log.Info(e.TraceMessage.ToString()); } else if (e.TraceMessage.Level == MqttNetLogLevel.Verbose) { _log.Verbose(e.TraceMessage.ToString()); } }; _server = new MqttFactory().CreateMqttServer(); _server.ApplicationMessageReceived += ProcessIncomingMessage; _server.ClientConnected += (s, e) => _log.Info($"MQTT client '{e.Client.ClientId}' connected."); _server.ClientDisconnected += (s, e) => _log.Info($"MQTT client '{e.Client.ClientId}' connected."); _server.ClientSubscribedTopic += (s, e) => _log.Info($"MQTT client '{e.ClientId}' subscribed topic '{e.TopicFilter}'."); _server.ClientUnsubscribedTopic += (s, e) => _log.Info($"MQTT client '{e.ClientId}' unsubscribed topic '{e.TopicFilter}'."); scriptingService.RegisterScriptProxy(s => new DeviceMessageBrokerScriptProxy(this, s)); }