alexmohr / sonyapilib Goto Github PK
View Code? Open in Web Editor NEWContains a python api to control sony devices.
License: MIT License
Contains a python api to control sony devices.
License: MIT License
sonyapilib/sonyapilib/device.py
Line 99 in 0d8548e
Every time a SonyDevice object is created, a new UUID is generated.
I think the UUID should be stored in the json file, so the UUID is the same on the next invocation.
On my 2011 device the Ircc definition returned from the TV has a full URL but the code prepends the received data with http etc .... so needs a change to allow for this alternative format.
Something like this (although I'm sure there is a tidier way to do it):
near the end of _parse_ircc
if service_location.startswith('http://'):
service_url = ''
else:
service_url = lirc_url.scheme + "://" + lirc_url.netloc
self.control_url = service_url + service_location
Implement a feature to support selection of sources
Bump the version after #40 has been merged
Turning on the device is done with SonyDevice.power(true)
:
def power(self, on):
if (on):
self.wakeonlan()
# Try using the power on command incase the WOL doesn't work
if not self.get_power_status():
self.send_command('Power')
else:
self.send_command('Power')
The function send_command
tries to fetch a list of available commands from the device:
def send_command(self, name):
if len(self.commands) == 0:
self.update_commands()
self.send_req_ircc(self.commands[name].value)
When the device is powered off (in this case a BDP-S3200), this will fail because the call to /getRemoteCommandList
is denied:
2019-04-01 11:21:03 ERROR (Thread-17) [sonyapilib.device] Exception: HTTPConnectionPool(host='192.168.240.4', port=50002): Max retries exceeded with url: /getRemoteCommandList (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fcc66435eb8>: Failed to establish a new connection: [Errno 111] Connection refused',))
This will cause the commands
array to remain empty, in turn causing a KeyError: 'Power'
if a power on is tried through send_command("Power")
Once the device has been turned on and the commands
array is populated, the problem is solved.
Following solutions are available:
update_commands()
did not return a populated array (should be checked in all circumstances, there could be other causes we didn't think of yet)Currently there is no support for authentication with pre shared keys.
Must be done after #2
The volume control currently only works with a static volume button in home assistant.
It can be improved by implementing it in a way the scrollbar from home assistant can be used.
Originally posted by @ptimatth in #40 (comment)
Some things could not be implemented without a V4 device.
Known issues:
update_commands: Don't know how the json response
2019-04-04 19:35:21 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform sony
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
return fut.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/sony/media_player.py", line 63, in setup_platform
from sonyapilib.device import SonyDevice
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 49
name: str
^
SyntaxError: invalid syntax
sonyapilib/sonyapilib/device.py
Line 49 in f9fa0ce
Happens on the v4
branch
On my BDP-S3200, only ports 50201, 50202 and 54400 are reachable when the device is powered off.
If Home Assistant is started and the device is not turned on, /actionList
is being requested over and over again:
2019-04-04 19:53:50 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.bdps3200 fails
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/connection.py", line 83, in create_connection
raise err
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 166, in connect
conn = self._new_conn()
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f625afcf080>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.240.4', port=50002): Max retries exceeded with url: /actionList (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f625afcf080>: Failed to establish a new connection: [Errno 111] Connection refused',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
await self.async_device_update()
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 379, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/sony/media_player.py", line 192, in update
if not self.sonydevice.get_power_status():
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 586, in get_power_status
log_errors=False, raise_errors=True)
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 421, in _send_http
timeout=TIMEOUT)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.240.4', port=50002): Max retries exceeded with url: /actionList (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f625afcf080>: Failed to establish a new connection: [Errno 111] Connection refused',))
2019-04-04 19:54:01 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.bdps3200 fails
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/connection.py", line 83, in create_connection
raise err
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 166, in connect
conn = self._new_conn()
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f625afaeeb8>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.240.4', port=50002): Max retries exceeded with url: /actionList (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f625afaeeb8>: Failed to establish a new connection: [Errno 111] Connection refused',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
await self.async_device_update()
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 379, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/sony/media_player.py", line 192, in update
if not self.sonydevice.get_power_status():
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 586, in get_power_status
log_errors=False, raise_errors=True)
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 421, in _send_http
timeout=TIMEOUT)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.240.4', port=50002): Max retries exceeded with url: /actionList (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f625afaeeb8>: Failed to establish a new connection: [Errno 111] Connection refused',))
[…] (repeat endlessly)
Travis is broken, migrate to gitlab runners
Use raise for status everywhere and do not check for status code
In the meantime I've tested this PR with Home Assistant, and it works (hooray!), but I noticed that the library is quite noisy if the device is turned off during startup:
2020-09-20 23:58:44 ERROR (SyncWorker_35) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='bdp-s370', port=52323): Max retries exceeded with url: /dmr.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb23f92a90>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:47 ERROR (SyncWorker_35) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='bdp-s370', port=50001): Max retries exceeded with url: /Ircc.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb22e791d0>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:47 ERROR (SyncWorker_35) [sonyapilib.device] failed to get device information: HTTPConnectionPool(host='bdp-s370', port=50001): Max retries exceeded with url: /Ircc.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb22e791d0>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:50 ERROR (SyncWorker_35) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='bdp-s370', port=50202): Max retries exceeded with url: /appslist (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdb2254bb50>: Failed to establish a new connection: [Errno 113] No route to host'))
2020-09-20 23:58:51 WARNING (MainThread) [homeassistant.helpers.entity] Update of media_player.sony_bdp_s370 is taking over 10 seconds
2020-09-20 23:58:51 WARNING (MainThread) [homeassistant.components.media_player] Updating sony media_player took longer than the scheduled update interval 0:00:10
These lines keep repeating every few seconds, so they really fill up the logs. I think the errors should be degraded to warnings, but maybe some kind of rate limiting could be applied, too. I don't think they are caused by my patch or the type of device (are newer devices always-on?), but who knows...
Originally posted by @mtdcr in #58 (comment)
In send_authentication if ewgistration_action.mode < 3 then there is no HTTP connection to the device to start the authentication process.
For my 2011 TV this (mode 2) this does not work.
The request has to be sent (PIN not needed) and this results in a pop-up on the TV that has to be acknowledged within 20 or so seconds to allow the registration to happen (subject to a maximum of 5 registered controllers).
I made a quick hack to change the test from "< 3" to "< 2" and it worked. Still need to enter a PIN into the HA UI to make this happen but that is not really an issue (and even less if documented).
Note - there is another issue that stops things working after registration - and I'll open a new ticket on that.
sonyapilib/sonyapilib/device.py
Line 132 in 367490d
Problem: if the device uses DHCP and the device was powered down long enough for the lease to expire, the WOL sequence won't work.
Possible solutions:
I am trying to get an old Sony TV integrated.
However, it is not getting through the early phases because the request to fetch from /Ircc.xml fails.
I am digging around to try to see if the info is hiding somewhere else or if I can bypass the call.
Can you post what would normally be returned from that URL so that I can see if equivalent info is available via a different URL/port?
If I try to use the example code, I get the following errors:
Enter the PIN displayed at your device: 0000
HTTPError: 403 Client Error: Forbidden for url: http://192.168.240.4:52323/dmr.xml
HTTPError: 500 Server Error: Internal Server Error for url: http://192.168.240.4:50002/register?name=SonyApiLib%20Python%20Test®istrationType=initial&deviceId=SonyApiLib%20Python%20Test&wolSupport=true
Mine doesn't seem to listen on 52323 at all. NMAP on it got me the following:
80/tcp open http
1083/tcp open ansoft-lm-1
1900/tcp open upnp
10100/tcp open itap-ddtp
33335/tcp open unknown
50001/tcp open unknown
60151/tcp open unknown
I've tried all of those ports for the DMR, and no luck on any of them. The port 80 Sony information page says the firmware version is "1.08 / fv=s9327.1092.0", if that helps.
Any ideas?
Hi,
I patched sonyapilib to be able to register at my old bluray player (BDP-S370).
Among other things, it doesn't offer a command list. However, it uses the same type="ircc" key codes as listed in getRemoteCommandList.xml.
Here's a copy of an Ircc.xml from this generation:
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>
<friendlyName>Blu-ray Disc Player</friendlyName>
<manufacturer>Sony Corporation</manufacturer>
<manufacturerURL>http://www.sony.net/</manufacturerURL>
<modelDescription/>
<modelName>Blu-ray Disc Player</modelName>
<modelURL/>
<UDN>uuid:00000000-0000-1010-8000-544249bd7901</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-sony-com:service:IRCC:1</serviceType>
<serviceId>urn:schemas-sony-com:serviceId:IRCC</serviceId>
<SCPDURL>/IRCCSCPD.xml</SCPDURL>
<controlURL>/upnp/control/IRCC</controlURL>
<eventSubURL>/upnp/event/IRCC</eventSubURL>
</service>
</serviceList>
<presentationURL/>
<av:X_IRCC_DeviceInfo xmlns:av="urn:schemas-sony-com:av">
<av:X_IRCC_Version>1.0</av:X_IRCC_Version>
<av:X_IRCC_CategoryList>
<av:X_IRCC_Category>
<av:X_CategoryInfo>AAMAABxa</av:X_CategoryInfo>
</av:X_IRCC_Category>
</av:X_IRCC_CategoryList>
</av:X_IRCC_DeviceInfo>
<av:X_UNR_DeviceInfo xmlns:av="urn:schemas-sony-com:av">
<av:X_UNR_Version>1.0</av:X_UNR_Version>
<av:X_CERS_URL>http://10.0.0.9:50002/</av:X_CERS_URL>
<av:X_CERS_ActionList_URL>http://10.0.0.9:50002/</av:X_CERS_ActionList_URL>
<av:X_Remote_Type>BDPlayer2010</av:X_Remote_Type>
</av:X_UNR_DeviceInfo>
</device>
</root>
This is how a response on http://<host>:50002/
looks like if registration is open:
<?xml version="1.0"?>
<actionList>
<action name="register"/>
<action name="getContentInformation"/>
<action name="getText"/>
<action name="sendText"/>
</actionList>
If it's closed, the server returns 403.
Action URLs are using this format: http://<host>:50002/?action=register¶m=value
diff --git a/sonyapilib/device.py b/sonyapilib/device.py
index ea74635..29c72ee 100644
--- a/sonyapilib/device.py
+++ b/sonyapilib/device.py
@@ -151,17 +151,22 @@ class SonyDevice:
def _update_service_urls(self):
"""Initialize the device by reading the necessary resources from it."""
- response = self._send_http(self.dmr_url, method=HttpMethod.GET)
- if not response:
- _LOGGER.error("Failed to get DMR")
+ try:
+ response = self._send_http(self.dmr_url, method=HttpMethod.GET, raise_errors=True)
+ except requests.exceptions.ConnectionError:
+ response = None
+ except requests.exceptions.RequestException as exc:
+ _LOGGER.error("Failed to get DMR: %s: %s", type(exc), exc)
return
try:
- self._parse_dmr(response.text)
+ if response:
+ self._parse_dmr(response.text)
if self.api_version <= 3:
self._parse_ircc()
self._parse_action_list()
- self._parse_system_information()
+ if self.api_version > 0:
+ self._parse_system_information()
else:
self._parse_system_information_v4()
@@ -177,12 +182,21 @@ class SonyDevice:
action = XmlApiObject(element.attrib)
self.actions[action.name] = action
+ if action.mode is None:
+ action.mode = self.api_version
+ if action.url is None and action.name:
+ action.url = urljoin(self.actionlist_url, "?action={}".format(action.name))
+ separator = "&"
+ else:
+ separator = "?"
+
if action.name == "register":
# the authentication is based on the device id and the mac
action.url = \
- "{0}?name={1}®istrationType=initial&deviceId={2}"\
+ "{0}{1}name={2}®istrationType=initial&deviceId={3}"\
.format(
action.url,
+ separator,
quote(self.nickname),
quote(self.client_id))
self.api_version = action.mode
Because the patch above is quite hackish, I'm not going to submit a PR. But I'd like to document my findings. Maybe you or someone else can find a nicer way to integrate it. I don't use my bluray player often these days, so my motivation is lacking a bit.
Good luck with your thesis, Alex!
This might be very pedantic ;-)
I created a "lint" branch in my fork and fixed a series of pylint
errors.
The errors remaining are lines that are too long at some places and missing docstrings
See:
sonyapilib/sonyapilib/device.py
Line 251 in 367490d
After that is not clear if e.g. json.get('error')
is a function from the json library or a method from the json
object.
Hi Alex,
I own a BDP-S4200 and would like to add that to my home-assistant setup. For that, I would like to know if you still plan to integrate this component in upstream and if you need help testing.
The media-player components have been restructured a bit lately.
Regards,
Edwin
ssdp.py line 24 has:
headers["LOCATON"]
and line 28 has:
headers["CACHE-CONTROL"]
These throw exceptions for my directtv box which has headers of:
{'Cache-Control': 'max-age=1800', 'EXT': '', 'Location': 'http://192.168.0.84:49152/0/description.xml', 'Server': 'Linux/3.3.8-3.0, UPnP/1.0 DIRECTV JHUPnP/1.0', 'ST': 'upnp:rootdevice', 'USN': 'uuid:DIRECTV2PC-Media-Server1_0-RID-025191287173::upnp:rootdevice'}
I.e. Location and Cache-Control.
Hei,
I am trying to make it to work on my home assitant. on a BDV-N9100W
I manage to pip install the sonyapilib and copied the sony custom component into home assistant config folder.
The problem is when I try to put the 0000 pin during the configuration, it does not work.
I get the message below, then nothing happens.
'SonyDevice' object has no attribute 'get_action'
Traceback (most recent call last):
File "/usr/src/app/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service
connection.context(msg))
File "/usr/src/app/homeassistant/core.py", line 1150, in async_call
self._execute_service(handler, service_call))
File "/usr/src/app/homeassistant/core.py", line 1172, in _execute_service
await handler.func(service_call)
File "/usr/src/app/homeassistant/components/configurator/__init__.py", line 221, in async_handle_service_call
call.data.get(ATTR_FIELDS, {}))
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/sony/media_player.py", line 120, in sony_configuration_callback
auth_mode = sony_device.get_action("register").mode
AttributeError: 'SonyDevice' object has no attribute 'get_action'
Any idea on how to precede?
Thanks
I have a fresh copy of the v4 branch.
I tried to power on the device and got the following stacktrace:
2019-04-05 22:23:20 ERROR (Thread-21) [sonyapilib.device] HTTPError: HTTPConnectionPool(host='192.168.240.4', port=52323): Max retries exceeded with url: /dmr.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f780830d780>: Failed to establish a new connection: [Errno 111] Connection refused',))
2019-04-05 22:23:20 ERROR (Thread-21) [sonyapilib.device] Failed to get DMR
2019-04-05 22:23:20 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140153510594880] 'SonyDevice' object has no attribute 'uuid'
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/websocket_api/commands.py", line 122, in handle_call_service
connection.context(msg))
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1138, in async_call
self._execute_service(handler, service_call))
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1160, in _execute_service
await handler.func(service_call)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 188, in handle_service
self._platforms.values(), func, call, service_name
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 314, in entity_service_call
future.result() # pop exception if have
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 328, in _handle_service_platform_call
await getattr(entity, func)(**data)
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/sony/media_player.py", line 251, in turn_on
self.sonydevice.power(True, self._broadcast)
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 597, in power
self._send_command('Power')
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 436, in _send_command
self._init_device()
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 112, in _init_device
self._recreate_authentication()
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 349, in _recreate_authentication
self.headers['X-CERS-DEVICE-ID'] = self.get_device_id()
File "/srv/homeassistant/lib/python3.5/site-packages/sonyapilib/device.py", line 506, in get_device_id
return "TVSideView:{0}".format(self.uuid)
AttributeError: 'SonyDevice' object has no attribute 'uuid'
sonyapilib/sonyapilib/device.py
Line 99 in 0d8548e
id()
is a built-in function of Python.
Using id
as a variable-name throws warnings.
See:
sonyapilib/sonyapilib/device.py
Line 268 in 367490d
Fix: #21
Hi, this seemed like the only place I could find to ask this question. As far as I know, your component is the only one out there that might provide integration with my Sony BluRay player. I pip installed sonyapilib, and it installed 0.3.8. I copied components/media_players/sony.py from your home-assistant fork, and put that in my custom_components/media_players folder. I added the following to my home assistant config:
`media_player:
After authentication/registration on the TV the commands are still not being accepted (403 response).
I think that this is because these old devices (reg mode 2) need to have 2 headers included that allow the TV to determine that this is an allowed controller.
In KHerron/SonyAPILib code there are hard-coded values that are always inserted in the HTTP requests.
For this Python app it should use the values that it provided during the registration phase.
The HTTP headers are:
X-CERS-DEVICE-ID:
X-CERS-DEVICE-INFO:
I suspect that newer devices ignore those fields if they are present so it is probably safe to ensure that they are present and set in _send_http
I am attempting to make a hard-coded version to verify the principle.
I failed to power on my device with wakeonlan.
The VM with the sonyapilib library is multihomed, if I use the wakeonlan library and send the magic packet with its built-in function and direct it at the IP of the device (which is already known anyway), it works flawlessly.
The wakeonlan library is a dependency of home assistant already, it does not need to be installed.
I can create a PR right away. To which branch should I direct the PR? dev?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.