Skip to content

Commit

Permalink
Merge pull request #8 from alexmohr/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
alexmohr authored Mar 29, 2019
2 parents 1d2d315 + 47b0246 commit 02a3c3a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
15 changes: 15 additions & 0 deletions convert_to_hass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json
from sonyapilib.device import SonyDevice


config_file = 'bluray.json'

with open(config_file, 'r') as myfile:
data=myfile.read()

device = SonyDevice.load_from_json(data)

hass_cfg = {}
hass_cfg[device.host] = {}
hass_cfg[device.host]["device"] = data
print(json.dumps(hass_cfg), file=open("sony.conf", "w"))
9 changes: 9 additions & 0 deletions discover_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import json
from sonyapilib.ssdp import SSDPDiscovery

ip = "10.0.0.102"
ssdp = SSDPDiscovery()
services = ssdp.discover()
for service in services:
if ip in str(service):
print(service)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# and be sure to test it firstly using "python setup.py register sdist upload -r pypitest"
setup(name='sonyapilib',
packages = ['sonyapilib'], # this must be the same as the name above
version = '0.3.7',
version = '0.3.10',
description = 'Lib to control sony devices with theier soap api',
author = 'Alexander Mohr',
author_email = '[email protected]',
Expand Down
16 changes: 9 additions & 7 deletions sonyapilib/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sonyapilib import ssdp
_LOGGER = logging.getLogger(__name__)

TIMEOUT = 50
TIMEOUT = 5


class AuthenicationResult(Enum):
Expand Down Expand Up @@ -324,12 +324,9 @@ def register(self):

# protocoll version 1 and 2
if registration_action.mode < 3:
registration_response = self.send_http(
self.send_http(
registration_action.url, method=HttpMethod.GET, raise_errors=True)
if registration_response.text == "":
registrataion_result = AuthenicationResult.SUCCESS
else:
registrataion_result = AuthenicationResult.ERROR
registrataion_result = AuthenicationResult.SUCCESS

# protocoll version 3
elif registration_action.mode == 3:
Expand Down Expand Up @@ -377,8 +374,13 @@ def register(self):
return registrataion_result

def send_authentication(self, pin):

registration_action = self.get_action("register")

# they do not need a pin
if registration_action.mode < 3:
return True

self.pin = pin
self.recreate_authentication()

Expand Down Expand Up @@ -519,7 +521,7 @@ def get_playing_status(self):
def get_power_status(self):
url = self.actionlist_url
try:
responst = self.send_http(url, HttpMethod.GET,
response = self.send_http(url, HttpMethod.GET,
log_errors=False, raise_errors=True)
except Exception as ex:
_LOGGER.debug(ex)
Expand Down

0 comments on commit 02a3c3a

Please sign in to comment.