mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Support for Wink local control (#8607)
* Support for Wink local control
This commit is contained in:
parent
e8ce41874c
commit
1b57566e8e
@ -25,7 +25,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['python-wink==1.3.1', 'pubnubsub-handler==1.0.2']
|
REQUIREMENTS = ['python-wink==1.4.2', 'pubnubsub-handler==1.0.2']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -36,10 +36,10 @@ SUBSCRIPTION_HANDLER = None
|
|||||||
CONF_CLIENT_ID = 'client_id'
|
CONF_CLIENT_ID = 'client_id'
|
||||||
CONF_CLIENT_SECRET = 'client_secret'
|
CONF_CLIENT_SECRET = 'client_secret'
|
||||||
CONF_USER_AGENT = 'user_agent'
|
CONF_USER_AGENT = 'user_agent'
|
||||||
CONF_OATH = 'oath'
|
CONF_OAUTH = 'oauth'
|
||||||
|
CONF_LOCAL_CONTROL = 'local_control'
|
||||||
CONF_APPSPOT = 'appspot'
|
CONF_APPSPOT = 'appspot'
|
||||||
CONF_DEFINED_BOTH_MSG = 'Remove access token to use oath2.'
|
CONF_MISSING_OAUTH_MSG = 'Missing oauth2 credentials.'
|
||||||
CONF_MISSING_OATH_MSG = 'Missing oath2 credentials.'
|
|
||||||
CONF_TOKEN_URL = "https://winkbearertoken.appspot.com/token"
|
CONF_TOKEN_URL = "https://winkbearertoken.appspot.com/token"
|
||||||
|
|
||||||
ATTR_ACCESS_TOKEN = 'access_token'
|
ATTR_ACCESS_TOKEN = 'access_token'
|
||||||
@ -64,15 +64,14 @@ SERVICE_KEEP_ALIVE = 'keep_pubnub_updates_flowing'
|
|||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Inclusive(CONF_EMAIL, CONF_APPSPOT,
|
vol.Inclusive(CONF_EMAIL, CONF_APPSPOT,
|
||||||
msg=CONF_MISSING_OATH_MSG): cv.string,
|
msg=CONF_MISSING_OAUTH_MSG): cv.string,
|
||||||
vol.Inclusive(CONF_PASSWORD, CONF_APPSPOT,
|
vol.Inclusive(CONF_PASSWORD, CONF_APPSPOT,
|
||||||
msg=CONF_MISSING_OATH_MSG): cv.string,
|
msg=CONF_MISSING_OAUTH_MSG): cv.string,
|
||||||
vol.Inclusive(CONF_CLIENT_ID, CONF_OATH,
|
vol.Inclusive(CONF_CLIENT_ID, CONF_OAUTH,
|
||||||
msg=CONF_MISSING_OATH_MSG): cv.string,
|
msg=CONF_MISSING_OAUTH_MSG): cv.string,
|
||||||
vol.Inclusive(CONF_CLIENT_SECRET, CONF_OATH,
|
vol.Inclusive(CONF_CLIENT_SECRET, CONF_OAUTH,
|
||||||
msg=CONF_MISSING_OATH_MSG): cv.string,
|
msg=CONF_MISSING_OAUTH_MSG): cv.string,
|
||||||
vol.Exclusive(CONF_EMAIL, CONF_OATH,
|
vol.Optional(CONF_LOCAL_CONTROL, default=False): cv.boolean
|
||||||
msg=CONF_DEFINED_BOTH_MSG): cv.string,
|
|
||||||
})
|
})
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
@ -206,8 +205,11 @@ def setup(hass, config):
|
|||||||
client_secret = config[DOMAIN].get(ATTR_CLIENT_SECRET)
|
client_secret = config[DOMAIN].get(ATTR_CLIENT_SECRET)
|
||||||
email = config[DOMAIN].get(CONF_EMAIL)
|
email = config[DOMAIN].get(CONF_EMAIL)
|
||||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
password = config[DOMAIN].get(CONF_PASSWORD)
|
||||||
|
local_control = config[DOMAIN].get(CONF_LOCAL_CONTROL)
|
||||||
if None not in [client_id, client_secret]:
|
if None not in [client_id, client_secret]:
|
||||||
_LOGGER.info("Using legacy oauth authentication")
|
_LOGGER.info("Using legacy oauth authentication")
|
||||||
|
if not local_control:
|
||||||
|
pywink.disable_local_control()
|
||||||
hass.data[DOMAIN]["oauth"]["client_id"] = client_id
|
hass.data[DOMAIN]["oauth"]["client_id"] = client_id
|
||||||
hass.data[DOMAIN]["oauth"]["client_secret"] = client_secret
|
hass.data[DOMAIN]["oauth"]["client_secret"] = client_secret
|
||||||
hass.data[DOMAIN]["oauth"]["email"] = email
|
hass.data[DOMAIN]["oauth"]["email"] = email
|
||||||
@ -216,11 +218,14 @@ def setup(hass, config):
|
|||||||
client_id, client_secret)
|
client_id, client_secret)
|
||||||
elif None not in [email, password]:
|
elif None not in [email, password]:
|
||||||
_LOGGER.info("Using web form authentication")
|
_LOGGER.info("Using web form authentication")
|
||||||
|
pywink.disable_local_control()
|
||||||
hass.data[DOMAIN]["oauth"]["email"] = email
|
hass.data[DOMAIN]["oauth"]["email"] = email
|
||||||
hass.data[DOMAIN]["oauth"]["password"] = password
|
hass.data[DOMAIN]["oauth"]["password"] = password
|
||||||
_get_wink_token_from_web()
|
_get_wink_token_from_web()
|
||||||
else:
|
else:
|
||||||
_LOGGER.info("Using new oauth authentication")
|
_LOGGER.info("Using new oauth authentication")
|
||||||
|
if not local_control:
|
||||||
|
pywink.disable_local_control()
|
||||||
config_path = hass.config.path(WINK_CONFIG_FILE)
|
config_path = hass.config.path(WINK_CONFIG_FILE)
|
||||||
if os.path.isfile(config_path):
|
if os.path.isfile(config_path):
|
||||||
config_file = _read_config_file(config_path)
|
config_file = _read_config_file(config_path)
|
||||||
@ -304,6 +309,15 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.bus.listen(EVENT_HOMEASSISTANT_STOP, stop_subscription)
|
hass.bus.listen(EVENT_HOMEASSISTANT_STOP, stop_subscription)
|
||||||
|
|
||||||
|
def save_credentials(event):
|
||||||
|
"""Save currently set oauth credentials."""
|
||||||
|
if hass.data[DOMAIN]["oauth"].get("email") is None:
|
||||||
|
config_path = hass.config.path(WINK_CONFIG_FILE)
|
||||||
|
_config = pywink.get_current_oauth_credentials()
|
||||||
|
_write_config_file(config_path, _config)
|
||||||
|
|
||||||
|
hass.bus.listen(EVENT_HOMEASSISTANT_STOP, save_credentials)
|
||||||
|
|
||||||
def force_update(call):
|
def force_update(call):
|
||||||
"""Force all devices to poll the Wink API."""
|
"""Force all devices to poll the Wink API."""
|
||||||
_LOGGER.info("Refreshing Wink states from API")
|
_LOGGER.info("Refreshing Wink states from API")
|
||||||
|
@ -768,7 +768,7 @@ python-velbus==2.0.11
|
|||||||
python-vlc==1.1.2
|
python-vlc==1.1.2
|
||||||
|
|
||||||
# homeassistant.components.wink
|
# homeassistant.components.wink
|
||||||
python-wink==1.3.1
|
python-wink==1.4.2
|
||||||
|
|
||||||
# homeassistant.components.zwave
|
# homeassistant.components.zwave
|
||||||
python_openzwave==0.4.0.31
|
python_openzwave==0.4.0.31
|
||||||
|
Loading…
x
Reference in New Issue
Block a user