8000 Support for Wink local control by w1ll1am23 · Pull Request #8607 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support for Wink local control #8607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 28, 2017
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
38 changes: 26 additions & 12 deletions homeassistant/components/wink.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from homeassistant.helpers.entity import Entity
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__)

Expand All @@ -36,10 +36,10 @@
CONF_CLIENT_ID = 'client_id'
CONF_CLIENT_SECRET = 'client_secret'
CONF_USER_AGENT = 'user_agent'
CONF_OATH = 'oath'
CONF_OAUTH = 'oauth'
CONF_LOCAL_CONTROL = 'local_control'
CONF_APPSPOT = 'appspot'
CONF_DEFINED_BOTH_MSG = 'Remove access token to use oath2.'
CONF_MISSING_OATH_MSG = 'Missing oath2 credentials.'
CONF_MISSING_OAUTH_MSG = 'Missing oauth2 credentials.'
CONF_TOKEN_URL = "https://winkbearertoken.appspot.com/token"

ATTR_ACCESS_TOKEN = 'access_token'
Expand All @@ -64,15 +64,14 @@
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
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,
msg=CONF_MISSING_OATH_MSG): cv.string,
vol.Inclusive(CONF_CLIENT_ID, CONF_OATH,
msg=CONF_MISSING_OATH_MSG): cv.string,
vol.Inclusive(CONF_CLIENT_SECRET, CONF_OATH,
msg=CONF_MISSING_OATH_MSG): cv.string,
vol.Exclusive(CONF_EMAIL, CONF_OATH,
msg=CONF_DEFINED_BOTH_MSG): cv.string,
msg=CONF_MISSING_OAUTH_MSG): cv.string,
vol.Inclusive(CONF_CLIENT_ID, CONF_OAUTH,
msg=CONF_MISSING_OAUTH_MSG): cv.string,
vol.Inclusive(CONF_CLIENT_SECRET, CONF_OAUTH,
msg=CONF_MISSING_OAUTH_MSG): cv.string,
vol.Optional(CONF_LOCAL_CONTROL, default=False): cv.boolean
})
}, extra=vol.ALLOW_EXTRA)

Expand Down Expand Up @@ -206,8 +205,11 @@ def _get_wink_token_from_web():
client_secret = config[DOMAIN].get(ATTR_CLIENT_SECRET)
email = config[DOMAIN].get(CONF_EMAIL)
password = config[DOMAIN].get(CONF_PASSWORD)
local_control = config[DOMAIN].get(CONF_LOCAL_CONTROL)
if None not in [client_id, client_secret]:
_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_secret"] = client_secret
hass.data[DOMAIN]["oauth"]["email"] = email
Expand All @@ -216,11 +218,14 @@ def _get_wink_token_from_web():
client_id, client_secret)
elif None not in [email, password]:
_LOGGER.info("Using web form authentication")
pywink.disable_local_control()
hass.data[DOMAIN]["oauth"]["email"] = email
hass.data[DOMAIN]["oauth"]["password"] = password
_get_wink_token_from_web()
else:
_LOGGER.info("Using new oauth authentication")
if not local_control:
pywink.disable_local_control()
config_path = hass.config.path(WINK_CONFIG_FILE)
if os.path.isfile(config_path):
config_file = _read_config_file(config_path)
Expand Down Expand Up @@ -304,6 +309,15 @@ def stop_subscription(event):

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):
"""Force all devices to poll the Wink API."""
_LOGGER.info("Refreshing Wink states from API")
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ python-velbus==2.0.11
python-vlc==1.1.2

# homeassistant.components.wink
python-wink==1.3.1
python-wink==1.4.2

# homeassistant.components.zwave
python_openzwave==0.4.0.31
Expand Down
0