Compare commits

..

2 commits

Author SHA1 Message Date
epenet
bf207f6135 Ignore fake_integration in repairs 2024-11-14 15:28:07 +00:00
epenet
5192aa52bf Add translation checks for repair flows 2024-11-14 15:28:07 +00:00
5 changed files with 64 additions and 54 deletions

View file

@ -515,7 +515,7 @@ async def async_from_config_dict(
issue_registry.async_create_issue( issue_registry.async_create_issue(
hass, hass,
core.DOMAIN, core.DOMAIN,
f"python_version_{required_python_version}", "python_version",
is_fixable=False, is_fixable=False,
severity=issue_registry.IssueSeverity.WARNING, severity=issue_registry.IssueSeverity.WARNING,
breaks_in_ha_version=REQUIRED_NEXT_PYTHON_HA_RELEASE, breaks_in_ha_version=REQUIRED_NEXT_PYTHON_HA_RELEASE,

View file

@ -1,5 +1,5 @@
# serializer version: 1 # serializer version: 1
# name: test_buttons[button.lunar_ddeeff_reset_timer-entry] # name: test_buttons[entry_button_reset_timer]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -32,20 +32,7 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_buttons[button.lunar_ddeeff_reset_timer-state] # name: test_buttons[entry_button_start_stop_timer]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'LUNAR-DDEEFF Reset timer',
}),
'context': <ANY>,
'entity_id': 'button.lunar_ddeeff_reset_timer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_buttons[button.lunar_ddeeff_start_stop_timer-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -78,20 +65,7 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_buttons[button.lunar_ddeeff_start_stop_timer-state] # name: test_buttons[entry_button_tare]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'LUNAR-DDEEFF Start/stop timer',
}),
'context': <ANY>,
'entity_id': 'button.lunar_ddeeff_start_stop_timer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_buttons[button.lunar_ddeeff_tare-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -124,7 +98,33 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_buttons[button.lunar_ddeeff_tare-state] # name: test_buttons[state_button_reset_timer]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'LUNAR-DDEEFF Reset timer',
}),
'context': <ANY>,
'entity_id': 'button.lunar_ddeeff_reset_timer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_buttons[state_button_start_stop_timer]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'LUNAR-DDEEFF Start/stop timer',
}),
'context': <ANY>,
'entity_id': 'button.lunar_ddeeff_start_stop_timer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_buttons[state_button_tare]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'LUNAR-DDEEFF Tare', 'friendly_name': 'LUNAR-DDEEFF Tare',

View file

@ -1,24 +1,21 @@
"""Tests for the acaia buttons.""" """Tests for the acaia buttons."""
from datetime import timedelta from datetime import timedelta
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.const import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, STATE_UNKNOWN
ATTR_ENTITY_ID,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from . import setup_integration from tests.common import async_fire_time_changed
pytestmark = pytest.mark.usefixtures("init_integration")
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
BUTTONS = ( BUTTONS = (
"tare", "tare",
@ -31,25 +28,24 @@ async def test_buttons(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
mock_scale: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None: ) -> None:
"""Test the acaia buttons.""" """Test the acaia buttons."""
for button in BUTTONS:
state = hass.states.get(f"button.lunar_ddeeff_{button}")
assert state
assert state == snapshot(name=f"state_button_{button}")
with patch("homeassistant.components.acaia.PLATFORMS", [Platform.BUTTON]): entry = entity_registry.async_get(state.entity_id)
await setup_integration(hass, mock_config_entry) assert entry
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) assert entry == snapshot(name=f"entry_button_{button}")
async def test_button_presses( async def test_button_presses(
hass: HomeAssistant, hass: HomeAssistant,
mock_scale: MagicMock, mock_scale: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None: ) -> None:
"""Test the acaia button presses.""" """Test the acaia button presses."""
await setup_integration(hass, mock_config_entry)
for button in BUTTONS: for button in BUTTONS:
await hass.services.async_call( await hass.services.async_call(
BUTTON_DOMAIN, BUTTON_DOMAIN,
@ -67,13 +63,10 @@ async def test_button_presses(
async def test_buttons_unavailable_on_disconnected_scale( async def test_buttons_unavailable_on_disconnected_scale(
hass: HomeAssistant, hass: HomeAssistant,
mock_scale: MagicMock, mock_scale: MagicMock,
mock_config_entry: MockConfigEntry,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Test the acaia buttons are unavailable when the scale is disconnected.""" """Test the acaia buttons are unavailable when the scale is disconnected."""
await setup_integration(hass, mock_config_entry)
for button in BUTTONS: for button in BUTTONS:
state = hass.states.get(f"button.lunar_ddeeff_{button}") state = hass.states.get(f"button.lunar_ddeeff_{button}")
assert state assert state

View file

@ -18,6 +18,7 @@ from aiohasupervisor.models import (
) )
import pytest import pytest
from homeassistant.components import repairs
from homeassistant.config_entries import ( from homeassistant.config_entries import (
DISCOVERY_SOURCES, DISCOVERY_SOURCES,
ConfigEntriesFlowManager, ConfigEntriesFlowManager,
@ -32,6 +33,7 @@ from homeassistant.data_entry_flow import (
FlowManager, FlowManager,
FlowResultType, FlowResultType,
) )
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.translation import async_get_translations from homeassistant.helpers.translation import async_get_translations
if TYPE_CHECKING: if TYPE_CHECKING:
@ -615,12 +617,23 @@ async def _check_config_flow_result_translations(
result: FlowResult[FlowContext, str], result: FlowResult[FlowContext, str],
ignore_translations: dict[str, str], ignore_translations: dict[str, str],
) -> None: ) -> None:
if result["type"] is FlowResultType.CREATE_ENTRY:
# No need to check translations for a completed flow
return
key_prefix = ""
if isinstance(manager, ConfigEntriesFlowManager): if isinstance(manager, ConfigEntriesFlowManager):
category = "config" category = "config"
integration = flow.handler integration = flow.handler
elif isinstance(manager, OptionsFlowManager): elif isinstance(manager, OptionsFlowManager):
category = "options" category = "options"
integration = flow.hass.config_entries.async_get_entry(flow.handler).domain integration = flow.hass.config_entries.async_get_entry(flow.handler).domain
elif isinstance(manager, repairs.RepairsFlowManager):
category = "issues"
integration = flow.handler
issue_id = flow.issue_id
issue = ir.async_get(flow.hass).async_get_issue(integration, issue_id)
key_prefix = f"{issue.translation_key}.fix_flow."
else: else:
return return
@ -639,7 +652,7 @@ async def _check_config_flow_result_translations(
ignore_translations, ignore_translations,
category, category,
integration, integration,
f"step.{step_id}.{header}", f"{key_prefix}step.{step_id}.{header}",
result["description_placeholders"], result["description_placeholders"],
translation_required=False, translation_required=False,
) )
@ -650,7 +663,7 @@ async def _check_config_flow_result_translations(
ignore_translations, ignore_translations,
category, category,
integration, integration,
f"error.{error}", f"{key_prefix}error.{error}",
result["description_placeholders"], result["description_placeholders"],
) )
return return
@ -665,7 +678,7 @@ async def _check_config_flow_result_translations(
ignore_translations, ignore_translations,
category, category,
integration, integration,
f"abort.{result["reason"]}", f"{key_prefix}abort.{result["reason"]}",
result["description_placeholders"], result["description_placeholders"],
) )

View file

@ -533,6 +533,10 @@ async def test_list_issues(
} }
@pytest.mark.parametrize(
"ignore_translations",
["component.fake_integration.issues.abc_123.fix_flow.abort.not_given"],
)
async def test_fix_issue_aborted( async def test_fix_issue_aborted(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,