Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SERVICE_AXIS = 'axis'
SERVICE_APPLE_TV = 'apple_tv'
SERVICE_WINK = 'wink'
SERVICE_XIAOMI_GW = 'xiaomi_gw'

SERVICE_HANDLERS = {
SERVICE_HASS_IOS_APP: ('ios', None),
Expand All @@ -44,6 +45,7 @@
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'),
Expand Down
21 changes: 17 additions & 4 deletions homeassistant/components/xiaomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
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']

Expand Down Expand Up @@ -57,9 +57,22 @@ def _validate_conf(config):

def setup(hass, config):
"""Set up the Xiaomi component."""
gateways = config[DOMAIN][CONF_GATEWAYS]
interface = config[DOMAIN][CONF_INTERFACE]
discovery_retry = config[DOMAIN][CONF_DISCOVERY_RETRY]
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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see the lint warning (C: 68, 4: Missing function docstring (missing-docstring))? Please just add the docstring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"""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,
Expand Down