Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 1323e06

Browse files
scopballoob
authored andcommitted
Misc cleanups (#208)
* Use unix linefeeds in canon_printer.py and samsung_printer.py * Remove no longer needed __future__ print_function import * Docstring fixes * Remove some unneeded method overrides * Simplify n.d.konnected.get_entries * Lint tests and top level *.py too * Remove no longer needed module-rgx from pylintrc
1 parent d8ddc4e commit 1323e06

10 files changed

+47
-58
lines changed

example_service.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
Will quit after 2 minutes.
66
77
"""
8-
from __future__ import print_function
9-
108
import logging
119
from datetime import datetime
1210
import time
@@ -24,6 +22,7 @@ def new_service_listener(discoverable, service):
2422
print("{} - Found new service: {} {}".format(
2523
datetime.now(), discoverable, service))
2624

25+
2726
nd.add_listener(new_service_listener)
2827

2928
nd.start()

netdisco/discoverables/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, netdis):
4141
self.netdis = netdis
4242

4343
def info_from_entry(self, entry):
44-
"""Get most important info, by default the description location."""
44+
"""Get most important info."""
4545
url = urlparse(entry.location)
4646
info = {
4747
ATTR_HOST: url.hostname,
@@ -88,10 +88,6 @@ def reset(self):
8888
"""Reset found services."""
8989
self.services.clear()
9090

91-
def is_discovered(self):
92-
"""Return True if any device has been discovered."""
93-
return len(self.get_entries()) > 0
94-
9591
# pylint: disable=unused-argument
9692
def remove_service(self, zconf, typ, name):
9793
"""Callback when a service is removed."""

netdisco/discoverables/cambridgeaudio.py

-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,3 @@ def get_entries(self):
1111
"manufacturer": "Cambridge Audio",
1212
"deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1"
1313
})
14-
15-
def info_from_entry(self, entry):
16-
"""Get most important info, which is name, model and host."""
17-
info = super().info_from_entry(entry)
18-
return info
+13-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"""Discover Canon Printers"""
2-
from . import SSDPDiscoverable
3-
4-
5-
class Discoverable(SSDPDiscoverable):
6-
"""Support for the discovery of Canon Printers"""
7-
8-
def get_entries(self):
9-
"""Get all the Canon Printer uPnP entries."""
10-
return self.find_by_device_description({
11-
"manufacturer": "CANON INC.",
12-
"deviceType": "urn:schemas-cipa-jp:device:DPSPrinter:1"
13-
})
1+
"""Discover Canon Printers"""
2+
from . import SSDPDiscoverable
3+
4+
5+
class Discoverable(SSDPDiscoverable):
6+
"""Support for the discovery of Canon Printers"""
7+
8+
def get_entries(self):
9+
"""Get all the Canon Printer uPnP entries."""
10+
return self.find_by_device_description({
11+
"manufacturer": "CANON INC.",
12+
"deviceType": "urn:schemas-cipa-jp:device:DPSPrinter:1"
13+
})

netdisco/discoverables/konnected.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ class Discoverable(SSDPDiscoverable):
77

88
def get_entries(self):
99
"""Return all Konnected entries."""
10-
results = []
11-
results.extend(
12-
self.find_by_st('urn:schemas-konnected-io:device:Security:1'))
13-
return results
10+
return self.find_by_st('urn:schemas-konnected-io:device:Security:1')
+13-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"""Discover Samsung Printers"""
2-
from . import SSDPDiscoverable
3-
4-
5-
class Discoverable(SSDPDiscoverable):
6-
"""Support for the discovery of Samsung Printers"""
7-
8-
def get_entries(self):
9-
"""Get all the Samsung Printer uPnP entries."""
10-
return self.find_by_device_description({
11-
"manufacturer": "Samsung Electronics",
12-
"deviceType": "urn:schemas-upnp-org:device:Printer:1"
13-
})
1+
"""Discover Samsung Printers"""
2+
from . import SSDPDiscoverable
3+
4+
5+
class Discoverable(SSDPDiscoverable):
6+
"""Support for the discovery of Samsung Printers"""
7+
8+
def get_entries(self):
9+
"""Get all the Samsung Printer uPnP entries."""
10+
return self.find_by_device_description({
11+
"manufacturer": "Samsung Electronics",
12+
"deviceType": "urn:schemas-upnp-org:device:Printer:1"
13+
})

netdisco/gdm.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ def find_by_data(self, values):
4545
def update(self):
4646
"""Scan for new GDM services.
4747
48-
Example of the dict list returned by this function:
49-
[{'data': 'Content-Type: plex/media-server'
50-
'Host: 53f4b5b6023d41182fe88a99b0e714ba.plex.direct'
51-
'Name: myfirstplexserver'
52-
'Port: 32400'
53-
'Resource-Identifier: 646ab0aa8a01c543e94ba975f6fd6efadc36b7'
54-
'Updated-At: 1444852697'
55-
'Version: 0.9.12.13.1464-4ccd2ca'
48+
Example of the dict list assigned to self.entries by this function:
49+
[{'data': {
50+
'Content-Type': 'plex/media-server',
51+
'Host': '53f4b5b6023d41182fe88a99b0e714ba.plex.direct',
52+
'Name': 'myfirstplexserver',
53+
'Port': '32400',
54+
'Resource-Identifier': '646ab0aa8a01c543e94ba975f6fd6efadc36b7',
55+
'Updated-At': '1444852697',
56+
'Version': '0.9.12.13.1464-4ccd2ca',
57+
},
5658
'from': ('10.10.10.100', 32414)}]
5759
"""
5860

pylintrc

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
[MASTER]
22
disable=duplicate-code
3-
4-
[BASIC]
5-
module-rgx=(([a-z_][a-z0-9_]*)|(?:DLNA))$

tests/discoverables/test_yamaha.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def test_info_from_entry_rx_v481(self):
4343
'serial': 'XXXXXXXX',
4444
'ssdp_description': 'http://192.168.XXX.XXX:80/desc.xml',
4545
'udn': 'uuid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
46-
'upnp_device_type': 'urn:schemas-upnp-org:device:MediaRenderer:1',
46+
'upnp_device_type':
47+
'urn:schemas-upnp-org:device:MediaRenderer:1',
4748
})
4849

4950
def test_info_from_entry_single_service(self):
@@ -110,14 +111,16 @@ def test_info_from_entry_multiple_services_no_remote_control(self):
110111
})
111112

112113
def test_get_entries_incompatible_models(self):
113-
supported_model = MockUPNPEntry("desc_multiple_services_no_remote_control.xml")
114+
supported_model = MockUPNPEntry(
115+
"desc_multiple_services_no_remote_control.xml")
114116
devices = [
115117
supported_model,
116118
MockUPNPEntry("desc_incompatible_device.xml")
117119
]
118120

119121
discoverable = Discoverable(None)
120122
discoverable.INCOMPATIBLE_MODELS = ["aaa"]
121-
discoverable.find_by_device_description = MagicMock(return_value=devices)
123+
discoverable.find_by_device_description = MagicMock(
124+
return_value=devices)
122125

123126
self.assertEqual(discoverable.get_entries(), [supported_model])

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ deps =
1616
flake8
1717
pylint
1818
commands =
19-
flake8 netdisco
20-
pylint netdisco
19+
flake8 netdisco tests setup.py example_service.py
20+
pylint netdisco tests

0 commit comments

Comments
 (0)