hass-core/homeassistant/components/insteon_local.py
Cameron Llewellyn 903cda08b1 Insteon local update (#11088)
* trying to rework device discovery. now the main component will do the getlinked and pass it to the sub-components. no longer any config needed other than what is needed to connect to the hub. device names are no longer stored. core team told us to stop using configurator to ask for names. there should be a way to set names in hass...possibly this https://home-assistant.io/docs/configuration/customizing-devices/

* fix device types

* make device names just be the isnteon device id

* revert some config changes

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* update insteon client

* linting fixes

* Error Clean up

* Update to make requested changes

* more changes

* Finish requested changes to components

* Fixing Rebase Conflicts

* fix device types

* make device names just be the isnteon device id

* revert some config changes

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* Update insteon_local.py

* update insteon client

* linting fixes

* Error Clean up

* Update to make requested changes

* more changes

* Finish requested changes to components

* Update Insteon_Local for performance improvements

* Fix errors from get_linked

* Fix typo

* Requested changes

* Fix spacing

* Clean up

* Requested Changes
2018-01-08 18:18:10 +01:00

89 lines
2.5 KiB
Python

"""
Local support for Insteon.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/insteon_local/
"""
import logging
import os
import requests
import voluptuous as vol
from homeassistant.const import (
CONF_PASSWORD, CONF_USERNAME, CONF_HOST, CONF_PORT, CONF_TIMEOUT)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform
REQUIREMENTS = ['insteonlocal==0.53']
_LOGGER = logging.getLogger(__name__)
DEFAULT_PORT = 25105
DEFAULT_TIMEOUT = 10
DOMAIN = 'insteon_local'
INSTEON_CACHE = '.insteon_local_cache'
INSTEON_PLATFORMS = [
'light',
'switch',
'fan',
]
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int
})
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config):
"""Setup insteon hub."""
from insteonlocal.Hub import Hub
conf = config[DOMAIN]
username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)
host = conf.get(CONF_HOST)
port = conf.get(CONF_PORT)
timeout = conf.get(CONF_TIMEOUT)
try:
if not os.path.exists(hass.config.path(INSTEON_CACHE)):
os.makedirs(hass.config.path(INSTEON_CACHE))
insteonhub = Hub(host, username, password, port, timeout, _LOGGER,
hass.config.path(INSTEON_CACHE))
# Check for successful connection
insteonhub.get_buffer_status()
except requests.exceptions.ConnectTimeout:
_LOGGER.error(
"Could not connect. Check config",
exc_info=True)
return False
except requests.exceptions.ConnectionError:
_LOGGER.error(
"Could not connect. Check config",
exc_info=True)
return False
except requests.exceptions.RequestException:
if insteonhub.http_code == 401:
_LOGGER.error("Bad user/pass for insteon_local hub")
else:
_LOGGER.error("Error on insteon_local hub check", exc_info=True)
return False
linked = insteonhub.get_linked()
hass.data['insteon_local'] = insteonhub
for insteon_platform in INSTEON_PLATFORMS:
load_platform(hass, insteon_platform, DOMAIN, {'linked': linked},
config)
return True