protected override CustomListExecuteReturnContext ExecuteFunctionOverride(CustomListData data, CustomListExecuteParameterContext context)
        {
            var bridgeIP = data.Parameter.Split(';')[0];
            var userName = data.Parameter.Split(';')[1];

            this.Log?.Info(string.Format("The function {0} has been called with {1} parameters", context.FunctionName, context.Values.Count));
            var returnContext = default(CustomListExecuteReturnContext);

            if (context.FunctionName.Equals("switchlighton", StringComparison.InvariantCultureIgnoreCase))
            {
                string lightname = context.Values[0].StringValue;
                this.Log?.Info(string.Format("Lightname: {0} -> switchlighton", lightname));
                HueHelper.SwitchLight(bridgeIP, userName, lightname, true);
            }
            else if (context.FunctionName.Equals("switchlightoff", StringComparison.InvariantCultureIgnoreCase))
            {
                string lightname = context.Values[0].StringValue;
                this.Log?.Info(string.Format("Lightname: {0} -> switchlightoff", lightname));
                HueHelper.SwitchLight(bridgeIP, userName, lightname, false);
            }
            else if (context.FunctionName.Equals("setlightbrightness", StringComparison.InvariantCultureIgnoreCase))
            {
                string lightname  = context.Values[0].StringValue;
                int    brightness = Convert.ToInt32(context.Values[1].GetValue());
                this.Log?.Info(string.Format("Lightname: {0} -> setlightbrightness -> {1}", lightname, brightness));
                HueHelper.SetLightBrightness(bridgeIP, userName, lightname, brightness);
            }
            else if (context.FunctionName.Equals("setlightcolor", StringComparison.InvariantCultureIgnoreCase))
            {
                string lightname = context.Values[0].StringValue;
                int    color     = Convert.ToInt32(context.Values[1].GetValue());
                this.Log?.Info(string.Format("Lightname: {0} -> setlightcolor -> {1}", lightname, color));
                HueHelper.SetLightColor(bridgeIP, userName, lightname, color);
            }
            else if (context.FunctionName.Equals("alert", StringComparison.InvariantCultureIgnoreCase))
            {
                string lightname = context.Values[0].StringValue;
                this.Log?.Info(string.Format("Lightname: {0} -> alert", lightname));
                HueHelper.Alert(bridgeIP, userName, lightname);
            }
            else
            {
                throw new DataErrorException("Function is not supported in this version.");
            }

            return(returnContext);
        }
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);
        }
Ejemplo n.º 3
0
        protected override CustomListExecuteReturnContext ExecuteFunctionOverride(CustomListData data, CustomListExecuteParameterContext context)
        {
            var returnContext = default(CustomListExecuteReturnContext);

            if (context.FunctionName.Equals("switchstate", StringComparison.InvariantCultureIgnoreCase))
            {
                string macID       = context.Values[0].StringValue;
                string channelName = context.Values[1].StringValue;
                string action      = context.Values[2].StringValue;

                this.Log?.Info(string.Format("nameofchannel: {0} -> switchlighton", channelName));

                StartCommand(channelName, action, macID);
            }
            else
            {
                throw new DataErrorException("Function is not supported in this version.");
            }

            return(returnContext);
        }