Fix mysensors awesomeversion strategy usage (#51627)

* Update awesomeversion strategy use in mysensors

* Remove default version
This commit is contained in:
Martin Hjelmare 2021-06-08 20:24:54 +02:00 committed by GitHub
parent abbd4d1d16
commit 2eb6f16a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 19 deletions

View File

@ -1,7 +1,6 @@
"""Config flow for MySensors."""
from __future__ import annotations
from contextlib import suppress
import logging
import os
from typing import Any
@ -55,7 +54,6 @@ def _get_schema_common(user_input: dict[str, str]) -> dict:
schema = {
vol.Required(
CONF_VERSION,
default="",
description={
"suggested_value": user_input.get(CONF_VERSION, DEFAULT_VERSION)
},
@ -67,14 +65,14 @@ def _get_schema_common(user_input: dict[str, str]) -> dict:
def _validate_version(version: str) -> dict[str, str]:
"""Validate a version string from the user."""
version_okay = False
with suppress(AwesomeVersionStrategyException):
version_okay = bool(
AwesomeVersion.ensure_strategy(
version,
[AwesomeVersionStrategy.SIMPLEVER, AwesomeVersionStrategy.SEMVER],
)
version_okay = True
try:
AwesomeVersion(
version,
[AwesomeVersionStrategy.SIMPLEVER, AwesomeVersionStrategy.SEMVER],
)
except AwesomeVersionStrategyException:
version_okay = False
if version_okay:
return {}

View File

@ -264,16 +264,6 @@ async def test_fail_to_connect(hass: HomeAssistant) -> None:
CONF_VERSION,
"invalid_version",
),
(
CONF_GATEWAY_TYPE_TCP,
"gw_tcp",
{
CONF_TCP_PORT: 5003,
CONF_DEVICE: "127.0.0.1",
},
CONF_VERSION,
"invalid_version",
),
(
CONF_GATEWAY_TYPE_TCP,
"gw_tcp",
@ -302,6 +292,7 @@ async def test_fail_to_connect(hass: HomeAssistant) -> None:
{
CONF_TCP_PORT: 5003,
CONF_DEVICE: "127.0.0.",
CONF_VERSION: "2.4",
},
CONF_DEVICE,
"invalid_ip",
@ -312,6 +303,7 @@ async def test_fail_to_connect(hass: HomeAssistant) -> None:
{
CONF_TCP_PORT: 5003,
CONF_DEVICE: "abcd",
CONF_VERSION: "2.4",
},
CONF_DEVICE,
"invalid_ip",