コード例 #1
0
        public async Task TestWallboxReadProperty(string property)
        {
            Assert.True(Wallbox.IsProperty(property));
            var status = await _wallbox.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
        }
コード例 #2
0
        public async Task <IActionResult> GetWallboxData(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetWallboxData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

            try
            {
                _logger?.LogDebug($"GetWallboxData({name})...");

                if (Wallbox.IsProperty(name))
                {
                    if (!_wallbox.IsLocked)
                    {
                        return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished."));
                    }

                    if (update)
                    {
                        var status = await _wallbox.ReadPropertyAsync(name);

                        if (!status.IsGood)
                        {
                            return(StatusCode(StatusCodes.Status502BadGateway, status));
                        }
                    }

                    return(Ok(_wallbox.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetWallboxData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
コード例 #3
0
        public WallboxFixture()
        {
            // Set the default culture.
            CultureInfo.CurrentCulture = new CultureInfo("en-US");

            var loggerFactory = new LoggerFactory();
            var logger        = loggerFactory.CreateLogger <Wallbox>();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(AppContext.BaseDirectory)
                                .AddJsonFile("appsettings.json", false, false)
                                .AddUserSecrets <Startup>(true)
                                .Build();

            configuration.GetSection("AppSettings").Bind(Settings);

            var client = new WallboxClient(Settings, loggerFactory.CreateLogger <WallboxClient>());

            Wallbox = new Wallbox(logger, client, Settings);

            Wallbox.ReadAllAsync().Wait();
        }
コード例 #4
0
ファイル: TestData.cs プロジェクト: polytronicgr/HomeControl
 public void TestProperty(string property)
 {
     Assert.True(Wallbox.IsProperty(property));
     Assert.NotNull(_wallbox.GetPropertyValue(property));
 }