Add wiffi integration (#30784)
* Add integration for wiffi devices wiffi devices are DIY board manufactured by stall.biz. Several devices are available, e.g. a weather station (weatherman), an indoor environmental sensor (wiffi-wz) and some more. This intgration has been developed using a weatherman device, but should also work for other devices from stall.biz. * Fix pylint warning * Use WIFFI / STALL WIFFI instead of wiffi to be consistent with stall.biz * Don't update disabled entities. * fix complains - move wiffi specific code to pypi - remove yaml configuration code * incorporate various suggestions from code review * fix remaining comments from Martin * fix comments * add tests for config flow * fix comments * add missing requirements for tests * fix pylint warnings * fix comments * fix comments remove debug log rename .translations to translations * rebase and adapt to latest dev branch * Update homeassistant/components/wiffi/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/wiffi/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fix missing import Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
6464c94990
commit
ee96ff2846
16 changed files with 647 additions and 0 deletions
57
homeassistant/components/wiffi/config_flow.py
Normal file
57
homeassistant/components/wiffi/config_flow.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
"""Config flow for wiffi component.
|
||||
|
||||
Used by UI to setup a wiffi integration.
|
||||
"""
|
||||
import errno
|
||||
|
||||
import voluptuous as vol
|
||||
from wiffi import WiffiTcpServer
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_PORT
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .const import DEFAULT_PORT, DOMAIN # pylint: disable=unused-import
|
||||
|
||||
|
||||
class WiffiFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Wiffi server setup config flow."""
|
||||
|
||||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle the start of the config flow.
|
||||
|
||||
Called after wiffi integration has been selected in the 'add integration
|
||||
UI'. The user_input is set to None in this case. We will open a config
|
||||
flow form then.
|
||||
This function is also called if the form has been submitted. user_input
|
||||
contains a dict with the user entered values then.
|
||||
"""
|
||||
if user_input is None:
|
||||
return self._async_show_form()
|
||||
|
||||
# received input from form or configuration.yaml
|
||||
|
||||
try:
|
||||
# try to start server to check whether port is in use
|
||||
server = WiffiTcpServer(user_input[CONF_PORT])
|
||||
await server.start_server()
|
||||
await server.close_server()
|
||||
return self.async_create_entry(
|
||||
title=f"Port {user_input[CONF_PORT]}", data=user_input
|
||||
)
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EADDRINUSE:
|
||||
return self.async_abort(reason="addr_in_use")
|
||||
return self.async_abort(reason="start_server_failed")
|
||||
|
||||
@callback
|
||||
def _async_show_form(self, errors=None):
|
||||
"""Show the config flow form to the user."""
|
||||
data_schema = {vol.Required(CONF_PORT, default=DEFAULT_PORT): int}
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=vol.Schema(data_schema), errors=errors or {}
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue