diff --git a/convert_to_hass.py b/convert_to_hass.py new file mode 100644 index 0000000..f7ffab6 --- /dev/null +++ b/convert_to_hass.py @@ -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")) \ No newline at end of file diff --git a/discover_devices.py b/discover_devices.py new file mode 100644 index 0000000..5e01e30 --- /dev/null +++ b/discover_devices.py @@ -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) diff --git a/setup.py b/setup.py index 523f537..65d2171 100644 --- a/setup.py +++ b/setup.py @@ -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 = 'sonyapilib@mohr.io', diff --git a/sonyapilib/device.py b/sonyapilib/device.py index e3aa84e..1c915b6 100644 --- a/sonyapilib/device.py +++ b/sonyapilib/device.py @@ -20,7 +20,7 @@ from sonyapilib import ssdp _LOGGER = logging.getLogger(__name__) -TIMEOUT = 50 +TIMEOUT = 5 class AuthenicationResult(Enum): @@ -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: @@ -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() @@ -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)