示例#1
0
 private void thermostat2_OnDesiredPropertiesReceived(TwinCollection desired)
 {
     Task.Run(async() =>
     {
         var targetTemp = desired.GetPropertyValue <double>("thermostat2", "targetTemperature");
         logger.LogWarning($"TargetTempUpdated on thermostat2: " + targetTemp);
         await pnpClient.AckDesiredPropertyReadAsync("thermostat2", "targetTemperature", targetTemp, StatusCodes.Pending, "update in progress", desired.Version);
         await this.ProcessTempUpdateAsync("thermostat2", targetTemp);
         await pnpClient.AckDesiredPropertyReadAsync("thermostat2", "targetTemperature", targetTemp, StatusCodes.Completed, "update Complete", desired.Version);
     });
 }
        public void GetRootPropertyWithNoValue()
        {
            string json = @"
      {
         targetTemperature: 1.23
      }";

            TwinCollection twinCollection = new TwinCollection(json);
            var            propVal        = twinCollection.GetPropertyValue <double>("targetTemperature");

            Assert.Equal(1.23, propVal);
        }
示例#3
0
        public void GetComponentPropertyWithoutFlagDoesRaiseException()
        {
            string         json           = @"
              {
                tempSensor1: {
                  targetTemperature: {
                    value : 1.23
                  }
                }
              }";
            TwinCollection twinCollection = new TwinCollection(json);

            Assert.Throws <Exception>(() => twinCollection.GetPropertyValue <double>("tempSensor1", "targetTemperature"));
        }
        public void GetPropertyReturnsDefaultIfCompoNotFound()
        {
            string json = @"
      {
        tempSensor1: {
          __t: 'c',
          targetTemperature: {}
        }
      }";

            TwinCollection twinCollection = new TwinCollection(json);
            var            propVal        = twinCollection.GetPropertyValue <double>("notfound", "NotFound");

            Assert.Equal(0, propVal);
        }
        public void GetPropertyFromComponentWithoutValue()
        {
            string json = @"
      {
        tempSensor1: {
          __t: 'c',
          targetTemperature: 1.23
        }
      }";

            TwinCollection twinCollection = new TwinCollection(json);
            var            propVal        = twinCollection.GetPropertyValue <double>("tempSensor1", "targetTemperature");

            Assert.Equal(1.23, propVal);
        }
        public void GetPropertyWithoutFlagReturnsDefaultValue()
        {
            string         json           = @"
      {
        tempSensor1: {
          targetTemperature: {
            value : 1.23
          }
        }
      }";
            TwinCollection twinCollection = new TwinCollection(json);

            var propVal = twinCollection.GetPropertyValue <double>("tempSensor1", "targetTemperature");

            Assert.Equal(default, propVal);
        public void AddPropertyToAnExistingComponent()
        {
            string         json           = @"
      {
        tempSensor1: {
          __t: 'c',
          targetTemperature: {}
        }
      }";
            TwinCollection twinCollection = new TwinCollection(json);

            twinCollection.AddComponentProperty("tempSensor1", "newProperty", true);
            TwinCollection updatedCollection = new TwinCollection(twinCollection.ToJson());
            var            result            = twinCollection.GetPropertyValue <bool>("tempSensor1", "newProperty");

            Assert.True(result);
        }
        public void GetPropertyFromComponentWithIncorrectType()
        {
            string json = @"
      {
        tempSensor1: {
          __t: 'c',
          targetTemperature: {
            value : 1.8
          }
        }
      }";

            TwinCollection twinCollection = new TwinCollection(json);
            var            propVal        = twinCollection.GetPropertyValue <string>("tempSensor1", "targetTemperature");

            Assert.Equal("1.8", propVal);
        }
        public void GetPropertyWithoutFlagDoesRaiseException()
        {
            string         json           = @"
      {
        tempSensor1: {
          targetTemperature: {
            value : 1.23
          }
        }
      }";
            TwinCollection twinCollection = new TwinCollection(json);

            try
            {
                var propVal = twinCollection.GetPropertyValue <double>("tempSensor1", "targetTemperature");
            }
            catch (Exception ex)
            {
                Assert.Equal("Component tempSensor1 does not have the expected '__t' flag", ex.Message);
            }
        }