Giter Site home page Giter Site logo

sonyapilib's People

Contributors

alexmohr avatar dilruacs avatar felix-pi avatar liborsaf avatar mtdcr avatar ptimatth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sonyapilib's Issues

2011 device - _parse_ircc - location definition has full URL

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

KeyError: 'Power' on first power-on

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:

  1. do not try to send commands if the function 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)
  2. store the array in the json configuration as soon as it has been fetched from the device, so it will persist (otherwise if one starts Home Assistant with the device turned off, this will always throw an error the first time)

Improve volume control

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)

Finish V4 implementation.

Some things could not be implemented without a V4 device.

Known issues:
update_commands: Don't know how the json response

SyntaxError "name: str"

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

"/actionList" is being fetched in an endless loop when device powered off

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)

Rate limiting for warnings

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)

2011 device - Register Type 2 - auth request not sent

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.

Send wakeonlan magic packet to broadcast instead of IP

wakeonlan.send_magic_packet(self.mac, ip_address=self.host)

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:

  • determine the broadcast address of the subnet the host is in and use that as a parameter
  • make the WOL address a configuration variable with a sane default (broadcast address)

Sony Bravia KDL-xxHX723 (2011) not working because no reposnse to /Ircc.xml

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?

Trouble configuring Sony BDP-S4200

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&registrationType=initial&deviceId=SonyApiLib%20Python%20Test&wolSupport=true

Can't get DMR for STR-DN1040

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?

Unsupported 2010 BDP models

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>

(Source: https://forums.homeseer.com/forum/media-plug-ins/media-discussion/media-controller-dcorsus/68042-support-for-sony-tv-bluray-media-player#post664783)

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&param=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}&registrationType=initial&deviceId={2}"\
+                    "{0}{1}name={2}&registrationType=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!

Linting, style, pep8 etc

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

Is an integration in upstream still pursued?

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 LOCATION/CACHE-CONTROL: different capitalization for directtv device

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.

error 'SonyDevice' object has no attribute 'get_action' (BDV-N9100W)

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

AttributeError: 'SonyDevice' object has no attribute 'uuid'

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'

self.uuid = uuid.uuid4()

At this point the attribute should be there, I do not understand why the error occurs.

Trouble configuring Sony BDP-S590

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:

  • platform: sony
    host: 192.168.20.151
    name: 3D Bluray
    `
    When I restart, it shows that device in the configurator. If I go to "Media Remote Device Registration" on my BluRay player, click "Start Registration," then confirm pin 0000 on the home assistant side, then the player registers Home Assistant. But nothing else ever happens on the home assistant side. Is there more that I need to do? Something in a sony.conf file, maybe? Thanks in advance!

2011 device - HTTP headers required for commands to work after authentication

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.

wakeonlan does not work as expected

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.