Пример #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _allDevices        = null;
                    _allLocations      = null;
                    _allRooms          = null;
                    _allScenes         = null;
                    _allRules          = null;
                    _allSchedules      = null;
                    _allApps           = null;
                    _allSubscriptions  = null;
                    _allInstalledApps  = null;
                    _allDeviceProfiles = null;

                    _devicesApi        = null;
                    _locationsApi      = null;
                    _roomsApi          = null;
                    _scenesApi         = null;
                    _rulesApi          = null;
                    _schedulesApi      = null;
                    _appsApi           = null;
                    _subscriptionsApi  = null;
                    _installedAppsApi  = null;
                    _deviceProfilesApi = null;
                }
                _disposedValue = true;
            }
        }
Пример #2
0
        public static DevicesApi GetDevicesApi()
        {
            DevicesApi api = new DevicesApi();

            api.ExceptionFactory = TorizonAPIException.DefaultExceptionFactory;
            return(api);
        }
        /// <summary>
        /// This method connects to the IoT Hub with the device identity.
        /// by that it queries the authentication information for its module authentication
        /// It then returns the Connection string by which the Module can perform authentication
        /// </summary>
        /// <returns>Connection String</returns>
        public override string GetConnectionString()
        {
            JToken registrationToken = _dpsApi.GetDeviceRegistration(_idScope, _registrationId);

            if (registrationToken == null)
            {
                throw new FailedToGetRegistrationException($"Registration ID: \"{_registrationId}\" for ID Scope: \"{_idScope}\" could not be retrieved");
            }

            string assignedHub = registrationToken["assignedHub"].ToString();
            string deviceId    = registrationToken["deviceId"].ToString();

            string status = registrationToken["status"].ToString();

            if (status != "assigned")
            {
                // TODO: handle error
            }

            _deviceAuthenticationData.GatewayHostName = assignedHub;
            _deviceAuthenticationData.DeviceId        = deviceId;

            IDeviceApi deviceApi    = new DevicesApi(RestClient.CreateFrom(_deviceAuthenticationData));
            JToken     moduleJToken = deviceApi.GetDeviceAgentModule(deviceId);

            if (moduleJToken == null)
            {
                throw new FailedToGetModuleException($"Module for device: {deviceId} is empty");
            }
            //Note that the response represents the object Module in the SDK Microsoft.Azure.Devices
            //We do not want to include the SDK in the project so we extract the specific parameters we need
            string primaryKey = moduleJToken["authentication"]["symmetricKey"]["primaryKey"].ToString();

            return(CreateModuleConnectionString(assignedHub, deviceId, primaryKey));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (User.Identity.IsAuthenticated)
            {
                var accessToken = await HttpContext.GetTokenAsync("access_token");

                if (string.IsNullOrEmpty(accessToken))
                {
                    // We don't have an access token, sign out
                    await HttpContext.SignOutAsync();

                    return(Redirect("/"));
                }

                // Test if access token is still valid else sign out and reload
                return(await DevicesApi.GetDevicesAsync(accessToken, new ResultHandler <List <Device> >
                {
                    OnError = (errorType, errorMessage) =>
                    {
                        HttpContext.SignOutAsync();
                        return Redirect("/");
                    }
                }));
            }

            return(Page());
        }
Пример #5
0
        public void Init()
        {
            var deviceToken = Properties["device1.token"];
            var config      = new Configuration(timeout: 10000, accessToken: deviceToken);

            instance = new DevicesApi(config);
        }
        public SmartThingsClient(string accessToken)
        {
            var configuration = new Configuration();

            configuration.AccessToken = accessToken ?? throw new ArgumentNullException(accessToken);
            _accessToken = accessToken;

            _devicesApi        = new DevicesApi(configuration);
            _locationsApi      = new LocationsApi(configuration);
            _roomsApi          = new RoomsApi(configuration);
            _scenesApi         = new ScenesApi(configuration);
            _rulesApi          = new RulesApi(configuration);
            _schedulesApi      = new SchedulesApi(configuration);
            _appsApi           = new AppsApi(configuration);
            _subscriptionsApi  = new SubscriptionsApi(configuration);
            _installedAppsApi  = new InstalledappsApi(configuration);
            _deviceProfilesApi = new ProfilesApi(configuration);
            _capabilitiesApi   = new CapabilitiesApi(configuration);
            _presentationApi   = new PresentationsApi(configuration);

            //_accessToken = accessToken;
            //_devicesApi = new DevicesApi();
            //_locationsApi = new LocationsApi();
            //_roomsApi = new RoomsApi();
            //_scenesApi = new ScenesApi();
            //_rulesApi = new RulesApi();
            //_schedulesApi = new SchedulesApi();
            //_appsApi = new AppsApi();
            //_subscriptionsApi = new SubscriptionsApi();
            //_installedAppsApi = new InstalledappsApi();
            //_deviceProfilesApi = new ProfilesApi();
            //_capabilitiesApi = new CapabilitiesApi();
            //_presentationApi = new PresentationsApi();
        }
Пример #7
0
        static void Main(string[] args)
        {
            var configuration = GetConfigurationService(args).Get <Configuration>();

            if (!configuration.IsValid())
            {
                Console.Error.WriteLine("It is necessary to provide the DeviceApiEndpoint, and DeviceApiKey configuration properties via environment variables or command line arguments.");
                Environment.Exit(1);
            }
            Console.WriteLine("Starting with configuration: " + JsonConvert.SerializeObject(configuration));

            IO.Swagger.Client.Configuration.ApiKey = new Dictionary <string, string> {
                { "X-API-KEY", configuration.DeviceApiKey }
            };
            ApiClient  apliClient = new ApiClient(configuration.DeviceApiEndpoint);
            DevicesApi devicesApi = new DevicesApi(apliClient);

            Random random         = new Random();
            float  temperature    = random.Next(18, 30);
            float  airHumidity    = random.Next(0, 100);
            int    carbonMonoxide = random.Next(0, 5);

            string[] healthStatuses = { "needs_service", "needs_new_filter", "gas_leak", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK" };
            string   serialNumber   = Guid.NewGuid().ToString();

            devicesApi.RegisterDevice(new DeviceInfo {
                SerialNumber = serialNumber, FirmwareVersion = "1.0.0"
            });

            while (true)
            {
                devicesApi.SendReadings(new List <Reading> {
                    new Reading {
                        DateTime       = DateTime.UtcNow,
                        AirHumidity    = airHumidity,
                        Temperature    = temperature,
                        CarbonMonoxide = carbonMonoxide,
                        HealthStatus   = healthStatuses[random.Next(0, healthStatuses.Length)]
                    }
                }, serialNumber);
                temperature   += ((float)random.Next(-100, 100)) / 100f;
                airHumidity    = Math.Min(100f, airHumidity + ((float)random.Next(-100, 100)) / 100f);
                carbonMonoxide = Math.Min(10, Math.Max(carbonMonoxide + random.Next(-1, 2), 0));
                Thread.Sleep(60000);
            }
        }
Пример #8
0
        public SmartThingsClient(string accessToken)
        {
            var configuration = new Configuration();

            configuration.AccessToken = accessToken ?? throw new ArgumentNullException(accessToken);
            //configuration.BasePath = "https://graph-eu01-euwest1.api.smartthings.com/v1";

            _devicesApi        = new DevicesApi(configuration);
            _locationsApi      = new LocationsApi(configuration);
            _roomsApi          = new RoomsApi(configuration);
            _scenesApi         = new ScenesApi(configuration);
            _rulesApi          = new RulesApi(configuration);
            _schedulesApi      = new SchedulesApi(configuration);
            _appsApi           = new AppsApi(configuration);
            _subscriptionsApi  = new SubscriptionsApi(configuration);
            _installedAppsApi  = new InstalledAppsApi(configuration);
            _deviceProfilesApi = new DeviceProfilesApi(configuration);
        }
        public async Task <IActionResult> OnPostAsync(CustomDevice customDevice)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.AddCustomDeviceAsync(tokenData.AccessToken, customDevice, new ResultHandler <CustomDevice>
            {
                OnSuccess = (newCustomDevice) =>
                {
                    return Redirect("/Devices/AddCustomDeviceResult?id=" + newCustomDevice.Id);
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnPostAsync(Device device)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await DevicesApi.AddDeviceAsync(accessToken, device, new ResultHandler <Device>
            {
                OnSuccess = (newDevice) =>
                {
                    return Redirect("/Devices/AddDeviceResult?id=" + newDevice.Id);
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.GetDevicesAsync(tokenData.AccessToken, MeterSubType.MeterSubTypeHeat, new ResultHandler <List <Device> >
            {
                OnSuccess = (devices) =>
                {
                    Devices = devices;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Пример #12
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await DevicesApi.GetDevicesAsync(accessToken, new ResultHandler <List <Device> >
            {
                OnSuccess = (devices) =>
                {
                    Devices = devices;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Пример #13
0
        public async Task <IActionResult> OnPostAsync(Device device)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await DevicesApi.UpdateDeviceAsync(accessToken, device, new ResultHandler <Device>
            {
                OnSuccess = (empty) =>
                {
                    // Trigger another GET to show the updated device
                    return Redirect("/Devices/UpdateDevice");
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnPostAsync(SmartMeDeviceConfiguration config)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await DevicesApi.SetSmartMeDeviceConfigurationAsync(accessToken, config, new ResultHandler <SmartMeDeviceConfiguration>
            {
                OnSuccess = (empty) =>
                {
                    // Trigger another GET to show the updated SmartMeDeviceConfiguration
                    return Redirect("/Devices/SetSmartMeDeviceConfiguration");
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Пример #15
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await DevicesApi.GetAdditionalDeviceInformationAsync(accessToken, Id, new ResultHandler <AdditionalDeviceInformation>
            {
                OnSuccess = (info) =>
                {
                    Info = info;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.GetSmartMeDeviceConfigurationAsync(tokenData.AccessToken, Id, new ResultHandler <SmartMeDeviceConfiguration>
            {
                OnSuccess = (deviceConfig) =>
                {
                    DeviceConfig = deviceConfig;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync(Guid id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.GetCustomDeviceAsync(tokenData.AccessToken, id, new ResultHandler <CustomDevice>
            {
                OnSuccess = (customDevice) =>
                {
                    CustomDevice = customDevice;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnPostAsync(CustomDevice customDevice)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.UpdateCustomDeviceAsync(tokenData.AccessToken, customDevice, new ResultHandler <CustomDevice>
            {
                OnSuccess = (empty) =>
                {
                    // Trigger another GET to show the updated custom device
                    return Redirect("/Devices/UpdateCustomDevice");
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync(Guid id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            return(await DevicesApi.GetCustomDeviceAsync(accessToken, id, new ResultHandler <CustomDevice>
            {
                OnSuccess = (customDevice) =>
                {
                    CustomDevice = customDevice;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Пример #20
0
        public static async Task DevicesAsync(UserPassword credentials)
        {
            // We will use this device to fetch its details later
            Device sampleDevice;

            // Get all devices
            {
                Helpers.WriteConsoleTitle("Get all devices");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials);

                foreach (var device in devices)
                {
                    Console.WriteLine($"Id: {device.Id}, Name: {device.Name}");
                }

                // Store the first device to show how to fetch its details in various ways. Make sure you have at least
                // one device in your smart-me account.
                sampleDevice = devices.First();
            }

            // Get all devices with a certain energy type
            {
                Helpers.WriteConsoleTitle("Get all devices with energy type 'MeterTypeElectricity'");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials, MeterEnergyType.MeterTypeElectricity);

                foreach (var device in devices)
                {
                    Console.WriteLine($"Id: {device.Id}, Name: {device.Name}, EnergyType: {Enum.GetName(typeof(MeterEnergyType), device.DeviceEnergyType)}");
                }
            }

            // Get all devices with a certain meter sub type
            {
                Helpers.WriteConsoleTitle("Get all devices with meter sub type 'MeterSubTypeHeat'");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials, MeterSubType.MeterSubTypeHeat);

                foreach (var device in devices)
                {
                    Console.Write($"Id: {device.Id} Name: {device.Name} ");

                    if (device.MeterSubType != null)
                    {
                        Console.Write($"SubType: {Enum.GetName(typeof(MeterSubType), device.MeterSubType)}");
                    }

                    Console.WriteLine();
                }
            }

            // Get device by Id
            {
                Helpers.WriteConsoleTitle("Get device by Id");

                Device device = await DevicesApi.GetDeviceAsync(credentials, sampleDevice.Id);

                Console.WriteLine($"Name: {device.Name}, Id: {device.Id}");
            }

            // Get device by Serial
            {
                Helpers.WriteConsoleTitle("Get device by serial number");

                Device device = await DevicesApi.GetDeviceAsync(credentials, sampleDevice.Serial);

                Console.WriteLine($"Name: {device.Name}, Serial: {device.Serial}");
            }

            // Get additional device information
            {
                Helpers.WriteConsoleTitle("Get additional device information");

                var info = await DevicesApi.GetAdditionalDeviceInformationAsync(credentials, sampleDevice.Id);

                Console.WriteLine($"ID: {info.ID}, HardwareVersion: {info.HardwareVersion}, FirmwareVersion: {info.FirmwareVersion}, AdditionalMeterSerialNumber: {info.AdditionalMeterSerialNumber}");
            }

            // Add and update device
            {
                Helpers.WriteConsoleTitle("Add a new device");

                Device newDevice = await DevicesApi.AddDeviceAsync(credentials, new Device
                {
                    Name             = "NewDevice",
                    DeviceEnergyType = MeterEnergyType.MeterTypeElectricity,
                    ActivePower      = 0,
                    CounterReading   = 0,
                    Voltage          = 230,
                    VoltageL1        = 230,
                    Current          = 1.0,
                    PowerFactor      = 0,
                    PowerFactorL1    = 0,
                    Temperature      = 26
                });

                Helpers.WriteConsoleTitle("Update the name of a device");

                newDevice.Name = "UpdatedDevice";

                await DevicesApi.UpdateDeviceAsync(credentials, newDevice);

                Helpers.WriteConsoleTitle("Update CounterReadingImport and ActivePower of a device");

                for (int i = 0; i < 10; i++)
                {
                    newDevice.CounterReading = i + 1;
                    newDevice.ActivePower    = i * 1.1;

                    await DevicesApi.UpdateDeviceAsync(credentials, newDevice);

                    Thread.Sleep(1000);
                }
            }
        }
Пример #21
0
 public void Cleanup()
 {
     instance = null;
 }
        public static async Task ValuesAsync(UserPassword credentials)
        {
            // We will use this device to fetch its details later
            Device sampleDevice;

            // Get all devices
            {
                Helpers.WriteConsoleTitle("Get all devices");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials);

                foreach (var device in devices)
                {
                    Console.WriteLine($"Id: {device.Id}, Name: {device.Name}");
                }

                // Store the first device. Make sure you have at least one device in your smart-me account.
                sampleDevice = devices.First();
            }

            // Get Values
            {
                Helpers.WriteConsoleTitle("Get Values");

                var deviceValues = await ValuesApi.GetDeviceValuesAsync(credentials, sampleDevice.Id);

                foreach (var deviceValue in deviceValues.Values)
                {
                    Console.WriteLine($"Obis: {deviceValue.Obis}, Value: {deviceValue.Value}");
                }
            }

            // Get Values In Past
            {
                Helpers.WriteConsoleTitle("Get Values In Past");

                var deviceValues = await ValuesApi.GetDeviceValuesInPastAsync(credentials, sampleDevice.Id, new DateTime(2019, 8, 16, 12, 0, 0, DateTimeKind.Utc));

                foreach (var deviceValue in deviceValues.Values)
                {
                    Console.WriteLine($"Obis: {deviceValue.Obis}, Value: {deviceValue.Value}");
                }
            }

            // Get Values In Past Multiple
            {
                Helpers.WriteConsoleTitle("Get Values In Past Multiple");

                var multipleDeviceValues = await ValuesApi.GetDeviceValuesInPastMultipleAsync(
                    credentials,
                    sampleDevice.Id,
                    new DateTime(2019, 8, 5, 10, 0, 0, DateTimeKind.Utc),
                    new DateTime(2019, 8, 5, 12, 0, 0, DateTimeKind.Utc),
                    5);

                foreach (var deviceValues in multipleDeviceValues)
                {
                    Console.WriteLine(deviceValues.Date);

                    foreach (var deviceValue in deviceValues.Values)
                    {
                        Console.WriteLine($"Obis: {deviceValue.Obis}, Value: {deviceValue.Value}");
                    }
                }
            }

            // Get Meter Values
            {
                Helpers.WriteConsoleTitle("Get Meter Values");

                var meterValues = await ValuesApi.GetMeterValuesAsync(credentials, sampleDevice.Id, new DateTime(2019, 8, 5, 12, 0, 0, DateTimeKind.Utc));

                Console.WriteLine($"CounterReading: {meterValues.CounterReading}, CounterReadingImport: {meterValues.CounterReadingImport}");
            }
        }
        public static async Task ActionsAsync(UserPassword credentials)
        {
            // We will use this device to fetch its details later
            Device sampleDevice;

            // Get all devices
            {
                Helpers.WriteConsoleTitle("Get all devices");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials);

                foreach (var device in devices)
                {
                    Console.WriteLine($"Id: {device.Id}, Name: {device.Name}");
                }

                // Store the first device. Make sure you have at least one device in your smart-me account.
                sampleDevice = devices.First();
            }

            // Get Actions
            {
                Helpers.WriteConsoleTitle("Get Actions");

                List <SmartMeApiClient.Containers.Action> actions = await ActionsApi.GetActionsAsync(credentials, sampleDevice.Id);

                foreach (var action in actions)
                {
                    Console.WriteLine($"Name: {action.Name}, ObisCode: {action.ObisCode}");
                }
            }

            // Run Actions
            {
                Helpers.WriteConsoleTitle("Run Actions");

                await ActionsApi.RunActionsAsync(credentials, new ActionToRun
                {
                    DeviceID = sampleDevice.Id,
                    Actions  = new List <ActionToRunItem>
                    {
                        new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 1.0)
                    }
                });

                Console.WriteLine("Switch on");

                Thread.Sleep(5000);

                await ActionsApi.RunActionsAsync(credentials, new ActionToRun
                {
                    DeviceID = sampleDevice.Id,
                    Actions  = new List <ActionToRunItem>
                    {
                        new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0)
                    }
                });

                Console.WriteLine("Switch off");
            }
        }
Пример #24
0
        public static async Task DeviceConfigurationAsync(UserPassword credentials)
        {
            // We will use this device to fetch its details later
            Device sampleDevice;

            // Get all devices
            {
                Helpers.WriteConsoleTitle("Get all devices");

                List <Device> devices = await DevicesApi.GetDevicesAsync(credentials);

                foreach (var device in devices)
                {
                    Console.WriteLine($"Id: {device.Id}, Name: {device.Name}");
                }

                // Store the first device to show fow to fetch its details in various ways. Make sure you have at least
                // one device in your smart-me account.
                sampleDevice = devices.First();
            }

            // Get smart-me Device Configuration
            {
                Helpers.WriteConsoleTitle("Get smart-me device configuration");

                var configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, sampleDevice.Id);

                Console.WriteLine($"Id: {configuration.Id}, UploadInterval: {configuration.UploadInterval}");
            }

            // Modify smart-me device configuration
            {
                Helpers.WriteConsoleTitle("Set smart-me device configuration");

                var configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, sampleDevice.Id);

                configuration.DevicePinCode = "1234";

                try
                {
                    await DevicesApi.SetSmartMeDeviceConfigurationAsync(credentials, configuration);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error: {e.Message}");
                }

                Thread.Sleep(5000);

                configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, sampleDevice.Id);

                configuration.DevicePinCode = "7890";

                try
                {
                    await DevicesApi.SetSmartMeDeviceConfigurationAsync(credentials, configuration);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error: {e.Message}");
                }

                Thread.Sleep(5000);
            }
        }
Пример #25
0
        public static async Task CustomDevicesAsync(UserPassword credentials)
        {
            // Add Custom Device
            {
                Helpers.WriteConsoleTitle("Add a custom device");

                await DevicesApi.AddCustomDeviceAsync(credentials, new CustomDevice
                {
                    Id        = new Guid(),
                    Name      = "CustomDeviceTest",
                    Serial    = 0,
                    ValueDate = DateTime.UtcNow,
                    Values    = new List <CustomDeviceValue>
                    {
                        new CustomDeviceValue {
                            Name = "SomeVoltageValue", Value = 5.6
                        },
                        new CustomDeviceValue {
                            Name = "SomeTemperatureValue", Value = 12.1
                        }
                    }
                });
            }

            CustomDevice sampleDevice;

            // Get Custom Devices
            {
                Helpers.WriteConsoleTitle("Get custom devices");

                List <CustomDevice> customDevices = await DevicesApi.GetCustomDevicesAsync(credentials);

                foreach (CustomDevice customDevice in customDevices)
                {
                    if (customDevice != null)
                    {
                        Console.WriteLine($"Id: {customDevice.Id}, Name: {customDevice.Name}");
                    }
                }

                sampleDevice = customDevices.First();
            }

            // Update Custom Device
            {
                Helpers.WriteConsoleTitle("Update a custom device");

                List <CustomDevice> customDevices = await DevicesApi.GetCustomDevicesAsync(credentials);

                foreach (CustomDevice customDevice in customDevices)
                {
                    if (customDevice != null)
                    {
                        customDevice.Name = "UpdatedCustomDeviceTest";
                        await DevicesApi.UpdateCustomDeviceAsync(credentials, customDevice);

                        break;
                    }
                }
            }

            // Get Custom Device by Id
            {
                Helpers.WriteConsoleTitle("Get custom device by id");

                CustomDevice customDevice = await DevicesApi.GetCustomDeviceAsync(credentials, sampleDevice.Id);

                Console.WriteLine($"Id: {customDevice.Id}, Name: {customDevice.Name}");
            }
        }
Пример #26
0
 public DevicesApiTests()
 {
     instance = new DevicesApi();
 }
Пример #27
0
 public void Init()
 {
     instance = new DevicesApi();
 }