public async Task should_change_power_on_state()
        {
            var serviceData = await GetServiceData();

            var client           = new SonoffClient(_httpClient);
            var beforeDeviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);

            Exception      exception  = null;
            DeviceInfoData deviceInfo = null;

            try
            {
                await client.SetPowerOnStateAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId, PowerOnState.off);

                deviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);

                await client.SetPowerOnStateAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId, PowerOnState.on);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Null(exception);
            Assert.NotNull(deviceInfo);
            Assert.Equal(PowerOnState.on, deviceInfo.Startup);

            await client.SetPowerOnStateAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId, beforeDeviceInfo.Startup);
        }
        public async Task should_unlock_ota()
        {
            var serviceData = await GetServiceData();

            var client = new SonoffClient(_httpClient);

            Exception      exception        = null;
            DeviceInfoData beforeDeviceInfo = null;
            DeviceInfoData afterDeviceInfo  = null;

            try
            {
                beforeDeviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);

                if (beforeDeviceInfo.OtaUnlock)
                {
                    output.WriteLine("OTA already unlocked. Test will show nothing.");
                    return;
                }

                await client.UnlockOTAAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);

                afterDeviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Null(exception);
            Assert.NotNull(beforeDeviceInfo);
            Assert.NotNull(afterDeviceInfo);
            Assert.NotEqual(beforeDeviceInfo.OtaUnlock, afterDeviceInfo.OtaUnlock);
        }
        public async Task should_set_inching()
        {
            var serviceData = await GetServiceData();

            var client = new SonoffClient(_httpClient);

            Exception exception = null;

            try
            {
                var deviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);

                await client.SetInchingAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId, State.on, 1000);

                await Task.Delay(5000); // time to observe inching

                await client.SetInchingAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId, deviceInfo.Pulse, deviceInfo.PulseWidth);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Null(exception);
        }
        public async Task should_return_device_info()
        {
            var serviceData = await GetServiceData();

            var client = new SonoffClient(_httpClient);

            DeviceInfoData deviceInfo = null;
            Exception      exception  = null;

            try
            {
                deviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Null(exception);
            Assert.NotNull(deviceInfo);
        }
        public async Task should_turn_switch_off()
        {
            var serviceData = await GetServiceData();

            var client = new SonoffClient(_httpClient);

            Exception      exception  = null;
            DeviceInfoData deviceInfo = null;

            try
            {
                await client.TurnSwitchOffAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);

                deviceInfo = await client.GetDeviceInfoAsync(serviceData.ipAddress, serviceData.port, serviceData.deviceId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Null(exception);
            Assert.NotNull(deviceInfo);
            Assert.Equal(State.off, deviceInfo.Switch);
        }