public string serialize_indented(object value) { var json = PythonConvert.FromPythonToJson(value); return(json.ToString(Formatting.Indented)); }
public void set_status(string component_uid, string status_uid, object value) { _componentRegistryService.SetComponentStatusValue(component_uid, status_uid, PythonConvert.FromPython(value)); }
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))); }
public List ulong_to_list(ulong buffer, int length) { return(PythonConvert.ToPythonList(ULongToArray(buffer, length))); }
public object get_setting(string setting_uid, object default_value = null) { return(PythonConvert.ToPython(_componentRegistryService.GetComponentSetting(_componentUid, setting_uid, default_value))); }
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)); }
public List get_ssdp_devices() { var devices = _discoveryService.GetDiscoveredDevices().Select(ToPythonDictionary); return(PythonConvert.ToPythonList(devices)); }
public string register_route(string uid, string uri_template, RequestHandler handler) { return(_httpServerService.RegisterRoute(uid, uri_template, request => handler(PythonConvert.ToPythonDictionary(request)))); }
public string subscribe(string uid, PythonDictionary filter, MessageCallback callback) { return(_messageBusService.Subscribe(uid, filter, m => { callback(PythonConvert.ToPythonDictionary(m)); })); }
public void register_panel([PythonDictionaryDefinition(typeof(AppPanelDefinition))] PythonDictionary panel_definition) { var definition = PythonConvert.CreateModel <AppPanelDefinition>(panel_definition); _appService.RegisterPanel(definition); }
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))); }
//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))); }
public IDictionary <object, object> ProcessMessage(IDictionary <object, object> message) { ThrowIfLogicNotSet(); return(_logic.ProcessMessage(PythonConvert.ToPythonDictionary(message))); }
public void register_setting(string settingUid, object value) { _componentRegistryService.RegisterComponentSetting(_componentUid, settingUid, PythonConvert.FromPython(value)); }
public IDictionary <object, object> GetDebugInformation(IDictionary <object, object> parameters) { ThrowIfLogicNotSet(); return(_logic.GetDebugInformation(PythonConvert.ToPythonDictionary(parameters))); }
public void set_configuration(string configuration_uid, object value) { _componentRegistryService.SetComponentConfiguration(_componentUid, configuration_uid, PythonConvert.FromPython(value)); }
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)); }
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)); }
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()); } }
public string attach_to_default_timer(string uid, Action <PythonDictionary> callback, object state = null) { return(_schedulerService.AttachToDefaultTimer(uid, p => callback(PythonConvert.ToPythonDictionary(p)), state)); }
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))); }
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)); }
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))); }