public string serialize_indented(object value)
        {
            var json = PythonConvert.FromPythonToJson(value);

            return(json.ToString(Formatting.Indented));
        }
예제 #2
0
 public void set_status(string component_uid, string status_uid, object value)
 {
     _componentRegistryService.SetComponentStatusValue(component_uid, status_uid, PythonConvert.FromPython(value));
 }
예제 #3
0
 public void set_setting(string component_uid, string setting_uid, object value)
 {
     _componentRegistryService.SetComponentSetting(component_uid, setting_uid, PythonConvert.FromPython(value));
 }
 public object get_setting(string setting_uid, object default_value = null)
 {
     return(PythonConvert.ToPython(_automationRegistryService.GetAutomationSetting(_automationUid, setting_uid, default_value)));
 }
예제 #5
0
 public List ulong_to_list(ulong buffer, int length)
 {
     return(PythonConvert.ToPythonList(ULongToArray(buffer, length)));
 }
예제 #6
0
 public object get_setting(string setting_uid, object default_value = null)
 {
     return(PythonConvert.ToPython(_componentRegistryService.GetComponentSetting(_componentUid, setting_uid, default_value)));
 }
예제 #7
0
 public object get_configuration(string configuration_uid, object default_value = null)
 {
     return(PythonConvert.ToPython(_componentRegistryService.GetComponentConfiguration(_componentUid, configuration_uid, default_value)));
 }
 public PythonDictionary ConvertToPythonDictionary()
 {
     return(PythonConvert.ToPythonDictionary(this));
 }
 public WirehomeDictionary ConvertToWirehomeDictionary()
 {
     return(PythonConvert.ToPythonDictionary(this));
 }
예제 #10
0
        public List get_ssdp_devices()
        {
            var devices = _discoveryService.GetDiscoveredDevices().Select(ToPythonDictionary);

            return(PythonConvert.ToPythonList(devices));
        }
예제 #11
0
 public string register_route(string uid, string uri_template, RequestHandler handler)
 {
     return(_httpServerService.RegisterRoute(uid, uri_template, request => handler(PythonConvert.ToPythonDictionary(request))));
 }
예제 #12
0
 public string subscribe(string uid, PythonDictionary filter, MessageCallback callback)
 {
     return(_messageBusService.Subscribe(uid, filter, m => { callback(PythonConvert.ToPythonDictionary(m)); }));
 }
예제 #13
0
        public void register_panel([PythonDictionaryDefinition(typeof(AppPanelDefinition))] PythonDictionary panel_definition)
        {
            var definition = PythonConvert.CreateModel <AppPanelDefinition>(panel_definition);

            _appService.RegisterPanel(definition);
        }
예제 #14
0
        public static PythonDictionary publish_external(PythonDictionary parameters)
        {
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var server   = Convert.ToString(parameters.get("server"));
            var port     = Convert.ToInt32(parameters.get("port", 1883));
            var username = Convert.ToString(parameters.get("username"));
            var password = Convert.ToString(parameters.get("password"));
            var clientId = Convert.ToString(parameters.get("client_id", Guid.NewGuid().ToString("N")));
            var topic    = Convert.ToString(parameters.get("topic"));
            var qos      = Convert.ToInt32(parameters.get("qos", 0));
            var retain   = Convert.ToBoolean(parameters.get("retain", false));
            var tls      = Convert.ToBoolean(parameters.get("tls", false));
            var timeout  = Convert.ToInt32(parameters.get("timeout", 5000));
            var payload  = parameters.get("payload", null);

            var mqttClient = new MqttFactory().CreateMqttClient();

            try
            {
                var options = new MqttClientOptionsBuilder()
                              .WithTcpServer(server, port)
                              .WithCredentials(username, password)
                              .WithClientId(clientId)
                              .WithCommunicationTimeout(TimeSpan.FromMilliseconds(timeout))
                              .WithTls(new MqttClientOptionsBuilderTlsParameters
                {
                    UseTls = tls
                })
                              .Build();

                mqttClient.ConnectAsync(options).GetAwaiter().GetResult();

                var message = new MqttApplicationMessageBuilder()
                              .WithTopic(topic)
                              .WithPayload(ConvertPayload(payload))
                              .WithQualityOfServiceLevel((MqttQualityOfServiceLevel)qos)
                              .WithRetainFlag(retain)
                              .Build();

                mqttClient.PublishAsync(message).GetAwaiter().GetResult();

                return(new PythonDictionary
                {
                    ["type"] = "success"
                });
            }
            catch (MqttConnectingFailedException)
            {
                return(new PythonDictionary
                {
                    ["type"] = "exception.connecting_failed"
                });
            }
            catch (Exception exception)
            {
                return(PythonConvert.ToPythonDictionary(new ExceptionPythonModel(exception).ToDictionary()));
            }
            finally
            {
                mqttClient?.DisconnectAsync().GetAwaiter().GetResult();
                mqttClient?.Dispose();
            }
        }
 public object invoke(string service_id, string function_name, params object[] parameters)
 {
     return(PythonConvert.ToPython(_serviceHostService.InvokeFunction(service_id, function_name, parameters)));
 }
예제 #16
0
        //public void publish_response(PythonDictionary request, PythonDictionary response)
        //{
        //    _messageBusService.PublishResponse(request, response);
        //}

        public string subscribe(string uid, PythonDictionary filter, Action <PythonDictionary> callback)
        {
            return(_messageBusService.Subscribe(uid, filter, m => callback(PythonConvert.ToPythonDictionary(m.Message))));
        }
 public object get_status(string component_uid, string status_uid, object default_value = null)
 {
     return(PythonConvert.ToPython(_componentRegistryService.GetComponentStatus(component_uid, status_uid, default_value)));
 }
예제 #18
0
 public IDictionary <object, object> ProcessMessage(IDictionary <object, object> message)
 {
     ThrowIfLogicNotSet();
     return(_logic.ProcessMessage(PythonConvert.ToPythonDictionary(message)));
 }
예제 #19
0
 public void register_setting(string settingUid, object value)
 {
     _componentRegistryService.RegisterComponentSetting(_componentUid, settingUid, PythonConvert.FromPython(value));
 }
예제 #20
0
 public IDictionary <object, object> GetDebugInformation(IDictionary <object, object> parameters)
 {
     ThrowIfLogicNotSet();
     return(_logic.GetDebugInformation(PythonConvert.ToPythonDictionary(parameters)));
 }
예제 #21
0
 public void set_configuration(string configuration_uid, object value)
 {
     _componentRegistryService.SetComponentConfiguration(_componentUid, configuration_uid, PythonConvert.FromPython(value));
 }
예제 #22
0
 public string start_thread(string uid, Action <PythonDictionary> callback, object state = null)
 {
     return(_schedulerService.StartThread(uid, p => callback(PythonConvert.ToPythonDictionary(p)), state));
 }
 public void set_setting(string settingUid, object value)
 {
     _automationRegistryService.SetAutomationSetting(_automationUid, settingUid, PythonConvert.FromPython(value));
 }
예제 #24
0
 public string start_timer(string uid, int interval, Action <PythonDictionary> callback, object state = null)
 {
     return(_schedulerService.StartTimer(uid, TimeSpan.FromMilliseconds(interval), p => callback(PythonConvert.ToPythonDictionary(p)), state));
 }
예제 #25
0
        public PythonDictionary send(PythonDictionary parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            try
            {
                using (var httpClient = new HttpClient())
                    using (var request = CreateRequest(parameters))
                    {
                        var response = httpClient.SendAsync(request).GetAwaiter().GetResult();
                        var content  = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();

                        var result = new PythonDictionary
                        {
                            ["type"]        = ControlType.Success,
                            ["status_code"] = (int)response.StatusCode
                        };

                        var responseContentType = Convert.ToString(parameters.get("response_content_type", "text"));
                        if (responseContentType == "raw")
                        {
                            var rawContent = new List();
                            foreach (var contentByte in content)
                            {
                                rawContent.Add(contentByte);
                            }

                            result["content"] = rawContent;
                        }
                        else if (responseContentType == "text")
                        {
                            result["content"] = Encoding.UTF8.GetString(content);
                        }
                        else if (responseContentType == "json")
                        {
                            var jsonString = Encoding.UTF8.GetString(content);
                            if (!string.IsNullOrEmpty(jsonString))
                            {
                                try
                                {
                                    var json = JObject.Parse(jsonString);

                                    var convertedJson = PythonConvert.ToPython(json);
                                    result["content"] = convertedJson;
                                }
                                catch (Exception exception)
                                {
                                    return(new ExceptionPythonModel(exception).ConvertToPythonDictionary());
                                }
                            }
                        }

                        return(result);
                    }
            }
            catch (Exception exception)
            {
                return(new ExceptionPythonModel(exception).ConvertToPythonDictionary());
            }
        }
예제 #26
0
 public string attach_to_default_timer(string uid, Action <PythonDictionary> callback, object state = null)
 {
     return(_schedulerService.AttachToDefaultTimer(uid, p => callback(PythonConvert.ToPythonDictionary(p)), state));
 }
예제 #27
0
 public object get_setting(string component_uid, string setting_uid, [DefaultParameterValue(null)] object default_value)
 {
     return(PythonConvert.ToPython(_componentRegistryService.GetComponentSetting(component_uid, setting_uid, default_value)));
 }
예제 #28
0
 public string start_countdown(string uid, long duration, Action <PythonDictionary> callback, object state = null)
 {
     return(_schedulerService.StartCountdown(uid, TimeSpan.FromMilliseconds(duration), p => callback(PythonConvert.ToPythonDictionary(p)), state));
 }
예제 #29
0
 public object ConvertToPython()
 {
     return(PythonConvert.ToPythonDictionary(this));
 }
 public IDictionary <object, object> GetDebugInformation(string uid, [FromBody] IDictionary <object, object> parameters)
 {
     return(_componentRegistryService.GetComponent(uid).GetDebugInformation(PythonConvert.ToPythonDictionary(parameters)));
 }