Skip to content

Commit

Permalink
Add global broadcast address
Browse files Browse the repository at this point in the history
  • Loading branch information
Liborsaf authored and alexmohr committed Apr 19, 2024
1 parent dfba585 commit dc4bda0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sonyapilib/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class SonyDevice:
"""Contains all data for the device."""

def __init__(self, host, nickname, psk=None,
broadcast_address="255.255.255.255",
app_port=50202, dmr_port=52323, ircc_port=50001,
client_id=None):
# pylint: disable=too-many-arguments
Expand All @@ -152,6 +153,8 @@ def __init__(self, host, nickname, psk=None,
self.app_url = None
self.psk = psk

self.broadcast_address = broadcast_address

self.app_port = app_port
self.dmr_port = dmr_port
self.ircc_port = ircc_port
Expand Down Expand Up @@ -194,6 +197,8 @@ def __init__(self, host, nickname, psk=None,

def init_device(self):
"""Update this object with data from the device"""
self._set_value('broadcast_address', '255.255.255.255')

self._update_service_urls()
self._update_commands()
self._add_headers()
Expand Down Expand Up @@ -823,7 +828,8 @@ def send_authentication(self, pin):

def wakeonlan(self, broadcast=None):
"""Start the device via wakeonlan."""
broadcast = broadcast or '255.255.255.255'
broadcast = broadcast or self.broadcast_address

if self.mac:
wakeonlan.send_magic_packet(self.mac, ip_address=broadcast)

Expand Down Expand Up @@ -920,7 +926,7 @@ def start_app(self, app_name):
self._send_http(url, HttpMethod.POST,
cookies=self._recreate_auth_cookie())

def power(self, power_on, broadcast='255.255.255.255'):
def power(self, power_on, broadcast=None):
"""Powers the device on or shuts it off."""
if power_on:
self.wakeonlan(broadcast)
Expand Down
1 change: 1 addition & 0 deletions tests/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ def verify_json_load_fields(self, device):
self.assertEqual(device.rendering_control_url, "http://test:52323/upnp/control/RenderingControl")
self.assertEqual(device.dmr_base, "http://test:52323")
self.assertEqual(device.ircc_base, "http://test:50001")
self.assertEqual(device.broadcast_address, "255.255.255.255")

self.verify_system_info_fields(device, "BDP-S5500", "BDP-2015", [
"http://test:52323/bdp_ax_device_icon_large.jpg",
Expand Down

0 comments on commit dc4bda0

Please sign in to comment.