Exemple #1
0
        /**
         * Read an attribute
         *
         * @param attribute the {@link ZclAttribute} to read
         * @return
         */
        protected object ReadSync(ZclAttribute attribute)
        {
            //logger.debug("readSync request: {}", attribute);
            CommandResult result;

            try
            {
                result = Read(attribute).Result;
            }
            catch (TaskCanceledException e) // TODO: Check if this is the right exception to catch here
            {
                //logger.debug("readSync interrupted");
                return(null);
            }
            catch (Exception e)
            {
                //logger.debug("readSync exception ", e);
                return(null);
            }

            if (!result.IsSuccess())
            {
                return(null);
            }

            ReadAttributesResponse response = result.GetResponse <ReadAttributesResponse>();

            if (response.Records[0].Status == ZclStatus.SUCCESS)
            {
                ReadAttributeStatusRecord attributeRecord = response.Records[0];
                return(_normalizer.NormalizeZclData(attribute.ZclDataType, attributeRecord.AttributeValue));
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Read an attribute
        ///
        /// <param name="attribute">the ZclAttribute to read</param>
        /// </summary>
        protected object ReadSync(ZclAttribute attribute)
        {
            // Log.Debug("readSync request: {Attribute}", attribute);
            CommandResult result;

            try
            {
                // TODO: Consider removing the call to .Result and use async/await all the way. (GodeGenerator and calls must be adjusted)
                result = Read(attribute).Result;
            }
            catch (TaskCanceledException e) // TODO: Check if this is the right exception to catch here
            {
                // Log.Debug("readSync interrupted");
                return(null);
            }
            catch (Exception e)
            {
                // Log.Debug("readSync exception ", e);
                return(null);
            }

            if (!result.IsSuccess())
            {
                return(null);
            }

            ReadAttributesResponse response = result.GetResponse <ReadAttributesResponse>();

            if (response.Records != null && response.Records[0].Status == ZclStatus.SUCCESS)
            {
                ReadAttributeStatusRecord attributeRecord = response.Records[0];
                return(_normalizer.NormalizeZclData(attribute.ZclDataType, attributeRecord.AttributeValue));
            }

            return(null);
        }