Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global broadcast address #72

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading