Skip to content

Commit

Permalink
Store the key file in the config dir (home-assistant#5732)
Browse files Browse the repository at this point in the history
* webostv: Store the key file in the config dir

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

* Add missing config parameter
  • Loading branch information
pschmitt authored and pvizeli committed Feb 5, 2017
1 parent d88c903 commit 573fc65
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
28 changes: 16 additions & 12 deletions homeassistant/components/media_player/webostv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
from homeassistant.const import (
CONF_HOST, CONF_MAC, CONF_CUSTOMIZE, STATE_OFF,
STATE_PLAYING, STATE_PAUSED,
STATE_UNKNOWN, CONF_NAME)
STATE_UNKNOWN, CONF_NAME, CONF_FILENAME)
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv'
'/archive/v0.1.2.zip'
'#pylgtv==0.1.2',
'/archive/v0.1.3.zip'
'#pylgtv==0.1.3',
'websockets==3.2',
'wakeonlan==0.2.2']

Expand All @@ -37,6 +37,8 @@

DEFAULT_NAME = 'LG webOS Smart TV'

WEBOSTV_CONFIG_FILE = 'webostv.conf'

SUPPORT_WEBOSTV = SUPPORT_TURN_OFF | \
SUPPORT_NEXT_TRACK | SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK | \
SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP | \
Expand All @@ -55,6 +57,7 @@
vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_MAC): cv.string,
vol.Optional(CONF_CUSTOMIZE, default={}): CUSTOMIZE_SCHEMA,
vol.Optional(CONF_FILENAME, default=WEBOSTV_CONFIG_FILE): cv.string
})


Expand All @@ -77,16 +80,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
mac = config.get(CONF_MAC)
name = config.get(CONF_NAME)
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."""
from pylgtv import WebOsClient
from pylgtv import PyLGTVPairException
from websockets.exceptions import ConnectionClosed

client = WebOsClient(host)
client = WebOsClient(host, config)

if not client.is_registered():
if host in _CONFIGURING:
Expand All @@ -104,7 +108,7 @@ def setup_tv(host, mac, name, customize, hass, add_devices):
# Not registered, request configuration.
_LOGGER.warning("LG webOS TV %s needs to be paired", host)
request_configuration(
host, mac, name, customize, hass, add_devices)
host, mac, name, customize, config, hass, add_devices)
return

# If we came here and configuring this host, mark as done.
Expand All @@ -113,11 +117,11 @@ def setup_tv(host, mac, name, customize, hass, add_devices):
configurator = get_component('configurator')
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(
host, mac, name, customize, hass, add_devices):
host, mac, name, customize, config, hass, add_devices):
"""Request configuration steps from the user."""
configurator = get_component('configurator')

Expand All @@ -130,7 +134,7 @@ def request_configuration(
# pylint: disable=unused-argument
def lgtv_configuration_callback(data):
"""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(
hass, name, lgtv_configuration_callback,
Expand All @@ -143,11 +147,11 @@ def lgtv_configuration_callback(data):
class LgWebOSDevice(MediaPlayerDevice):
"""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."""
from pylgtv import WebOsClient
from wakeonlan import wol
self._client = WebOsClient(host)
self._client = WebOsClient(host, config)
self._wol = wol
self._mac = mac
self._customize = customize
Expand Down
11 changes: 7 additions & 4 deletions homeassistant/components/notify/webostv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import (
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'
'#pylgtv==0.1.2']
REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv/archive/v0.1.3.zip'
'#pylgtv==0.1.3']

_LOGGER = logging.getLogger(__name__)

WEBOSTV_CONFIG_FILE = 'webostv.conf'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_FILENAME, default=WEBOSTV_CONFIG_FILE): cv.string
})


Expand All @@ -29,7 +31,8 @@ def get_service(hass, config, discovery_info=None):
from pylgtv import WebOsClient
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:
client.register()
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.switch.thinkingcleaner
Expand Down

0 comments on commit 573fc65

Please sign in to comment.