public static LightStateEntity SetConfLightState(LightStateEntity lightStateEntity)
        {
            var bacnetDeviceFromDB = lutronEntities.BACnetDevices
                                     .Where(x => x.device_id == lightStateEntity.DeviceID &&
                                            x.object_instance == (int?)LutronObjectType.Lighting_State)
                                     .Select(x => x).FirstOrDefault();

            if (bacnetDeviceFromDB != null && bacnetDeviceFromDB.bacnet_device_id > 0)
            {
                BacnetAddress bacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.network_id);
                bacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.routed_source,
                                                               (ushort)bacnetDeviceFromDB.routed_net);


                BacnetValue   newLightState      = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED, lightStateEntity.LightState == true ? 1 : 0);
                BacnetValue[] writeNewLightState = { newLightState };
                if (bacNetClient == null)
                {
                    bacNetClient = BackNetClientInit.NewBackNetClient();
                }
                bacNetClient.WritePropertyRequest(bacnetAddress,
                                                  new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)LutronObjectType.Lighting_State),
                                                  BacnetPropertyIds.PROP_PRESENT_VALUE, writeNewLightState);
            }

            Thread.Sleep(1000);

            return(BackNetReadAction.GetConfLightState(lightStateEntity.DeviceID));
        }
        public static LightLevelEntity SetConfLightLevel(LightLevelEntity lightLevelEntity)
        {
            var bacnetDeviceFromDB = lutronEntities.BACnetDevices
                                     .Where(x => x.device_id == lightLevelEntity.DeviceID &&
                                            x.object_instance == (int?)LutronObjectType.Lighting_Level)
                                     .Select(x => x).FirstOrDefault();

            if (bacnetDeviceFromDB != null && bacnetDeviceFromDB.bacnet_device_id > 0)
            {
                BacnetAddress bacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.network_id);
                bacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.routed_source,
                                                               (ushort)bacnetDeviceFromDB.routed_net);


                BacnetValue   newLightLevel      = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL, Convert.ToSingle(lightLevelEntity.LightLevel));
                BacnetValue[] writeNewLightLevel = { newLightLevel };
                if (bacNetClient == null)
                {
                    bacNetClient = BackNetClientInit.NewBackNetClient();
                }
                bacNetClient.WritePropertyRequest(bacnetAddress,
                                                  new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, (uint)LutronObjectType.Lighting_Level),
                                                  BacnetPropertyIds.PROP_PRESENT_VALUE, writeNewLightLevel);
            }



            return(BackNetReadAction.GetConfLightLevel(lightLevelEntity.DeviceID));
        }