Use common strings in luftdaten config flow (#42376)

This commit is contained in:
springstan 2020-10-25 23:40:12 +01:00 committed by GitHub
parent e6400fc11b
commit cbf6086c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -69,7 +69,7 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow):
sensor_id = user_input[CONF_SENSOR_ID]
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)
luftdaten = Luftdaten(user_input[CONF_SENSOR_ID], self.hass.loop, session)
@ -77,7 +77,7 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow):
await luftdaten.get_data()
valid = await luftdaten.validate_sensor()
except LuftdatenConnectionError:
return self._show_form({CONF_SENSOR_ID: "communication_error"})
return self._show_form({CONF_SENSOR_ID: "cannot_connect"})
if not valid:
return self._show_form({CONF_SENSOR_ID: "invalid_sensor"})

View file

@ -10,9 +10,9 @@
}
},
"error": {
"sensor_exists": "Sensor already registered",
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
"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%]"
}
}
}

View file

@ -19,7 +19,7 @@ async def test_duplicate_error(hass):
flow.hass = hass
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):