示例#1
0
        private AirCon Map(Twin twin)
        {
            var airCon = new AirCon
            {
                Id = twin.DeviceId,
            };

            if (twin.ConnectionState.HasValue)
            {
                airCon.IsConnected = twin.ConnectionState.Value == DeviceConnectionState.Connected;
            }

            if (twin.Tags.Contains("location"))
            {
                airCon.Location = twin.Tags["location"].ToString();
            }

            if (twin.Properties.Desired.Contains("devicePower"))
            {
                airCon.DevicePower = twin.Properties.Desired["devicePower"];
            }

            if (twin.Properties.Desired.Contains("quietOn"))
            {
                airCon.QuietOn = twin.Properties.Desired["quietOn"];
            }

            if (twin.Properties.Desired.Contains("powerfulOn"))
            {
                airCon.PowerfulOn = twin.Properties.Desired["powerfulOn"];
            }

            if (twin.Properties.Desired.Contains("fanMode"))
            {
                airCon.FanMode = int.Parse(twin.Properties.Desired["fanMode"].ToString());
            }

            if (twin.Properties.Desired.Contains("swingVOn"))
            {
                airCon.SwingVOn = twin.Properties.Desired["swingVOn"];
            }

            if (twin.Properties.Desired.Contains("swingHOn"))
            {
                airCon.SwingHOn = twin.Properties.Desired["swingHOn"];
            }

            if (twin.Properties.Desired.Contains("targetTempC"))
            {
                airCon.TargetTempC = int.Parse(twin.Properties.Desired["targetTempC"].ToString());
            }

            return(airCon);
        }
 public ActionResult Edit(AirCon airCon)
 {
     try
     {
         _airConsService.ChangeAirConSetting(airCon);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
示例#3
0
        public async Task ChangeAirConSetting(AirCon airCon)
        {
            RegistryManager registryManager = RegistryManager.CreateFromConnectionString(_azureConfiguration.IoTHubConnectionString);
            var             twin            = await registryManager.GetTwinAsync(airCon.Id);

            twin.Properties.Desired["targetTempC"] = airCon.TargetTempC;
            twin.Properties.Desired["devicePower"] = airCon.DevicePower;
            twin.Properties.Desired["swingHOn"]    = airCon.SwingHOn;
            twin.Properties.Desired["swingVOn"]    = airCon.SwingVOn;
            twin.Properties.Desired["fanMode"]     = airCon.FanMode;
            twin.Properties.Desired["powerfulOn"]  = airCon.PowerfulOn;
            twin.Properties.Desired["quietOn"]     = airCon.QuietOn;
            await registryManager.UpdateTwinAsync(airCon.Id, twin, twin.ETag);
        }
 public ActionResult Index(AirCon airCon)
 {
     _airConsService.ChangeAirConSetting(airCon);
     return(View(_airCons));
 }
示例#5
0
 public async Task Post(AirCon airCon)
 {
     await _airConService.ChangeAirConSetting(airCon);
 }