public void SetAutomationSetting(string automationUid, string settingUid, object value) { if (automationUid == null) { throw new ArgumentNullException(nameof(automationUid)); } if (settingUid == null) { throw new ArgumentNullException(nameof(settingUid)); } var automation = GetAutomation(automationUid); automation.Settings.TryGetValue(settingUid, out var oldValue); if (Equals(oldValue, value)) { return; } automation.Settings[settingUid] = value; _storageService.Write(automation.Settings, AutomationsDirectory, automation.Uid, DefaultFilenames.Settings); _messageBusService.Publish(new WirehomeDictionary { ["type"] = "automation_registry.event.setting_changed", ["automation_uid"] = automationUid, ["setting_uid"] = settingUid, ["old_value"] = oldValue, ["new_value"] = value, ["timestamp"] = DateTimeOffset.Now.ToString("O") }); }
public void SetValue(string uid, object value) { if (uid == null) { throw new ArgumentNullException(nameof(uid)); } object oldValue; lock (_variables) { if (_variables.TryGetValue(uid, out oldValue)) { if (Equals(oldValue, value)) { return; } } _variables[uid] = value; Save(); } var busMessage = new WirehomeDictionary() .WithValue("type", "global_variables.event.value_set") .WithValue("uid", uid) .WithValue("old_value", oldValue) .WithValue("new_value", value); _logger.LogInformation("Global variable '{0}' changed to '{1}'.", uid, value); _messageBusService.Publish(busMessage); }
public void Reboot(int waitTime) { _logger.LogInformation("Reboot initiated."); _notificationsService.PublishFromResource(new PublishFromResourceParameters { Type = NotificationType.Warning, ResourceUid = NotificationResourceUids.RebootInitiated, Parameters = new Dictionary <object, object> { ["wait_time"] = 0 // TODO: Add to event args. } }); _messageBusService.Publish(new Dictionary <object, object> { ["type"] = "system.reboot_initiated" }); Task.Run(() => { Thread.Sleep(TimeSpan.FromSeconds(waitTime)); Process.Start("shutdown", " -r now"); }, CancellationToken.None); }
public void SetValue(string uid, object value) { if (uid == null) { throw new ArgumentNullException(nameof(uid)); } object oldValue; lock (_variables) { if (_variables.TryGetValue(uid, out oldValue)) { if (Equals(oldValue, value)) { return; } } _variables[uid] = value; Save(); } var busMessage = new Dictionary <object, object> { ["type"] = "global_variables.event.value_set", ["uid"] = uid, ["old_value"] = oldValue, ["new_value"] = value }; _logger.LogInformation($"Global variable '{uid}' changed to '{value}'."); _messageBusService.Publish(busMessage); }
public void PublishTagAddedEvent(string componentUid, string tag) { var message = new WirehomeDictionary { ["type"] = "component_registry.event.tag_added", ["component_uid"] = componentUid, ["tag"] = tag, ["timestamp"] = DateTime.Now.ToString("O") }; _messageBusService.Publish(message); }
public void PublishStatusChangedBusMessage(string componentUid, string statusUid, object oldValue, object newValue) { var message = new WirehomeDictionary { ["type"] = "component_registry.event.status_changed", ["component_uid"] = componentUid, ["status_uid"] = statusUid, ["old_value"] = oldValue, ["new_value"] = newValue, ["timestamp"] = DateTime.Now.ToString("O") }; _messageBusService.Publish(message); }
public void PublishSettingChangedBusMessage(string macroUid, string settingUid, object oldValue, object newValue) { var message = new WirehomeDictionary { ["type"] = "macro_registry.event.setting_changed", ["macro_uid"] = macroUid, ["setting_uid"] = settingUid, ["old_value"] = oldValue, ["new_value"] = newValue, ["timestamp"] = DateTime.Now.ToString("O") }; _messageBusService.Publish(message); }
public void PublishDisabledEvent(string componentUid) { var message = new Dictionary <object, object>(3) { ["type"] = "component_registry.event.disabled", ["component_uid"] = componentUid, ["timestamp"] = DateTime.Now.ToString("O") }; _messageBusService.Publish(message); }
public void SetComponentGroupSetting(string componentGroupUid, string settingUid, object value) { if (componentGroupUid == null) { throw new ArgumentNullException(nameof(componentGroupUid)); } if (settingUid == null) { throw new ArgumentNullException(nameof(settingUid)); } var componentGroup = GetComponentGroup(componentGroupUid); var setSettingResult = componentGroup.SetSetting(settingUid, value); if (!setSettingResult.IsNewValue) { if (Equals(setSettingResult.OldValue, value)) { return; } } _storageService.Write(componentGroup.GetSettings(), ComponentGroupsDirectory, componentGroupUid, DefaultFileNames.Settings); _logger.Log( LogLevel.Debug, "Component group '{0}' setting '{1}' changed from '{2}' to '{3}'.", componentGroupUid, settingUid, setSettingResult.OldValue ?? "<null>", value ?? "<null>"); _messageBusService.Publish(new Dictionary <object, object> { ["type"] = "component_group_registry.event.setting_changed", ["component_group_uid"] = componentGroupUid, ["setting_uid"] = settingUid, ["old_value"] = setSettingResult.OldValue, ["new_value"] = value }); }
private void DispatchGpioStateChangedEvent(string gpioHostId, int gpioId, GpioState oldState, GpioState newState) { var properties = new WirehomeDictionary { ["type"] = "gpio_registry.event.state_changed", ["gpio_host_id"] = gpioHostId, ["gpio_id"] = gpioId, ["old_state"] = oldState.ToString().ToLowerInvariant(), ["new_state"] = newState.ToString().ToLowerInvariant() }; _messageBusService.Publish(properties); }
void OnGpioStateChanged(string hostId, GpioAdapterStateChangedEventArgs e) { var properties = new Dictionary <object, object> { ["type"] = "gpio_registry.event.state_changed", ["gpio_host_id"] = hostId, ["gpio_id"] = e.GpioId, ["old_state"] = e.OldState?.ToString().ToLowerInvariant(), ["new_state"] = e.NewState.ToString().ToLowerInvariant() }; _messageBusService.Publish(properties); }
private void Publish(Notification notification) { lock (_notifications) { _notifications.Add(notification); Save(); } _messageBusService.Publish(new WirehomeDictionary() .WithType("notifications.event.published") .WithValue("notification_type", notification.Type.ToString().ToLowerInvariant()) .WithValue("message", notification.Message) .WithValue("time_to_live", notification.TimeToLive.ToString("c"))); }
public void SetComponentGroupSetting(string componentGroupUid, string settingUid, object value) { if (componentGroupUid == null) { throw new ArgumentNullException(nameof(componentGroupUid)); } if (settingUid == null) { throw new ArgumentNullException(nameof(settingUid)); } var componentGroup = GetComponentGroup(componentGroupUid); componentGroup.Settings.TryGetValue(settingUid, out var oldValue); if (Equals(oldValue, value)) { return; } componentGroup.Settings[settingUid] = value; _storageService.Write(componentGroup.Settings, ComponentGroupsDirectory, componentGroupUid, DefaultFilenames.Settings); _logger.Log( LogLevel.Debug, "Component group '{0}' setting '{1}' changed from '{2}' to '{3}'.", componentGroupUid, settingUid, oldValue ?? "<null>", value ?? "<null>"); _messageBusService.Publish(new WirehomeDictionary() .WithType("component_group_registry.event.setting_changed") .WithValue("component_group_uid", componentGroupUid) .WithValue("setting_uid", settingUid) .WithValue("old_value", oldValue) .WithValue("new_value", oldValue)); }
private void Publish(Notification notification) { lock (_notifications) { _notifications.Add(notification); Save(); } _messageBusService.Publish(new Dictionary <object, object> { ["type"] = "notifications.event.published", ["notification_type"] = notification.Type.ToString().ToLowerInvariant(), ["message"] = notification.Message, ["time_to_live"] = notification.TimeToLive.ToString("c"), }); }
public void publish(PythonDictionary message) { _messageBusService.Publish(message); }
public void PostMessage([FromBody] WirehomeDictionary messsage) { _messageBusService.Publish(messsage); }
public void PostMessage([FromBody] IDictionary <object, object> messsage) { _messageBusService.Publish(messsage); }