def get_service(hass, config): """Return the notify service.""" if not validate_config({DOMAIN: config}, {DOMAIN: [CONF_HOST, CONF_NAME]}, _LOGGER): return None host = config.get(CONF_HOST, None) if not host: _LOGGER.error('No host provided.') return None from pylgtv import WebOsClient from pylgtv import PyLGTVPairException client = WebOsClient(host) try: client.register() except PyLGTVPairException: _LOGGER.error('Pairing failed.') return None except OSError: _LOGGER.error('Host unreachable.') return None return LgWebOSNotificationService(client)
def cmd(self, cmd): if "denon" in cmd: d = denonavr.DenonAVR(app_cfg['denon']['ip']) d.update() if cmd == "denon_input_digital": d.input_func = app_cfg['denon']['digital_in'] elif cmd == "denon_power_off": d.power_off() elif cmd == "denon_power_on": d.power_on() elif cmd == "denon_vol_down": d.volume_down() elif cmd == "denon_vol_mute": d.mute(True) #FIXME elif cmd == "denon_vol_up": d.volume_up() else: return '{"response":"invalid_cmd"}' return '{"response":"ok"}' elif "lg" in cmd: w = WebOsClient(app_cfg['lg']['ip']) w.register() if "lg_arr_" in cmd: w.request( "com.webos.service.networkinput/getPointerInputSocket") ws = websocket.WebSocket() ws.connect(w.last_response['payload']['socketPath']) if cmd == "lg_arr_down": ws.send('type:button\nname:DOWN\n\n') elif cmd == "lg_arr_up": ws.send('type:button\nname:UP\n\n') elif cmd == "lg_arr_left": ws.send('type:button\nname:LEFT\n\n') elif cmd == "lg_arr_right": ws.send('type:button\nname:RIGHT\n\n') elif cmd == "lg_arr_ok": ws.send('type:button\nname:ENTER\n\n') elif cmd == "lg_arr_back": ws.send('type:button\nname:BACK\n\n') elif cmd == "lg_cmd_pause": w.pause() elif cmd == "lg_input_netflix": w.launch_app(app_cfg['lg']['netflix']) elif cmd == "lg_input_ps4": w.set_input(app_cfg['lg']['ps4']) elif cmd == "lg_power_on": send_magic_packet(app_cfg['lg']['mac']) elif cmd == "lg_power_off": w.power_off() else: return '{"response":"invalid_cmd"}' return '{"response":"ok"}' else: return '{"response":"invalid_cmd"}'
def setup_tv(host, hass, add_devices): """Setup a phue bridge based on host parameter.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException client = WebOsClient(host) if not client.is_registered(): if host in _CONFIGURING: # Try to pair. try: client.register() except PyLGTVPairException: _LOGGER.warning( 'Connected to LG WebOS TV at %s but not paired.', host) return except ConnectionRefusedError: _LOGGER.error('Unable to connect to host %s.', host) return else: # Not registered, request configuration. _LOGGER.warning('LG WebOS TV at %s needs to be paired.', host) request_configuration(host, hass, add_devices) return # If we came here and configuring this host, mark as done. if client.is_registered() and host in _CONFIGURING: request_id = _CONFIGURING.pop(host) configurator = get_component('configurator') configurator.request_done(request_id) add_devices([LgWebOSDevice(host)])
def __init__(self): # inicialitza el reconeixedor de veu i comença a escoltar aiy.i18n.set_language_code('ca-ES') self.recognizer = aiy.cloudspeech.get_recognizer() self.inicialitzaRecognizer() # inicialitza robot self.initResetMarty() # inicialitza la càmera self.camera = picamera.PiCamera() # redueix la resolució self.camera.resolution = (320, 240) print('Càmera inicialitzada') # inicialitza llums self.inicialitzaHue() # inicialitza la tele LG self.webos_client = WebOsClient('192.168.0.16') print('TV inicialitzada') # inicialitza model per a reconèixer objectes self.inicialitzaModelImatges() # inicialitza cares conegudes self.inicialitzaCares() #Saluda print('Martina inicialitzada') os.system( " echo 'Hola ja estic llesta!' | festival --language catalan --tts" )
def setup_tv(host, mac, name, customize, config, hass, add_devices): """Set up a LG WebOS TV based on host parameter.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException from websockets.exceptions import ConnectionClosed client = WebOsClient(host, config) if not client.is_registered(): if host in _CONFIGURING: # Try to pair. try: client.register() except PyLGTVPairException: _LOGGER.warning("Connected to LG webOS TV %s but not paired", host) return except (OSError, ConnectionClosed, TypeError, asyncio.TimeoutError): _LOGGER.error("Unable to connect to host %s", host) return else: # Not registered, request configuration. _LOGGER.warning("LG webOS TV %s needs to be paired", host) request_configuration(host, mac, name, customize, config, hass, add_devices) return # If we came here and configuring this host, mark as done. if client.is_registered() and host in _CONFIGURING: request_id = _CONFIGURING.pop(host) configurator = get_component('configurator') configurator.request_done(request_id) add_devices([LgWebOSDevice(host, mac, name, customize, config)], True)
def run_app(tv_ip, app): try: webos_client = WebOsClient(tv_ip) webos_client.launch_app(app) return 0 except: return -1
def list_app(tv_ip): r = set() webos_client = WebOsClient(tv_ip) for app in webos_client.get_apps(): print(app) #print(app['title']) r.add(app['title']) #for ap1 in r: #print(ap1) #print(r) return r
def get_service(hass, config, discovery_info=None): """Return the notify service.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException client = WebOsClient(config.get(CONF_HOST)) try: client.register() except PyLGTVPairException: _LOGGER.error("Pairing with TV failed") return None except OSError: _LOGGER.error("TV unreachable") return None return LgWebOSNotificationService(client)
def setup_tv(host, name, customize, config, timeout, hass, add_entities, turn_on_action): """Set up a LG WebOS TV based on host parameter.""" client = WebOsClient(host, config, timeout) if not client.is_registered(): if host in _CONFIGURING: # Try to pair. try: client.register() except PyLGTVPairException: _LOGGER.warning("Connected to LG webOS TV %s but not paired", host) return except (OSError, ConnectionClosed, asyncio.TimeoutError): _LOGGER.error("Unable to connect to host %s", host) return else: # Not registered, request configuration. _LOGGER.warning("LG webOS TV %s needs to be paired", host) request_configuration( host, name, customize, config, timeout, hass, add_entities, turn_on_action, ) return # If we came here and configuring this host, mark as done. if client.is_registered() and host in _CONFIGURING: request_id = _CONFIGURING.pop(host) configurator = hass.components.configurator configurator.request_done(request_id) add_entities( [ LgWebOSDevice(host, name, customize, config, timeout, hass, turn_on_action) ], True, )
def get_service(hass, config): """Return the notify service.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException client = WebOsClient(config.get(CONF_HOST)) try: client.register() except PyLGTVPairException: _LOGGER.error('Pairing failed.') return None except OSError: _LOGGER.error('Host unreachable.') return None return LgWebOSNotificationService(client)
def __init__(self, host, name, customize, config, timeout, hass, on_action): """Initialize the webos device.""" from pylgtv import WebOsClient self._client = WebOsClient(host, config, timeout) self._on_script = Script(hass, on_action) if on_action else None self._customize = customize self._name = name # Assume that the TV is not muted self._muted = False # Assume that the TV is in Play mode self._playing = True self._volume = 0 self._current_source = None self._current_source_id = None self._state = STATE_UNKNOWN self._source_list = {} self._app_list = {}
def get_service(hass, config, discovery_info=None): """Return the notify service.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException path = hass.config.path(config.get(CONF_FILENAME)) client = WebOsClient(config.get(CONF_HOST), key_file_path=path) if not client.is_registered(): try: client.register() except PyLGTVPairException: _LOGGER.error("Pairing with TV failed") return None except OSError: _LOGGER.error("TV unreachable") return None return LgWebOSNotificationService(client, config.get(CONF_ICON))
def __init__(self, host): """Initialize the webos device.""" from pylgtv import WebOsClient self._client = WebOsClient(host) self._name = 'LG WebOS TV Remote' # Assume that the TV is not muted self._muted = False # Assume that the TV is in Play mode self._playing = True self._volume = 0 self._current_source = None self._current_source_id = None self._source_list = None self._source_label_list = None self._state = STATE_UNKNOWN self._app_list = None self.update()
def __init__(self, host, mac, name, customize, config): """Initialize the webos device.""" from pylgtv import WebOsClient from wakeonlan import wol self._client = WebOsClient(host, config) self._wol = wol self._mac = mac self._customize = customize self._name = name # Assume that the TV is not muted self._muted = False # Assume that the TV is in Play mode self._playing = True self._volume = 0 self._current_source = None self._current_source_id = None self._state = STATE_UNKNOWN self._source_list = {} self._app_list = {}
def __init__(self, ip): self.client = WebOsClient(ip) self.commandLines = { 'off': self.off, 'on': self.wakeonlan, 'software-info': self.software_info, 'volume-up': self.volume_up, 'volume-down': self.volume_down, 'current-app': self.current_app, 'apps': self.apps, 'services': self.services, 'get-volume': self.get_volume, 'get-inputs': self.get_inputs, 'app': self.app, 'set-volume': self.set_volume, 'close-app': self.close_app, 'mute': self.mute, 'unmute': self.unmute, 'get-mute': self.get_mute, 'get-input': self.get_input, 'set-input': self.set_input, 'channel-up': self.channel_up, 'channel-down': self.channel_down, 'channels': self.channels, 'get-channel': self.get_channel, 'info': self.info, 'set-channel': self.set_channel, 'play': self.play, 'pause': self.pause, 'stop': self.stop, 'close': self.close, 'rewind': self.rewind, 'fast-forward': self.fast_forward, 'send-message': self.send_message, 'enter': self.enter, 'delete': self.delete, #'3d-on': threeDOn, #'3d-off': threeDOff, }
def onStart(self): if Parameters["Mode6"] == "Debug": Domoticz.Debugging(1) Domoticz.Trace(True) self.debug = True DumpConfigToLog() Domoticz.Debug("onStart called") updateInterval = int(Parameters["Mode1"]) if updateInterval > 30 or updateInterval < 7: updateInterval = 10 Domoticz.Error("Invalid interval setting, changed to 10") Domoticz.Heartbeat(updateInterval) self.webos_client = WebOsClient(Parameters["Address"], "NONE", 5) # First get some TV details try: tv_details = self.webos_client.get_software_info() Domoticz.Log("Product name: " + tv_details["product_name"]) Domoticz.Log("Software version: " + tv_details["major_ver"] + "." + tv_details["minor_ver"]) Domoticz.Log("MAC Address: " + tv_details["device_id"]) except Exception as e: Domoticz.Error("Error at reading TV info") if not (1 in Devices): Domoticz.Device(Name="TV Status", Unit=1, Type=17, Switchtype=17).Create() if not (2 in Devices): Domoticz.Device(Name="TV Volume", Unit=2, Type=244, Subtype=73, Switchtype=7, Image=8).Create() return True
async def task_set(loop): global g_mute, g_volume try: tv = WebOsClient(WEBOSTV_IP) async with mqtt.local_client(True) as mqtt_client: await mqtt_client.subscribe( ('%s/mute/set' % TV_TOPIC, mqtt.QOS_1), ('%s/volume/set' % TV_TOPIC, mqtt.QOS_1)) while True: message = await mqtt_client.deliver_message() data = message.data.decode('utf-8') LOGGER.debug('delivered on topic %d, message: %s', message.topic, data) if message.topic == '%s/mute/set' % TV_TOPIC: await tv.set_mute(data == '1' and True or False) elif message.topic == '%s/volume/set' % TV_TOPIC: await tv.set_volume(int(data)) except asyncio.CancelledError: pass except: LOGGER.exception('Error in task_set')
#!/home/homeassistant/.homeassistant/bin/python from pylgtv import WebOsClient import sys webos_client = WebOsClient('192.168.1.12') webos_client.set_channel(str(sys.argv[-1])) print(webos_client.get_current_channel()) #webos_client.launch_app('netflix') #webos_client.launch_app('home theater') #for app in webos_client.get_apps(): # print(app)
from pylgtv import WebOsClient import sys import logging logging.basicConfig(stream=sys.stdout, level=logging.INFO) try: tv = WebOsClient('192.168.0.54') tv.set_mute(False) except: print("Error connecting to TV")
from pylgtv import WebOsClient webos_client = WebOsClient('192.168.0.112') #webos_client.launch_app('netflix') for app in webos_client.get_apps(): print(app)
def __init__(self, _ip, _mac, _onkyoip): self.ip = str(_ip) self.mac = _mac self.onkyoip = _onkyoip self.client = WebOsClient(self.ip, "/keys/lg.key") self.receiver = eISCP(self.onkyoip)
#!/usr/bin/python3 from pylgtv import WebOsClient import sys try: ip = sys.argv[1] msg = sys.argv[2] except: print("Usage : %s <ip> <msg>" % (sys.argv[0])) exit(-1) webos_client = WebOsClient(ip) webos_client.send_message(msg)
import asyncio import logging from athome.api import mqtt from pylgtv import WebOsClient WEBOSTV_IP = '192.168.1.131' TV_TOPIC = 'tv/0' LOGGER = logging.getLogger(__name__) g_mute = None g_volume = None g_app = None tv = WebOsClient(WEBOSTV_IP) async def task_poll(loop): while True: try: channel = await tv.get_current_channel() await perform_poll(loop) except OSError: LOGGER.exception('Error connecting to tv') await asyncio.sleep(300) async def perform_poll(loop): global g_mute, g_volume, g_app try:
def __init__(self): self.client = WebOsClient('192.168.1.75')
def list_current_app(tv_ip): webos_client = WebOsClient(tv_ip) return webos_client.get_current_app()
#!/usr/bin/python3 from pylgtv import WebOsClient import sys import logging host = '192.168.88.18' config = '/home/homeassistant/.homeassistant/webostv.conf' timeout = 5 logging.basicConfig(stream=sys.stdout, level=logging.INFO) try: webos_client = WebOsClient(host, config, timeout) except: print("Error connecting to TV") try: #device = webos_client.get_software_info() #print(" Device: "+device("product_name")) #print(" Model: "+device("model_name")) #print(" MAC: "+device("device_id")) #print(" Version: "+device("major_ver")+"."+device("minor_ver")) for app in webos_client.get_apps(): print(app) print(" ID: "+app["id"]) print(" Title: "+app["title"]) print(" Image: "+app["largeIcon"]) print(" UserData: "+app["userData"])
def power_down(tv_ip): webos_client = WebOsClient(tv_ip) WebOsClient.power_off