mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use common strings in luftdaten config flow (#42376)
This commit is contained in:
parent
e6400fc11b
commit
cbf6086c30
@ -69,7 +69,7 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow):
|
|||||||
sensor_id = user_input[CONF_SENSOR_ID]
|
sensor_id = user_input[CONF_SENSOR_ID]
|
||||||
|
|
||||||
if sensor_id in configured_sensors(self.hass):
|
if sensor_id in configured_sensors(self.hass):
|
||||||
return self._show_form({CONF_SENSOR_ID: "sensor_exists"})
|
return self._show_form({CONF_SENSOR_ID: "already_configured"})
|
||||||
|
|
||||||
session = aiohttp_client.async_get_clientsession(self.hass)
|
session = aiohttp_client.async_get_clientsession(self.hass)
|
||||||
luftdaten = Luftdaten(user_input[CONF_SENSOR_ID], self.hass.loop, session)
|
luftdaten = Luftdaten(user_input[CONF_SENSOR_ID], self.hass.loop, session)
|
||||||
@ -77,7 +77,7 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow):
|
|||||||
await luftdaten.get_data()
|
await luftdaten.get_data()
|
||||||
valid = await luftdaten.validate_sensor()
|
valid = await luftdaten.validate_sensor()
|
||||||
except LuftdatenConnectionError:
|
except LuftdatenConnectionError:
|
||||||
return self._show_form({CONF_SENSOR_ID: "communication_error"})
|
return self._show_form({CONF_SENSOR_ID: "cannot_connect"})
|
||||||
|
|
||||||
if not valid:
|
if not valid:
|
||||||
return self._show_form({CONF_SENSOR_ID: "invalid_sensor"})
|
return self._show_form({CONF_SENSOR_ID: "invalid_sensor"})
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"sensor_exists": "Sensor already registered",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||||
"invalid_sensor": "Sensor not available or invalid",
|
"invalid_sensor": "Sensor not available or invalid",
|
||||||
"communication_error": "Unable to communicate with the Luftdaten API"
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ async def test_duplicate_error(hass):
|
|||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
result = await flow.async_step_user(user_input=conf)
|
result = await flow.async_step_user(user_input=conf)
|
||||||
assert result["errors"] == {CONF_SENSOR_ID: "sensor_exists"}
|
assert result["errors"] == {CONF_SENSOR_ID: "already_configured"}
|
||||||
|
|
||||||
|
|
||||||
async def test_communication_error(hass):
|
async def test_communication_error(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user