Ejemplo n.º 1
0
        protected override CustomListObjectElementCollection GetItemsOverride(CustomListData data)
        {
            var items = new CustomListObjectElementCollection();
            var fh    = new FritzHelper();

            data.Properties.TryGetValue("Hostname", StringComparison.OrdinalIgnoreCase, out var Hostname);
            data.Properties.TryGetValue("User", StringComparison.OrdinalIgnoreCase, out var User);
            data.Properties.TryGetValue("Password", StringComparison.OrdinalIgnoreCase, out var Password);

            var thermostats = fh.GetThermostats(Hostname, User, Password);

            foreach (var thermostat in thermostats)
            {
                items.Add(new CustomListObjectElement {
                    { "Id", thermostat.Id },
                    { "Name", thermostat.Name },
                    { "Present", thermostat.Present },
                    { "Battery", thermostat.Battery },
                    { "TempCurrent", thermostat.TempCurrent },
                    { "TempTarget", thermostat.TempTarget }
                });
            }

            return(items);
        }
Ejemplo n.º 2
0
        protected override CustomListExecuteReturnContext ExecuteFunctionOverride(CustomListData data, CustomListExecuteParameterContext context)
        {
            data.Properties.TryGetValue("Hostname", StringComparison.OrdinalIgnoreCase, out var Hostname);
            data.Properties.TryGetValue("User", StringComparison.OrdinalIgnoreCase, out var User);
            data.Properties.TryGetValue("Password", StringComparison.OrdinalIgnoreCase, out var Password);

            Log?.Info(string.Format("The function {0} has been called with {1} parameters", context.FunctionName, context.Values.Count));
            var returnContext = default(CustomListExecuteReturnContext);
            var fh            = new FritzHelper();
            var thermostat    = fh.GetThermostats(Hostname, User, Password).First(t => t.Name.Equals(context.Values[0].StringValue));

            if (context.FunctionName.Equals("settemperature"))
            {
                fh.SetThermostatTemperature(Hostname, User, Password, thermostat, double.Parse(context.Values[1].StringValue, CultureInfo.InvariantCulture));
            }

            return(returnContext);
        }