Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 private void BuildResponseAndCache()
 {
     this.cache = null;
     if (this.homeModel == null)
     {
         return;
     }
     try
     {
         List <AlexaEndpoint> endpoints = new List <AlexaEndpoint>();
         foreach (var c in this.homeModel.Controls)
         {
             AlexaEndpoint ep = ParseControlToEndpoint(c);
             if (ep != null)
             {
                 endpoints.Add(ep);
             }
         }
         this.cache = new AlexaDiscoverResponsePayload()
         {
             Endpoints = endpoints.ToArray()
         };
         LogLevel cacheinfoLogLevel = LogLevel.DebugLevel;
         if (this.lastDayCacheinfoLogged != DateTime.Today)
         {
             cacheinfoLogLevel           = LogLevel.InfoLevel;
             this.lastDayCacheinfoLogged = DateTime.Today;
         }
         log.Log(cacheinfoLogLevel, "Caching Alexa Discovery Response with {0} endpoints", this.cache.Endpoints.Length);
     }
     catch (Exception ex)
     {
         string errMsg = $"Failed to build discovery response: {ex.Message}";
         log.Error(ex, errMsg);
     }
 }