public void LoadSettings()
        {
            SettingsConfiguration.HomeMaticSettings = new HomeMaticSettings("192.168.0.14");
            //SettingsConfiguration.HomeMaticSettings = new HomeMaticSettings("192.168.127.16");
            var homeMaticCcu = new Ccu("My HomeMatic", SettingsConfiguration.HomeMaticSettings.Address);

            App.HomeMaticXmlApi = new HomeMaticXmlApi(homeMaticCcu);
        }
Example #2
0
        /// <summary>
        /// Format the string input as a XML-RPC Request and return the Response in string. If the operation has fault, it returns an exception message.
        /// </summary>
        /// <param name="ccu">Carrier Object</param>
        /// <param name="m_Request">Local string Request. Input format: "Sensor Action Value"</param>
        /// <param name="m_Result">Response message from server in string</param>
        /// <returns></returns>
        private async Task <string> SendandReceive(IotApi iotApi, string request)
        {
            Ccu ccu = new Ccu();

            var    methodCall = ccu.PrepareMethodCall(request);
            string response   = "";

            await iotApi.SendAsync(methodCall, (responseMessages) =>
            {
                if (MethodResponse.isMethodResponse(responseMessages))
                {
                    MethodResponse res = responseMessages as MethodResponse;

                    if (ccu.isGetList)
                    {
                        response = ccu.GetListDevices(res);
                    }
                    else
                    {
                        if (!ccu.isGetMethod)
                        {
                            // Set Methods do not return any value. Detecting no value means the operation is done
                            if (res.ReceiveParams.Count() == 0)
                            {
                                response = "Operation is done!";
                            }

                            // Set methods can not return any value
                            else
                            {
                                throw new InvalidOperationException("The operation cannot return any value!");
                            }
                        }
                        else
                        {
                            // Get methods must return a value, if not it must be an error
                            if (res.ReceiveParams.Count() == 0)
                            {
                                throw new InvalidOperationException("No value returned or error");
                            }

                            // Collecting the returned value
                            else
                            {
                                response = res.ReceiveParams.First().Value.ToString();
                            }
                        }
                    }
                }
            },
                                   (error) =>
            {
                response = error.Message;
            });

            return(response);
        }
Example #3
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            // Initialize HomeMatic API
            var ccu = new Ccu("Demo", "192.168.0.14");

            HomeMatic = new HomeMaticXmlApi(ccu);
        }
Example #4
0
        //public StateRepository(string connString)
        //{
        //    _connString = connString;
        //}

        /// <inheritdoc />
        public async Task <Data> GetState()
        {
            Monitor state = await _context.Monitor
                            .OrderByDescending(d => d.Id)
                            .FirstOrDefaultAsync();

            Ccu ccuState = await _context.CCU
                           .OrderByDescending(d => d.Id)
                           .FirstOrDefaultAsync();


            //using (IDbConnection db = new MySqlConnection(_connString))
            //{

            //}

            return(new Data
            {
                Boiler = Convert.ToInt32(state.Boiler) == 10,
                BoilerHeat = state.BoilerHeating,
                Electricity = new Electricity
                {
                    Phase1 = state.Phase1,
                    Phase2 = state.Phase2,
                    Phase3 = state.Phase3,
                    PhaseSumm = state.PhaseSumm
                },
                Energy = state.Energy.ToString(),
                Heat = new Heat
                {
                    Batteries = Convert.ToInt32(state.Heat) == 6 || Convert.ToInt32(state.Heat) == 9,
                    Floor = Convert.ToInt32(state.Heat) == 3 || Convert.ToInt32(state.Heat) == 9
                },
                Humidity = new Humidity
                {
                    Bedroom = state.HumidityBedroom,
                    LivingRoom = state.HumidityLivingRoom
                },
                Temperature = new Temperature
                {
                    Barn = state.TemperatureBarn,
                    Bedroom = state.TemperatureBedroom,
                    LivingRoom = state.TemperatureLivingRoom,
                    Outside = state.TemperatureOutside,
                    BedroomYouth = state.BedroomYouth
                },
                Timestamp = state.Timestamp?.ToString("H':'mm"),
                Date = state.Timestamp?.ToString("d'.'MM'.'yy"),
                BedroomYouth = Convert.ToInt32(ccuState.BedroomYouth) == 1,
                WarmFloorKitchen = Convert.ToInt32(ccuState.WarmFloorKitchen) == 1,
            });
        }