* Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
167 lines
5.2 KiB
Python
167 lines
5.2 KiB
Python
"""
|
|
Starts a service to scan in intervals for new devices.
|
|
|
|
Will emit EVENT_PLATFORM_DISCOVERED whenever a new service has been discovered.
|
|
|
|
Knows which components handle certain types, will make sure they are
|
|
loaded before the EVENT_PLATFORM_DISCOVERED is fired.
|
|
"""
|
|
import json
|
|
from datetime import timedelta
|
|
import logging
|
|
import os
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.core import callback
|
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
|
import homeassistant.helpers.config_validation as cv
|
|
from homeassistant.helpers.event import async_track_point_in_utc_time
|
|
from homeassistant.helpers.discovery import async_load_platform, async_discover
|
|
import homeassistant.util.dt as dt_util
|
|
|
|
REQUIREMENTS = ['netdisco==1.3.0']
|
|
|
|
DOMAIN = 'discovery'
|
|
|
|
SCAN_INTERVAL = timedelta(seconds=300)
|
|
SERVICE_NETGEAR = 'netgear_router'
|
|
SERVICE_WEMO = 'belkin_wemo'
|
|
SERVICE_HASS_IOS_APP = 'hass_ios'
|
|
SERVICE_IKEA_TRADFRI = 'ikea_tradfri'
|
|
SERVICE_HASSIO = 'hassio'
|
|
SERVICE_AXIS = 'axis'
|
|
SERVICE_APPLE_TV = 'apple_tv'
|
|
SERVICE_WINK = 'wink'
|
|
SERVICE_XIAOMI_GW = 'xiaomi_gw'
|
|
SERVICE_TELLDUSLIVE = 'tellstick'
|
|
SERVICE_HUE = 'philips_hue'
|
|
SERVICE_DECONZ = 'deconz'
|
|
SERVICE_DAIKIN = 'daikin'
|
|
SERVICE_SAMSUNG_PRINTER = 'samsung_printer'
|
|
|
|
SERVICE_HANDLERS = {
|
|
SERVICE_HASS_IOS_APP: ('ios', None),
|
|
SERVICE_NETGEAR: ('device_tracker', None),
|
|
SERVICE_WEMO: ('wemo', None),
|
|
SERVICE_IKEA_TRADFRI: ('tradfri', None),
|
|
SERVICE_HASSIO: ('hassio', None),
|
|
SERVICE_AXIS: ('axis', None),
|
|
SERVICE_APPLE_TV: ('apple_tv', None),
|
|
SERVICE_WINK: ('wink', None),
|
|
SERVICE_XIAOMI_GW: ('xiaomi_aqara', None),
|
|
SERVICE_TELLDUSLIVE: ('tellduslive', None),
|
|
SERVICE_HUE: ('hue', None),
|
|
SERVICE_DECONZ: ('deconz', None),
|
|
SERVICE_DAIKIN: ('daikin', None),
|
|
SERVICE_SAMSUNG_PRINTER: ('sensor', 'syncthru'),
|
|
'google_cast': ('media_player', 'cast'),
|
|
'panasonic_viera': ('media_player', 'panasonic_viera'),
|
|
'plex_mediaserver': ('media_player', 'plex'),
|
|
'roku': ('media_player', 'roku'),
|
|
'sonos': ('media_player', 'sonos'),
|
|
'yamaha': ('media_player', 'yamaha'),
|
|
'logitech_mediaserver': ('media_player', 'squeezebox'),
|
|
'directv': ('media_player', 'directv'),
|
|
'denonavr': ('media_player', 'denonavr'),
|
|
'samsung_tv': ('media_player', 'samsungtv'),
|
|
'yeelight': ('light', 'yeelight'),
|
|
'frontier_silicon': ('media_player', 'frontier_silicon'),
|
|
'openhome': ('media_player', 'openhome'),
|
|
'harmony': ('remote', 'harmony'),
|
|
'sabnzbd': ('sensor', 'sabnzbd'),
|
|
'bose_soundtouch': ('media_player', 'soundtouch'),
|
|
'bluesound': ('media_player', 'bluesound'),
|
|
'songpal': ('media_player', 'songpal'),
|
|
}
|
|
|
|
CONF_IGNORE = 'ignore'
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
vol.Required(DOMAIN): vol.Schema({
|
|
vol.Optional(CONF_IGNORE, default=[]):
|
|
vol.All(cv.ensure_list, [vol.In(SERVICE_HANDLERS)])
|
|
}),
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
|
async def async_setup(hass, config):
|
|
"""Start a discovery service."""
|
|
from netdisco.discovery import NetworkDiscovery
|
|
|
|
logger = logging.getLogger(__name__)
|
|
netdisco = NetworkDiscovery()
|
|
already_discovered = set()
|
|
|
|
# Disable zeroconf logging, it spams
|
|
logging.getLogger('zeroconf').setLevel(logging.CRITICAL)
|
|
|
|
# Platforms ignore by config
|
|
ignored_platforms = config[DOMAIN][CONF_IGNORE]
|
|
|
|
async def new_service_found(service, info):
|
|
"""Handle a new service if one is found."""
|
|
if service in ignored_platforms:
|
|
logger.info("Ignoring service: %s %s", service, info)
|
|
return
|
|
|
|
comp_plat = SERVICE_HANDLERS.get(service)
|
|
|
|
# We do not know how to handle this service.
|
|
if not comp_plat:
|
|
logger.info("Unknown service discovered: %s %s", service, info)
|
|
return
|
|
|
|
discovery_hash = json.dumps([service, info], sort_keys=True)
|
|
if discovery_hash in already_discovered:
|
|
return
|
|
|
|
already_discovered.add(discovery_hash)
|
|
|
|
logger.info("Found new service: %s %s", service, info)
|
|
|
|
component, platform = comp_plat
|
|
|
|
if platform is None:
|
|
await async_discover(hass, service, info, component, config)
|
|
else:
|
|
await async_load_platform(
|
|
hass, component, platform, info, config)
|
|
|
|
async def scan_devices(now):
|
|
"""Scan for devices."""
|
|
results = await hass.async_add_job(_discover, netdisco)
|
|
|
|
for result in results:
|
|
hass.async_add_job(new_service_found(*result))
|
|
|
|
async_track_point_in_utc_time(hass, scan_devices,
|
|
dt_util.utcnow() + SCAN_INTERVAL)
|
|
|
|
@callback
|
|
def schedule_first(event):
|
|
"""Schedule the first discovery when Home Assistant starts up."""
|
|
async_track_point_in_utc_time(hass, scan_devices, dt_util.utcnow())
|
|
|
|
# discovery local services
|
|
if 'HASSIO' in os.environ:
|
|
hass.async_add_job(new_service_found(SERVICE_HASSIO, {}))
|
|
|
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_first)
|
|
|
|
return True
|
|
|
|
|
|
def _discover(netdisco):
|
|
"""Discover devices."""
|
|
results = []
|
|
try:
|
|
netdisco.scan()
|
|
|
|
for disc in netdisco.discover():
|
|
for service in netdisco.get_info(disc):
|
|
results.append((disc, service))
|
|
finally:
|
|
netdisco.stop()
|
|
|
|
return results
|