Store the key file in the config dir (#5732)

* webostv: Store the key file in the config dir

* Update the pylgtv source to use the repo by @TheRealLink

* Add missing config parameter
This commit is contained in:
Philipp Schmitt 2017-02-05 10:39:04 +01:00 committed by Pascal Vizeli
parent d88c903537
commit 573fc651dc
3 changed files with 24 additions and 17 deletions

View File

@ -20,13 +20,13 @@ from homeassistant.components.media_player import (
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_MAC, CONF_CUSTOMIZE, STATE_OFF, CONF_HOST, CONF_MAC, CONF_CUSTOMIZE, STATE_OFF,
STATE_PLAYING, STATE_PAUSED, STATE_PLAYING, STATE_PAUSED,
STATE_UNKNOWN, CONF_NAME) STATE_UNKNOWN, CONF_NAME, CONF_FILENAME)
from homeassistant.loader import get_component from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv' REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv'
'/archive/v0.1.2.zip' '/archive/v0.1.3.zip'
'#pylgtv==0.1.2', '#pylgtv==0.1.3',
'websockets==3.2', 'websockets==3.2',
'wakeonlan==0.2.2'] 'wakeonlan==0.2.2']
@ -37,6 +37,8 @@ CONF_SOURCES = 'sources'
DEFAULT_NAME = 'LG webOS Smart TV' DEFAULT_NAME = 'LG webOS Smart TV'
WEBOSTV_CONFIG_FILE = 'webostv.conf'
SUPPORT_WEBOSTV = SUPPORT_TURN_OFF | \ SUPPORT_WEBOSTV = SUPPORT_TURN_OFF | \
SUPPORT_NEXT_TRACK | SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK | \ SUPPORT_NEXT_TRACK | SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK | \
SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP | \ SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP | \
@ -55,6 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_HOST): cv.string, vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_MAC): cv.string, vol.Optional(CONF_MAC): cv.string,
vol.Optional(CONF_CUSTOMIZE, default={}): CUSTOMIZE_SCHEMA, vol.Optional(CONF_CUSTOMIZE, default={}): CUSTOMIZE_SCHEMA,
vol.Optional(CONF_FILENAME, default=WEBOSTV_CONFIG_FILE): cv.string
}) })
@ -77,16 +80,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
mac = config.get(CONF_MAC) mac = config.get(CONF_MAC)
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
customize = config.get(CONF_CUSTOMIZE) customize = config.get(CONF_CUSTOMIZE)
setup_tv(host, mac, name, customize, hass, add_devices) config = hass.config.path(config.get(CONF_FILENAME))
setup_tv(host, mac, name, customize, config, hass, add_devices)
def setup_tv(host, mac, name, customize, hass, add_devices): def setup_tv(host, mac, name, customize, config, hass, add_devices):
"""Setup a LG WebOS TV based on host parameter.""" """Setup a LG WebOS TV based on host parameter."""
from pylgtv import WebOsClient from pylgtv import WebOsClient
from pylgtv import PyLGTVPairException from pylgtv import PyLGTVPairException
from websockets.exceptions import ConnectionClosed from websockets.exceptions import ConnectionClosed
client = WebOsClient(host) client = WebOsClient(host, config)
if not client.is_registered(): if not client.is_registered():
if host in _CONFIGURING: if host in _CONFIGURING:
@ -104,7 +108,7 @@ def setup_tv(host, mac, name, customize, hass, add_devices):
# Not registered, request configuration. # Not registered, request configuration.
_LOGGER.warning("LG webOS TV %s needs to be paired", host) _LOGGER.warning("LG webOS TV %s needs to be paired", host)
request_configuration( request_configuration(
host, mac, name, customize, hass, add_devices) host, mac, name, customize, config, hass, add_devices)
return return
# If we came here and configuring this host, mark as done. # If we came here and configuring this host, mark as done.
@ -113,11 +117,11 @@ def setup_tv(host, mac, name, customize, hass, add_devices):
configurator = get_component('configurator') configurator = get_component('configurator')
configurator.request_done(request_id) configurator.request_done(request_id)
add_devices([LgWebOSDevice(host, mac, name, customize)], True) add_devices([LgWebOSDevice(host, mac, name, customize, config)], True)
def request_configuration( def request_configuration(
host, mac, name, customize, hass, add_devices): host, mac, name, customize, config, hass, add_devices):
"""Request configuration steps from the user.""" """Request configuration steps from the user."""
configurator = get_component('configurator') configurator = get_component('configurator')
@ -130,7 +134,7 @@ def request_configuration(
# pylint: disable=unused-argument # pylint: disable=unused-argument
def lgtv_configuration_callback(data): def lgtv_configuration_callback(data):
"""The actions to do when our configuration callback is called.""" """The actions to do when our configuration callback is called."""
setup_tv(host, mac, name, customize, hass, add_devices) setup_tv(host, mac, name, customize, config, hass, add_devices)
_CONFIGURING[host] = configurator.request_config( _CONFIGURING[host] = configurator.request_config(
hass, name, lgtv_configuration_callback, hass, name, lgtv_configuration_callback,
@ -143,11 +147,11 @@ def request_configuration(
class LgWebOSDevice(MediaPlayerDevice): class LgWebOSDevice(MediaPlayerDevice):
"""Representation of a LG WebOS TV.""" """Representation of a LG WebOS TV."""
def __init__(self, host, mac, name, customize): def __init__(self, host, mac, name, customize, config):
"""Initialize the webos device.""" """Initialize the webos device."""
from pylgtv import WebOsClient from pylgtv import WebOsClient
from wakeonlan import wol from wakeonlan import wol
self._client = WebOsClient(host) self._client = WebOsClient(host, config)
self._wol = wol self._wol = wol
self._mac = mac self._mac = mac
self._customize = customize self._customize = customize

View File

@ -11,16 +11,18 @@ import voluptuous as vol
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import ( from homeassistant.components.notify import (
BaseNotificationService, PLATFORM_SCHEMA) BaseNotificationService, PLATFORM_SCHEMA)
from homeassistant.const import CONF_HOST from homeassistant.const import (CONF_FILENAME, CONF_HOST)
REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv/archive/v0.1.2.zip' REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv/archive/v0.1.3.zip'
'#pylgtv==0.1.2'] '#pylgtv==0.1.3']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
WEBOSTV_CONFIG_FILE = 'webostv.conf'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string, vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_FILENAME, default=WEBOSTV_CONFIG_FILE): cv.string
}) })
@ -29,7 +31,8 @@ def get_service(hass, config, discovery_info=None):
from pylgtv import WebOsClient from pylgtv import WebOsClient
from pylgtv import PyLGTVPairException from pylgtv import PyLGTVPairException
client = WebOsClient(config.get(CONF_HOST)) path = hass.config.path(config.get(CONF_FILENAME))
client = WebOsClient(config.get(CONF_HOST), key_file_path=path)
try: try:
client.register() client.register()

View File

@ -205,7 +205,7 @@ https://github.com/LinuxChristian/pyW215/archive/v0.3.7.zip#pyW215==0.3.7
# homeassistant.components.media_player.webostv # homeassistant.components.media_player.webostv
# homeassistant.components.notify.webostv # homeassistant.components.notify.webostv
https://github.com/TheRealLink/pylgtv/archive/v0.1.2.zip#pylgtv==0.1.2 https://github.com/TheRealLink/pylgtv/archive/v0.1.3.zip#pylgtv==0.1.3
# homeassistant.components.sensor.thinkingcleaner # homeassistant.components.sensor.thinkingcleaner
# homeassistant.components.switch.thinkingcleaner # homeassistant.components.switch.thinkingcleaner