From f36fc12a738fac3bd56171a399de02bcb8363d9e Mon Sep 17 00:00:00 2001 From: Vincent Le Bourlot Date: Fri, 1 Apr 2022 15:50:18 +0200 Subject: [PATCH] add dhcp autodiscovery for levoit-* (#1) --- .gitignore | 1 - custom_components/vesync/config_flow.py | 13 +++++++++++++ custom_components/vesync/manifest.json | 8 +++++++- custom_components/vesync/strings.json | 4 +++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2157f57..43030cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ .vscode/** **/__pycache__/** Config/** -custom_components/vesync/__pycache__/sensor.cpython-39.pyc diff --git a/custom_components/vesync/config_flow.py b/custom_components/vesync/config_flow.py index 30e4b98..b697e93 100644 --- a/custom_components/vesync/config_flow.py +++ b/custom_components/vesync/config_flow.py @@ -1,15 +1,20 @@ """Config flow utilities.""" from collections import OrderedDict +import logging import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import dhcp from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import callback +from homeassistant.data_entry_flow import FlowResult from .const import DOMAIN from .pyvesync.vesync import VeSync +_LOGGER = logging.getLogger(__name__) + class VeSyncFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow.""" @@ -56,3 +61,11 @@ class VeSyncFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): title=self._username, 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() diff --git a/custom_components/vesync/manifest.json b/custom_components/vesync/manifest.json index fc99254..8cd514d 100644 --- a/custom_components/vesync/manifest.json +++ b/custom_components/vesync/manifest.json @@ -6,5 +6,11 @@ "config_flow": true, "iot_class": "cloud_polling", "version": "0.1.2", - "issue_tracker": "https://github.com/vlebourl/vesync-bpo" + "issue_tracker": "https://github.com/vlebourl/vesync-bpo", + "dhcp": [ + { + "hostname": "levoit-*", + "macaddress": "*" + } + ] } diff --git a/custom_components/vesync/strings.json b/custom_components/vesync/strings.json index 8359691..8c8ed7e 100644 --- a/custom_components/vesync/strings.json +++ b/custom_components/vesync/strings.json @@ -1,8 +1,10 @@ { "config": { + "flow_title": "Gateway: {gateway_id}", "step": { "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": { "username": "[%key:common::config_flow::data::email%]", "password": "[%key:common::config_flow::data::password%]"