mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
MySensors: Use version parser from packaging
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
from packaging.version import Version, parse as parse_version
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@@ -52,12 +53,7 @@ def _get_schema_common() -> dict:
|
|||||||
def _validate_version(version: str) -> Dict[str, str]:
|
def _validate_version(version: str) -> Dict[str, str]:
|
||||||
"""Validate a version string from the user."""
|
"""Validate a version string from the user."""
|
||||||
errors = {CONF_VERSION: "invalid_version"}
|
errors = {CONF_VERSION: "invalid_version"}
|
||||||
version_parts = version.split(".")
|
if not isinstance(parse_version(version), Version):
|
||||||
if len(version_parts) != 2:
|
|
||||||
return errors
|
|
||||||
try:
|
|
||||||
[int(x) for x in version_parts]
|
|
||||||
except ValueError:
|
|
||||||
return errors
|
return errors
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user