Update Fronius translations (#132876)

* Remove exception translation that's handled by configflow errors dict

* Remove entity name translations handled by device class

* Add data_description for Fronius config flow

* Remove unnecessary exception case

* review suggestion
This commit is contained in:
Matthias Alphart 2024-12-14 21:47:27 +01:00 committed by GitHub
parent 4dc1405e99
commit 74aa1a8f7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 55 deletions

View File

@ -52,14 +52,9 @@ async def validate_host(
try:
inverter_info = await fronius.inverter_info()
first_inverter = next(inverter for inverter in inverter_info["inverters"])
except FroniusError as err:
except (FroniusError, StopIteration) as err:
_LOGGER.debug(err)
raise CannotConnect from err
except StopIteration as err:
raise CannotConnect(
translation_domain=DOMAIN,
translation_key="no_supported_device_found",
) from err
first_inverter_uid: str = first_inverter["unique_id"]["value"]
return first_inverter_uid, FroniusConfigEntryData(
host=host,

View File

@ -3,10 +3,12 @@
"flow_title": "{device}",
"step": {
"user": {
"title": "Fronius SolarNet",
"description": "Configure the IP address or local hostname of your Fronius device.",
"description": "Configure your Fronius SolarAPI device.",
"data": {
"host": "[%key:common::config_flow::data::host%]"
},
"data_description": {
"host": "The IP address or hostname of your Fronius device."
}
},
"confirm_discovery": {
@ -41,9 +43,6 @@
"energy_total": {
"name": "Total energy"
},
"frequency_ac": {
"name": "[%key:component::sensor::entity_component::frequency::name%]"
},
"current_ac": {
"name": "AC current"
},
@ -156,9 +155,6 @@
"power_apparent_phase_3": {
"name": "Apparent power phase 3"
},
"power_apparent": {
"name": "[%key:component::sensor::entity_component::apparent_power::name%]"
},
"power_factor_phase_1": {
"name": "Power factor phase 1"
},
@ -168,9 +164,6 @@
"power_factor_phase_3": {
"name": "Power factor phase 3"
},
"power_factor": {
"name": "[%key:component::sensor::entity_component::power_factor::name%]"
},
"power_reactive_phase_1": {
"name": "Reactive power phase 1"
},
@ -216,12 +209,6 @@
"energy_real_ac_consumed": {
"name": "Energy consumed"
},
"power_real_ac": {
"name": "[%key:component::sensor::entity_component::power::name%]"
},
"temperature_channel_1": {
"name": "[%key:component::sensor::entity_component::temperature::name%]"
},
"state_code": {
"name": "State code"
},
@ -296,9 +283,6 @@
}
},
"exceptions": {
"no_supported_device_found": {
"message": "No supported Fronius SolarNet device found."
},
"entry_cannot_connect": {
"message": "Failed to connect to Fronius device at {host}: {fronius_error}"
},

View File

@ -118,8 +118,18 @@ async def test_form_with_inverter(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
"inverter_side_effect",
[
FroniusError,
None, # raises StopIteration through INVERTER_INFO_NONE
],
)
async def test_form_cannot_connect(
hass: HomeAssistant, inverter_side_effect: type[FroniusError] | None
) -> None:
"""Test we handle cannot connect error."""
INVERTER_INFO_NONE: dict[str, list] = {"inverters": []}
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
@ -131,34 +141,8 @@ async def test_form_cannot_connect(hass: HomeAssistant) -> None:
),
patch(
"pyfronius.Fronius.inverter_info",
side_effect=FroniusError,
),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"host": "1.1.1.1",
},
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_no_device(hass: HomeAssistant) -> None:
"""Test we handle no device found error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with (
patch(
"pyfronius.Fronius.current_logger_info",
side_effect=FroniusError,
),
patch(
"pyfronius.Fronius.inverter_info",
return_value={"inverters": []},
side_effect=inverter_side_effect,
return_value=INVERTER_INFO_NONE,
),
):
result2 = await hass.config_entries.flow.async_configure(