Address late review comments for version integration (#63283)
* Address late review comments for version integration * 2 leftover persistent_notification setup
This commit is contained in:
parent
06ebbb7cae
commit
56bda80e0a
6 changed files with 12 additions and 28 deletions
|
@ -9,7 +9,6 @@ import voluptuous as vol
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_NAME, CONF_SOURCE
|
from homeassistant.const import CONF_NAME, CONF_SOURCE
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.util import slugify
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_VERSION_SOURCE,
|
ATTR_VERSION_SOURCE,
|
||||||
|
@ -47,10 +46,12 @@ from .const import (
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Version."""
|
"""Handle a config flow for Version."""
|
||||||
|
|
||||||
_entry_data: dict[str, Any] = DEFAULT_CONFIGURATION.copy()
|
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""Initialize the Version config flow."""
|
||||||
|
self._entry_data: dict[str, Any] = DEFAULT_CONFIGURATION.copy()
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self,
|
self,
|
||||||
user_input: dict[str, Any] | None = None,
|
user_input: dict[str, Any] | None = None,
|
||||||
|
@ -141,9 +142,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Import a config entry from configuration.yaml."""
|
"""Import a config entry from configuration.yaml."""
|
||||||
self._entry_data = _convert_imported_configuration(import_config)
|
self._entry_data = _convert_imported_configuration(import_config)
|
||||||
|
|
||||||
for entry in self._async_current_entries():
|
self._async_abort_entries_match({**DEFAULT_CONFIGURATION, **self._entry_data})
|
||||||
if _fingerprint(entry.data) == _fingerprint(self._entry_data):
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=self._config_entry_name, data=self._entry_data
|
title=self._config_entry_name, data=self._entry_data
|
||||||
|
@ -163,12 +162,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def _fingerprint(data) -> str:
|
|
||||||
"""Return a fingerprint of the configuration."""
|
|
||||||
configuration = {**DEFAULT_CONFIGURATION, **data}
|
|
||||||
return slugify("_".join(configuration.values()))
|
|
||||||
|
|
||||||
|
|
||||||
def _convert_imported_configuration(config: dict[str, Any]) -> Any:
|
def _convert_imported_configuration(config: dict[str, Any]) -> Any:
|
||||||
"""Convert a key from the imported configuration."""
|
"""Convert a key from the imported configuration."""
|
||||||
data = DEFAULT_CONFIGURATION.copy()
|
data = DEFAULT_CONFIGURATION.copy()
|
||||||
|
|
|
@ -29,7 +29,6 @@ class VersionDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
hass=hass,
|
hass=hass,
|
||||||
logger=LOGGER,
|
logger=LOGGER,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_method=self._async_update_version_data,
|
|
||||||
update_interval=UPDATE_COORDINATOR_UPDATE_INTERVAL,
|
update_interval=UPDATE_COORDINATOR_UPDATE_INTERVAL,
|
||||||
)
|
)
|
||||||
self._api = api
|
self._api = api
|
||||||
|
@ -46,7 +45,7 @@ class VersionDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
"""Return the version data."""
|
"""Return the version data."""
|
||||||
return self._version_data or {}
|
return self._version_data or {}
|
||||||
|
|
||||||
async def _async_update_version_data(self) -> None:
|
async def _async_update_data(self) -> None:
|
||||||
"""Update version data."""
|
"""Update version data."""
|
||||||
try:
|
try:
|
||||||
self._version, self._version_data = await self._api.get_version()
|
self._version, self._version_data = await self._api.get_version()
|
||||||
|
|
|
@ -113,7 +113,7 @@ class VersionSensorEntity(CoordinatorEntity, SensorEntity):
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
f"{coordinator.config_entry.unique_id}_{entity_description.key}"
|
f"{coordinator.config_entry.entry_id}_{entity_description.key}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -14,7 +14,6 @@ from homeassistant.components.version.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
@ -55,7 +54,6 @@ async def mock_get_version_update(
|
||||||
|
|
||||||
async def setup_version_integration(hass: HomeAssistant) -> MockConfigEntry:
|
async def setup_version_integration(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Set up the Version integration."""
|
"""Set up the Version integration."""
|
||||||
await async_setup_component(hass, "persistent_notification", {})
|
|
||||||
mock_entry = MockConfigEntry(**MOCK_VERSION_CONFIG_ENTRY_DATA)
|
mock_entry = MockConfigEntry(**MOCK_VERSION_CONFIG_ENTRY_DATA)
|
||||||
mock_entry.add_to_hass(hass)
|
mock_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from pyhaversion.consts import HaVersionChannel, HaVersionSource
|
from pyhaversion.consts import HaVersionChannel, HaVersionSource
|
||||||
|
|
||||||
from homeassistant import config_entries, setup
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.version.const import (
|
from homeassistant.components.version.const import (
|
||||||
CONF_BETA,
|
CONF_BETA,
|
||||||
CONF_BOARD,
|
CONF_BOARD,
|
||||||
|
@ -34,9 +34,10 @@ from tests.components.version.common import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_reload(hass: HomeAssistant):
|
async def test_reload_config_entry(hass: HomeAssistant):
|
||||||
"""Test the Version sensor with different sources."""
|
"""Test reloading the config entry."""
|
||||||
config_entry = await setup_version_integration(hass)
|
config_entry = await setup_version_integration(hass)
|
||||||
|
assert config_entry.state == config_entries.ConfigEntryState.LOADED
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyhaversion.HaVersion.get_version",
|
"pyhaversion.HaVersion.get_version",
|
||||||
|
@ -48,12 +49,10 @@ async def test_reload(hass: HomeAssistant):
|
||||||
|
|
||||||
entry = hass.config_entries.async_get_entry(config_entry.entry_id)
|
entry = hass.config_entries.async_get_entry(config_entry.entry_id)
|
||||||
assert entry.state == config_entries.ConfigEntryState.LOADED
|
assert entry.state == config_entries.ConfigEntryState.LOADED
|
||||||
assert hass.states.get("sensor.local_installation").state == MOCK_VERSION
|
|
||||||
|
|
||||||
|
|
||||||
async def test_basic_form(hass: HomeAssistant) -> None:
|
async def test_basic_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test that we get the form."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": False},
|
context={"source": config_entries.SOURCE_USER, "show_advanced_options": False},
|
||||||
|
@ -82,7 +81,6 @@ async def test_basic_form(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
async def test_advanced_form_pypi(hass: HomeAssistant) -> None:
|
async def test_advanced_form_pypi(hass: HomeAssistant) -> None:
|
||||||
"""Show advanced form when pypi is selected."""
|
"""Show advanced form when pypi is selected."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||||
|
@ -124,7 +122,6 @@ async def test_advanced_form_pypi(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
async def test_advanced_form_container(hass: HomeAssistant) -> None:
|
async def test_advanced_form_container(hass: HomeAssistant) -> None:
|
||||||
"""Show advanced form when container source is selected."""
|
"""Show advanced form when container source is selected."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||||
|
@ -166,7 +163,6 @@ async def test_advanced_form_container(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
async def test_advanced_form_supervisor(hass: HomeAssistant) -> None:
|
async def test_advanced_form_supervisor(hass: HomeAssistant) -> None:
|
||||||
"""Show advanced form when docker source is selected."""
|
"""Show advanced form when docker source is selected."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||||
|
|
|
@ -36,7 +36,6 @@ async def async_setup_sensor_wrapper(
|
||||||
hass: HomeAssistant, config: dict[str, Any]
|
hass: HomeAssistant, config: dict[str, Any]
|
||||||
) -> ConfigEntry:
|
) -> ConfigEntry:
|
||||||
"""Set up the Version sensor platform."""
|
"""Set up the Version sensor platform."""
|
||||||
await async_setup_component(hass, "persistent_notification", {})
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyhaversion.HaVersion.get_version",
|
"pyhaversion.HaVersion.get_version",
|
||||||
return_value=(MOCK_VERSION, MOCK_VERSION_DATA),
|
return_value=(MOCK_VERSION, MOCK_VERSION_DATA),
|
||||||
|
@ -47,7 +46,6 @@ async def async_setup_sensor_wrapper(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
config_entries = hass.config_entries.async_entries(DOMAIN)
|
config_entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
print(config_entries)
|
|
||||||
config_entry = config_entries[-1]
|
config_entry = config_entries[-1]
|
||||||
assert config_entry.source == "import"
|
assert config_entry.source == "import"
|
||||||
return config_entry
|
return config_entry
|
||||||
|
|
Loading…
Add table
Reference in a new issue