コード例 #1
0
        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")
            });
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
    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);
    }
コード例 #9
0
        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
            });
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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")));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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"),
            });
        }
コード例 #15
0
 public void publish(PythonDictionary message)
 {
     _messageBusService.Publish(message);
 }
コード例 #16
0
 public void PostMessage([FromBody] WirehomeDictionary messsage)
 {
     _messageBusService.Publish(messsage);
 }
コード例 #17
0
 public void PostMessage([FromBody] IDictionary <object, object> messsage)
 {
     _messageBusService.Publish(messsage);
 }