Ensure homekit version strings conform to spec (#35741)
HomeKit requires all version strings to be in the format MAJOR.MINOR.REVISIONpull/35828/head
parent
e2f0520028
commit
cc5fc2baa4
|
@ -75,6 +75,7 @@ from .const import (
|
|||
from .util import (
|
||||
convert_to_float,
|
||||
dismiss_setup_message,
|
||||
format_sw_version,
|
||||
show_setup_message,
|
||||
validate_media_player_features,
|
||||
)
|
||||
|
@ -253,7 +254,7 @@ class HomeAccessory(Accessory):
|
|||
else:
|
||||
model = domain.title()
|
||||
if ATTR_SOFTWARE_VERSION in self.config:
|
||||
sw_version = self.config[ATTR_SOFTWARE_VERSION]
|
||||
sw_version = format_sw_version(self.config[ATTR_SOFTWARE_VERSION])
|
||||
else:
|
||||
sw_version = __version__
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import io
|
|||
import ipaddress
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import secrets
|
||||
import socket
|
||||
|
||||
|
@ -415,6 +416,14 @@ def get_aid_storage_fullpath_for_entry_id(hass: HomeAssistant, entry_id: str):
|
|||
)
|
||||
|
||||
|
||||
def format_sw_version(version):
|
||||
"""Extract the version string in a format homekit can consume."""
|
||||
match = re.search(r"([0-9]+)(\.[0-9]+)?(\.[0-9]+)?", str(version).replace("-", "."))
|
||||
if match:
|
||||
return match.group(0)
|
||||
return None
|
||||
|
||||
|
||||
def migrate_filesystem_state_data_for_primary_imported_entry_id(
|
||||
hass: HomeAssistant, entry_id: str
|
||||
):
|
||||
|
|
|
@ -28,6 +28,7 @@ from homeassistant.components.homekit.util import (
|
|||
density_to_air_quality,
|
||||
dismiss_setup_message,
|
||||
find_next_available_port,
|
||||
format_sw_version,
|
||||
port_is_available,
|
||||
show_setup_message,
|
||||
temperature_to_homekit,
|
||||
|
@ -315,3 +316,12 @@ async def test_port_is_available(hass):
|
|||
assert next_port
|
||||
|
||||
assert await hass.async_add_executor_job(port_is_available, next_port)
|
||||
|
||||
|
||||
async def test_format_sw_version():
|
||||
"""Test format_sw_version method."""
|
||||
assert format_sw_version("soho+3.6.8+soho-release-rt120+10") == "3.6.8"
|
||||
assert format_sw_version("undefined-undefined-1.6.8") == "1.6.8"
|
||||
assert format_sw_version("56.0-76060") == "56.0.76060"
|
||||
assert format_sw_version(3.6) == "3.6"
|
||||
assert format_sw_version("unknown") is None
|
||||
|
|
Loading…
Reference in New Issue