Make get_channel available as generic helper (#101721)
* Make get_channel available as generic helper * Follow up comment
This commit is contained in:
parent
915f5bf84e
commit
31bd500222
4 changed files with 43 additions and 29 deletions
|
@ -15,7 +15,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
__version__ as current_version,
|
__version__ as current_version,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, get_release_channel
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform, instance_id
|
from homeassistant.helpers import config_validation as cv, entity_platform, instance_id
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
from homeassistant.helpers.system_info import async_get_system_info
|
from homeassistant.helpers.system_info import async_get_system_info
|
||||||
|
@ -67,7 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Additional/extra data collection
|
# Additional/extra data collection
|
||||||
channel = get_channel(current_version)
|
channel = get_release_channel()
|
||||||
huuid = await instance_id.async_get(hass)
|
huuid = await instance_id.async_get(hass)
|
||||||
system_info = await async_get_system_info(hass)
|
system_info = await async_get_system_info(hass)
|
||||||
custom_components = await async_get_custom_components(hass)
|
custom_components = await async_get_custom_components(hass)
|
||||||
|
@ -110,17 +110,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_channel(version: str) -> str:
|
|
||||||
"""Find channel based on version number."""
|
|
||||||
if "dev0" in version:
|
|
||||||
return "dev"
|
|
||||||
if "dev" in version:
|
|
||||||
return "nightly"
|
|
||||||
if "b" in version:
|
|
||||||
return "beta"
|
|
||||||
return "stable"
|
|
||||||
|
|
||||||
|
|
||||||
def process_before_send(
|
def process_before_send(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
options: MappingProxyType[str, Any],
|
options: MappingProxyType[str, Any],
|
||||||
|
|
|
@ -28,7 +28,17 @@ import re
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
from typing import TYPE_CHECKING, Any, Generic, ParamSpec, Self, TypeVar, cast, overload
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
|
Any,
|
||||||
|
Generic,
|
||||||
|
Literal,
|
||||||
|
ParamSpec,
|
||||||
|
Self,
|
||||||
|
TypeVar,
|
||||||
|
cast,
|
||||||
|
overload,
|
||||||
|
)
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -222,6 +232,19 @@ def async_get_hass() -> HomeAssistant:
|
||||||
return _hass.hass
|
return _hass.hass
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def get_release_channel() -> Literal["beta", "dev", "nightly", "stable"]:
|
||||||
|
"""Find release channel based on version number."""
|
||||||
|
version = __version__
|
||||||
|
if "dev0" in version:
|
||||||
|
return "dev"
|
||||||
|
if "dev" in version:
|
||||||
|
return "nightly"
|
||||||
|
if "b" in version:
|
||||||
|
return "beta"
|
||||||
|
return "stable"
|
||||||
|
|
||||||
|
|
||||||
@enum.unique
|
@enum.unique
|
||||||
class HassJobType(enum.Enum):
|
class HassJobType(enum.Enum):
|
||||||
"""Represent a job type."""
|
"""Represent a job type."""
|
||||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sentry import get_channel, process_before_send
|
from homeassistant.components.sentry import process_before_send
|
||||||
from homeassistant.components.sentry.const import (
|
from homeassistant.components.sentry.const import (
|
||||||
CONF_DSN,
|
CONF_DSN,
|
||||||
CONF_ENVIRONMENT,
|
CONF_ENVIRONMENT,
|
||||||
|
@ -103,20 +103,6 @@ async def test_setup_entry_with_tracing(hass: HomeAssistant) -> None:
|
||||||
assert call_args["traces_sample_rate"] == 0.5
|
assert call_args["traces_sample_rate"] == 0.5
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("version", "channel"),
|
|
||||||
[
|
|
||||||
("0.115.0.dev20200815", "nightly"),
|
|
||||||
("0.115.0", "stable"),
|
|
||||||
("0.115.0b4", "beta"),
|
|
||||||
("0.115.0dev0", "dev"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_get_channel(version: str, channel: str) -> None:
|
|
||||||
"""Test if channel detection works from Home Assistant version number."""
|
|
||||||
assert get_channel(version) == channel
|
|
||||||
|
|
||||||
|
|
||||||
async def test_process_before_send(hass: HomeAssistant) -> None:
|
async def test_process_before_send(hass: HomeAssistant) -> None:
|
||||||
"""Test regular use of the Sentry process before sending function."""
|
"""Test regular use of the Sentry process before sending function."""
|
||||||
hass.config.components.add("puppies")
|
hass.config.components.add("puppies")
|
||||||
|
|
|
@ -43,6 +43,7 @@ from homeassistant.core import (
|
||||||
State,
|
State,
|
||||||
SupportsResponse,
|
SupportsResponse,
|
||||||
callback,
|
callback,
|
||||||
|
get_release_channel,
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import (
|
from homeassistant.exceptions import (
|
||||||
HomeAssistantError,
|
HomeAssistantError,
|
||||||
|
@ -2481,3 +2482,18 @@ async def test_validate_state(hass: HomeAssistant) -> None:
|
||||||
assert ha.validate_state("test") == "test"
|
assert ha.validate_state("test") == "test"
|
||||||
with pytest.raises(InvalidStateError):
|
with pytest.raises(InvalidStateError):
|
||||||
ha.validate_state("t" * 256)
|
ha.validate_state("t" * 256)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("version", "release_channel"),
|
||||||
|
[
|
||||||
|
("0.115.0.dev20200815", "nightly"),
|
||||||
|
("0.115.0", "stable"),
|
||||||
|
("0.115.0b4", "beta"),
|
||||||
|
("0.115.0dev0", "dev"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_get_release_channel(version: str, release_channel: str) -> None:
|
||||||
|
"""Test if release channel detection works from Home Assistant version number."""
|
||||||
|
with patch("homeassistant.core.__version__", f"{version}"):
|
||||||
|
assert get_release_channel() == release_channel
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue