supersaiyanmode / PyWebOSTV

Python API for controlling LG TVs (Web OS)
MIT License
261 stars 50 forks source link

TvControl .. does not work #29

Open Bonze255 opened 4 years ago

Bonze255 commented 4 years ago

Can you give an example for reading current_channel? i can connect to the tv and read some system.info(), volume... but when i call get_current_channel(), get_current_program() ... does not work. I get an error, when i use the example from the readme.

Error 'NoneType' object has no attribute 'text_message' ` from pywebostv.discovery import from pywebostv.connection import from pywebostv.controls import *

self._client.connect() self._tv = TvControl(self._client) self._tv.subscribe_get_current_channel(callback=self.on_current_channel)

def on_current_channel(status, payload): if status: self.logger.debug("LGWebos: current_program {}".format(payload)) else: self.logger.debug("LGWebos: Something went wrong.") `

supersaiyanmode commented 4 years ago

It's weird, there's no instance (that I could find) of this project reading/writing a field named text_message. Do you have a stacktrace? Where is it coming from?

Also, can you please retry that in a new virtualenv, and share the pip freeze output?

Bonze255 commented 4 years ago

i play around, without a try block self._tv.channel_list() or self._tv.subscribe_channel_list(callback=self.on_channel) will raise

self._tv.subscribe_channel_list(callback=self.on_channel)

File "/usr/local/lib/python3.7/dist-packages/pywebostv/controls.py", line 76, in getattr raise AttributeError(name) AttributeError: subscribe_channel_list

but why?

supersaiyanmode commented 4 years ago

That is because channel_list(..) is not something you can subscribe to (because the TV doesn't emit events for it, and there's no subscription attribute that exists there).

However, looking at the source, I think self._tv.subscribe_get_current_channel(callback=self.on_current_channel) should work for you. Can you please paste the stacktrace associated with text_message as in the original post?

Bonze255 commented 4 years ago

ok, i would try it with that code and i would search fot the text_message.. I try it with a simple code now, but i think something is wrong..

self._tv.subscribe_get_current_channel(callback=self.on_current_channel)

returns Traceback (most recent call last): File "test.py", line 78, in <module> test() File "test.py", line 51, in __init__ self._tv.subscribe_get_current_channel(callback=self.on_current_channel) File "/usr/local/lib/python3.7/dist-packages/pywebostv/controls.py", line 76, in __getattr__ raise AttributeError(name) AttributeError: subscribe_get_current_channel

self._data['channel_list'] = self._tv.channel_list()

Traceback (most recent call last): File "test.py", line 78, in <module> test() File "test.py", line 53, in __init__ self._data['channel_list'] = self._tv.channel_list() File "/usr/local/lib/python3.7/dist-packages/pywebostv/controls.py", line 91, in __getattr__ raise AttributeError(name) AttributeError: channel_list it seems for me, that Class TvControl does not work. The TV is using Webos 05.70. I read a long time ago, with other code the channel infos from the tv, so i know that this must work.

Bonze255 commented 4 years ago

i´ve checked the requirements, so ws4py==0.4.2 was version 0.5.1, i had now downgraded to ws4py==0.4.2 but its the same. ive checked the pylgtv package, and call the get_current_channel() method, so i get

{'channelId': '7_17_4_0_1089_12020_1', 'signalChannelId': '1089_12020_1', 'channelModeId': 2, 'channelModeName': 'Satellite', 'channelTypeId': 6, 'channelTypeName': 'Satellite Digital TV', 'channelNumber': '4', 'channelName': 'RTL2', 'physicalNumber': 17, 'isSkipped': False, 'isLocked': False, 'isDescrambled': False, 'isScrambled': False, 'isFineTuned': False, 'isInvisible': False, 'favoriteGroup': 'A', 'hybridtvType': 'HBBTV', 'dualChannel': {'dualChannelId': None, 'dualChannelTypeId': None, 'dualChannelTypeName': None, 'dualChannelNumber': None}, 'returnValue': True}

i think there is a bug in your getattr(self, name): or TvControl

Bonze255 commented 4 years ago

when i write the TvControl class diretly into my programfile, then it works .. `class TvControl1(WebOSControlBase): COMMANDS = { "channel_down": {"uri": "ssap://tv/channelDown"}, "channel_up": {"uri": "ssap://tv/channelUp"}, "channel_list": {"uri": "ssap://tv/getChannelList"}

     }`
supersaiyanmode commented 4 years ago

Hey, hi. I haven't been able to reproduce it. If you are able to have it working in when you recreate the class in your local program as opposed to the installed library -- it sounds like a weird issue.

I noticed that you have the library installed to /usr/local/lib. Can you please retry installing it in a virtualenv?

Bonze255 commented 4 years ago

it works, but i have found something about the failure..

2020-04-05 17:50:37 ERROR CP Server Thread-8 Item tv.befehl.channel_down: problem running <bound method LGWebos.update_item of <plugins.webos.LGWebos object at 0x7fe0c489b748>>: 'NoneType' object has no attribute 'text_message' Traceback (most recent call last): File "/usr/local/smarthome/lib/item.py", line 2224, in update method(self, caller, source, dest) File "/usr/local/smarthome/plugins/webos/init__.py", line 342, in update_item self._tv.channel_down() File "/usr/local/lib/python3.7/dist-packages/pywebostv/controls.py", line 115, in request_func timeout=timeout) File "/usr/local/lib/python3.7/dist-packages/pywebostv/controls.py", line 59, in request get_queue=True) File "/usr/local/lib/python3.7/dist-packages/pywebostv/connection.py", line 166, in send_message self.send(json.dumps(obj)) File "/usr/local/lib/python3.7/dist-packages/ws4py/websocket.py", line 299, in send message_sender = self.stream.binary_message if binary else self.stream.text_message AttributeError: 'NoneType' object has no attribute 'text_message'

supersaiyanmode commented 4 years ago

Sounds like your WebSocket stream is None. Are you sure you called .connect() ? So, the stream attribute should not be None after a successful .connect(). Can you please check when stream is set to None? At the moment, since you say it works for you, I am inclining towards closing this issue. But I'll keep it open in case you are able to find the real root cause.

Bonze255 commented 4 years ago

when i use subcribe, it is not possible to read some other infos from the same class, when i dont use subscribe it works..

supersaiyanmode commented 4 years ago

@Bonze255 That sounds like a bug in the library. Can you please open a new bug (and perhaps close this one)?

Also, can you please include a small reproducible test code?