* Added localip component * Split config and core logic, and migrate to sensor platform (requested by @MartinHjelmare) Also allow overriding the sensor name via the config * Tweak docstring Co-Authored-By: Fabian Affolter <mail@fabian-affolter.ch> * Initial support for config entries * Rename localip to local_ip (1/2) * Rename localip to local_ip (2/2) * Add test for config_flow * Split and rename tests * Remove unneeded code from config_flow * Implement configuration as config entry import. Other misc requested changes from code review. * Fix tests * minor code review fixes * remove unneeded code Co-authored-by: Fabian Affolter <mail@fabian-affolter.ch>
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
"""Config flow for local_ip."""
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from . import DOMAIN
|
|
|
|
|
|
class SimpleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|
"""Handle a config flow for local_ip."""
|
|
|
|
VERSION = 1
|
|
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
|
|
|
|
async def async_step_user(self, user_input=None):
|
|
"""Handle the initial step."""
|
|
if user_input is not None:
|
|
if any(
|
|
user_input["name"] == entry.data["name"]
|
|
for entry in self._async_current_entries()
|
|
):
|
|
return self.async_abort(reason="already_configured")
|
|
|
|
return self.async_create_entry(title=user_input["name"], data=user_input)
|
|
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=vol.Schema({vol.Required("name", default=DOMAIN): str}),
|
|
errors={},
|
|
)
|
|
|
|
async def async_step_import(self, import_info):
|
|
"""Handle import from config file."""
|
|
return await self.async_step_user(import_info)
|