mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
components/xiaomi: Add initial discovery using NetDisco. (#9283)
There's a kind of duplication of functionality between NetDisco and "xiaomi" component, the latter features its own "discovery" in addition to general HomeAssistant discovery service, based on NetDisco. As such, this patch is pretty simple: the only purpose of NetDisco discovery is "plug and play", "zero configuration" discovery that Xiaomi Gateway device is present on the local network, and triggering of "xiaomi" component loading, which then "rediscovers" the gateway using its own method.
This commit is contained in:
parent
2c8967d0d5
commit
d90801f6dd
@ -34,6 +34,7 @@ SERVICE_HASSIO = 'hassio'
|
||||
SERVICE_AXIS = 'axis'
|
||||
SERVICE_APPLE_TV = 'apple_tv'
|
||||
SERVICE_WINK = 'wink'
|
||||
SERVICE_XIAOMI_GW = 'xiaomi_gw'
|
||||
|
||||
SERVICE_HANDLERS = {
|
||||
SERVICE_HASS_IOS_APP: ('ios', None),
|
||||
@ -44,6 +45,7 @@ SERVICE_HANDLERS = {
|
||||
SERVICE_AXIS: ('axis', None),
|
||||
SERVICE_APPLE_TV: ('apple_tv', None),
|
||||
SERVICE_WINK: ('wink', None),
|
||||
SERVICE_XIAOMI_GW: ('xiaomi', None),
|
||||
'philips_hue': ('light', 'hue'),
|
||||
'google_cast': ('media_player', 'cast'),
|
||||
'panasonic_viera': ('media_player', 'panasonic_viera'),
|
||||
|
@ -4,10 +4,10 @@ import voluptuous as vol
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.components.discovery import SERVICE_XIAOMI_GW
|
||||
from homeassistant.const import (ATTR_BATTERY_LEVEL, EVENT_HOMEASSISTANT_STOP,
|
||||
CONF_MAC)
|
||||
|
||||
|
||||
REQUIREMENTS = ['https://github.com/Danielhiversen/PyXiaomiGateway/archive/'
|
||||
'0.3.2.zip#PyXiaomiGateway==0.3.2']
|
||||
|
||||
@ -57,10 +57,23 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Xiaomi component."""
|
||||
gateways = []
|
||||
interface = 'any'
|
||||
discovery_retry = 3
|
||||
if DOMAIN in config:
|
||||
gateways = config[DOMAIN][CONF_GATEWAYS]
|
||||
interface = config[DOMAIN][CONF_INTERFACE]
|
||||
discovery_retry = config[DOMAIN][CONF_DISCOVERY_RETRY]
|
||||
|
||||
def xiaomi_gw_discovered(service, discovery_info):
|
||||
"""Called when Xiaomi Gateway device(s) has been found."""
|
||||
# We don't need to do anything here, the purpose of HA's
|
||||
# discovery service is to just trigger loading of this
|
||||
# component, and then its own discovery process kicks in.
|
||||
_LOGGER.info("Discovered: %s", discovery_info)
|
||||
|
||||
discovery.listen(hass, SERVICE_XIAOMI_GW, xiaomi_gw_discovered)
|
||||
|
||||
from PyXiaomiGateway import PyXiaomiGateway
|
||||
hass.data[PY_XIAOMI_GATEWAY] = PyXiaomiGateway(hass.add_job, gateways,
|
||||
interface)
|
||||
|
Loading…
x
Reference in New Issue
Block a user