add dhcp autodiscovery for levoit-* (#1)

This commit is contained in:
Vincent Le Bourlot 2022-04-01 15:50:18 +02:00 committed by GitHub
parent 49f05780b9
commit f36fc12a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 3 deletions

1
.gitignore vendored
View File

@ -2,4 +2,3 @@
.vscode/** .vscode/**
**/__pycache__/** **/__pycache__/**
Config/** Config/**
custom_components/vesync/__pycache__/sensor.cpython-39.pyc

View File

@ -1,15 +1,20 @@
"""Config flow utilities.""" """Config flow utilities."""
from collections import OrderedDict from collections import OrderedDict
import logging
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import dhcp
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from .const import DOMAIN from .const import DOMAIN
from .pyvesync.vesync import VeSync from .pyvesync.vesync import VeSync
_LOGGER = logging.getLogger(__name__)
class VeSyncFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): class VeSyncFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow.""" """Handle a config flow."""
@ -56,3 +61,11 @@ class VeSyncFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
title=self._username, title=self._username,
data={CONF_USERNAME: self._username, CONF_PASSWORD: self._password}, data={CONF_USERNAME: self._username, CONF_PASSWORD: self._password},
) )
async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
"""Handle DHCP discovery."""
hostname = discovery_info.hostname
_LOGGER.debug("DHCP discovery detected device %s", hostname)
self.context["title_placeholders"] = {"gateway_id": hostname}
return await self.async_step_user()

View File

@ -6,5 +6,11 @@
"config_flow": true, "config_flow": true,
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"version": "0.1.2", "version": "0.1.2",
"issue_tracker": "https://github.com/vlebourl/vesync-bpo" "issue_tracker": "https://github.com/vlebourl/vesync-bpo",
"dhcp": [
{
"hostname": "levoit-*",
"macaddress": "*"
}
]
} }

View File

@ -1,8 +1,10 @@
{ {
"config": { "config": {
"flow_title": "Gateway: {gateway_id}",
"step": { "step": {
"user": { "user": {
"title": "Enter Username and Password", "title": "VeSync Integration for Home Assistant",
"description": "Custom component for Home Assistant to interact with smart devices via the VeSync platform.",
"data": { "data": {
"username": "[%key:common::config_flow::data::email%]", "username": "[%key:common::config_flow::data::email%]",
"password": "[%key:common::config_flow::data::password%]" "password": "[%key:common::config_flow::data::password%]"