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:
Joakim Sørensen 2022-01-03 13:30:40 +01:00 committed by GitHub
parent 06ebbb7cae
commit 56bda80e0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 28 deletions

View file

@ -9,7 +9,6 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_NAME, CONF_SOURCE
from homeassistant.data_entry_flow import FlowResult
from homeassistant.util import slugify
from .const import (
ATTR_VERSION_SOURCE,
@ -47,10 +46,12 @@ from .const import (
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Version."""
_entry_data: dict[str, Any] = DEFAULT_CONFIGURATION.copy()
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(
self,
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."""
self._entry_data = _convert_imported_configuration(import_config)
for entry in self._async_current_entries():
if _fingerprint(entry.data) == _fingerprint(self._entry_data):
return self.async_abort(reason="already_configured")
self._async_abort_entries_match({**DEFAULT_CONFIGURATION, **self._entry_data})
return self.async_create_entry(
title=self._config_entry_name, data=self._entry_data
@ -163,12 +162,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
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:
"""Convert a key from the imported configuration."""
data = DEFAULT_CONFIGURATION.copy()

View file

@ -29,7 +29,6 @@ class VersionDataUpdateCoordinator(DataUpdateCoordinator):
hass=hass,
logger=LOGGER,
name=DOMAIN,
update_method=self._async_update_version_data,
update_interval=UPDATE_COORDINATOR_UPDATE_INTERVAL,
)
self._api = api
@ -46,7 +45,7 @@ class VersionDataUpdateCoordinator(DataUpdateCoordinator):
"""Return the version data."""
return self._version_data or {}
async def _async_update_version_data(self) -> None:
async def _async_update_data(self) -> None:
"""Update version data."""
try:
self._version, self._version_data = await self._api.get_version()

View file

@ -113,7 +113,7 @@ class VersionSensorEntity(CoordinatorEntity, SensorEntity):
super().__init__(coordinator)
self.entity_description = entity_description
self._attr_unique_id = (
f"{coordinator.config_entry.unique_id}_{entity_description.key}"
f"{coordinator.config_entry.entry_id}_{entity_description.key}"
)
@property

View file

@ -14,7 +14,6 @@ from homeassistant.components.version.const import (
)
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util import dt
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:
"""Set up the Version integration."""
await async_setup_component(hass, "persistent_notification", {})
mock_entry = MockConfigEntry(**MOCK_VERSION_CONFIG_ENTRY_DATA)
mock_entry.add_to_hass(hass)

View file

@ -3,7 +3,7 @@ from unittest.mock import patch
from pyhaversion.consts import HaVersionChannel, HaVersionSource
from homeassistant import config_entries, setup
from homeassistant import config_entries
from homeassistant.components.version.const import (
CONF_BETA,
CONF_BOARD,
@ -34,9 +34,10 @@ from tests.components.version.common import (
)
async def test_reload(hass: HomeAssistant):
"""Test the Version sensor with different sources."""
async def test_reload_config_entry(hass: HomeAssistant):
"""Test reloading the config entry."""
config_entry = await setup_version_integration(hass)
assert config_entry.state == config_entries.ConfigEntryState.LOADED
with patch(
"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)
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:
"""Test we get the form."""
await setup.async_setup_component(hass, "persistent_notification", {})
"""Test that we get the form."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
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:
"""Show advanced form when pypi is selected."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN,
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:
"""Show advanced form when container source is selected."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN,
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:
"""Show advanced form when docker source is selected."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},

View file

@ -36,7 +36,6 @@ async def async_setup_sensor_wrapper(
hass: HomeAssistant, config: dict[str, Any]
) -> ConfigEntry:
"""Set up the Version sensor platform."""
await async_setup_component(hass, "persistent_notification", {})
with patch(
"pyhaversion.HaVersion.get_version",
return_value=(MOCK_VERSION, MOCK_VERSION_DATA),
@ -47,7 +46,6 @@ async def async_setup_sensor_wrapper(
await hass.async_block_till_done()
config_entries = hass.config_entries.async_entries(DOMAIN)
print(config_entries)
config_entry = config_entries[-1]
assert config_entry.source == "import"
return config_entry