Esempio n. 1
0
        private void ProcessPowerlevelController(string name, AlexaDirective directive)
        {
            log.Info("Processing PowerlevelController request with name '{0}'", name);
            if (name == "SetPowerLevel")
            {
                string targetPowerLevelProp = directive.Payload["powerLevel"].ToString();
                bool   valueParseable       = Int32.TryParse(targetPowerLevelProp, out int targetPowerLevel);


                this.loxoneDispatcher.Tell(new LoxoneMessage.ControlDimmer(AlexaUuidTranslator.ToLoxoneUuid(directive.Endpoint.EndpointId), LoxoneMessage.ControlDimmer.DimType.Set, targetPowerLevel));

                var response = CreateResponse(directive.Header.CorrelationId, directive.Endpoint.EndpointId);
                response.Context.Properties.Add(new AlexaProperty("Alexa.PowerLevelController", "powerLevel", targetPowerLevelProp, DateTime.Now));
                SendResponseToAlexa(response);
            }
            else if (name == "AdjustPowerLevel")
            {
                // TODO
                SendResponseToAlexa(CreateError(directive.Endpoint.EndpointId, AlexaErrorType.INVALID_DIRECTIVE, "Adapter does not support adjusting power level"));
            }
            else
            {
                SendResponseToAlexa(CreateError(directive.Endpoint.EndpointId, AlexaErrorType.INVALID_DIRECTIVE, $"PowerLevelAdapter does not support '{name}'"));
            }
        }
Esempio n. 2
0
        private void ProcessPowerController(string name, AlexaDirective directive)
        {
            log.Info("Processing PowerController request with name '{0}'", name);
            string targetValue = "";

            if (name == "TurnOn")
            {
                this.loxoneDispatcher.Tell(new LoxoneMessage.ControlSwitch(AlexaUuidTranslator.ToLoxoneUuid(directive.Endpoint.EndpointId), LoxoneMessage.ControlSwitch.DesiredStateType.On));
                targetValue = "ON";
            }
            else if (name == "TurnOff")
            {
                this.loxoneDispatcher.Tell(new LoxoneMessage.ControlSwitch(AlexaUuidTranslator.ToLoxoneUuid(directive.Endpoint.EndpointId), LoxoneMessage.ControlSwitch.DesiredStateType.Off));
                targetValue = "OFF";
            }
            else
            {
                string message = $"Unknown control request '{name}'";
                log.Error(message);
            }
            var response = CreateResponse(directive.Header.CorrelationId, directive.Endpoint.EndpointId);

            response.Context.Properties.Add(new AlexaProperty("Alexa.PowerController", "powerState", targetValue, DateTime.Now));
            SendResponseToAlexa(response);
        }
Esempio n. 3
0
        private AlexaEndpoint ParseControlToEndpoint(Control c)
        {
            string uuid = AlexaUuidTranslator.ToAlexaId(c.LoxoneUuid);

            if (c.Type == ControlType.LightControl)
            {
                AlexaEndpoint ep = new AlexaEndpoint()
                {
                    EndpointId           = uuid,
                    ManufacturerName     = "Loxone / Aloxi by ZoolWay",
                    Description          = $"Lichtschalter via Loxone in {c.RoomName}",
                    FriendlyName         = c.FriendlyName,
                    AdditionalAttributes = GenerateBasicAdditionalAttributes(c),
                    DisplayCategories    = new[] { "LIGHT" },
                    Capabilities         = new AlexaEndpointCapability[] { new PowerControllerCapability(), new GenericAlexaCapability() },
                };
                AddOperationsToAdditionalAttributes(c.Operations, ep.AdditionalAttributes);
                return(ep);
            }
            else if (c.Type == ControlType.LightDimmableControl)
            {
                AlexaEndpoint ep = new AlexaEndpoint()
                {
                    EndpointId           = uuid,
                    ManufacturerName     = "Loxone / Aloxi by ZoolWay",
                    Description          = $"Dimmer via Loxone in {c.RoomName}",
                    FriendlyName         = c.FriendlyName,
                    AdditionalAttributes = GenerateBasicAdditionalAttributes(c),
                    DisplayCategories    = new[] { "LIGHT" },
                    Capabilities         = new AlexaEndpointCapability[] { new PowerLevelControllerCapability(), new PowerControllerCapability(), new GenericAlexaCapability() },
                };
                AddOperationsToAdditionalAttributes(c.Operations, ep.AdditionalAttributes);
                return(ep);
            }
            else if (c.Type == ControlType.BlindControl)
            {
                AlexaEndpoint ep = new AlexaEndpoint()
                {
                    EndpointId           = uuid,
                    ManufacturerName     = "Loxone / Aloxi by ZoolWay",
                    Description          = $"Jalousie via Loxone in {c.RoomName}",
                    FriendlyName         = c.FriendlyName,
                    AdditionalAttributes = GenerateBasicAdditionalAttributes(c),
                    DisplayCategories    = new[] { "INTERIOR_BLIND" },
                    Capabilities         = new AlexaEndpointCapability[] { new ModeControllerCapabilityForBlinds(), new GenericAlexaCapability() },
                };
                AddOperationsToAdditionalAttributes(c.Operations, ep.AdditionalAttributes);
                return(ep);
            }
            return(null);
        }
Esempio n. 4
0
        private void ProcessModeController(AlexaDirective directive)
        {
            string name       = directive.Header.Name;
            string instance   = directive.Header.Instance;
            string targetMode = directive.Payload["mode"]?.ToString();

            log.Info("Processing MopdeController request with name '{0}' for instance '{1}' targetting '{2}'", name, instance, targetMode);

            if (instance == "Blinds.BlindTargetState")
            {
                if (name == "SetMode")
                {
                    LoxoneMessage.ControlBlinds.BlindCmd command = LoxoneMessage.ControlBlinds.BlindCmd.FullUp;
                    switch (targetMode)
                    {
                    case "BlindTargetState.FullUp":
                        command = LoxoneMessage.ControlBlinds.BlindCmd.FullUp;
                        break;

                    case "BlindTargetState.FullDown":
                        command = LoxoneMessage.ControlBlinds.BlindCmd.FullDown;
                        break;

                    case "BlindTargetState.Stop":
                        command = LoxoneMessage.ControlBlinds.BlindCmd.Stop;
                        break;
                    }
                    this.loxoneDispatcher.Tell(new LoxoneMessage.ControlBlinds(AlexaUuidTranslator.ToLoxoneUuid(directive.Endpoint.EndpointId), command));
                    var response = CreateResponse(directive.Header.CorrelationId, directive.Endpoint.EndpointId);
                    response.Context.Properties.Add(new AlexaProperty("Alexa.ModeController", "mode", targetMode, DateTime.Now));
                    SendResponseToAlexa(response);
                    return;
                }
            }

            SendResponseToAlexa(CreateError(directive.Endpoint.EndpointId, AlexaErrorType.INVALID_DIRECTIVE, $"Directive {name} for instance {instance} is not implemented!"));
        }