From 12f1be9b1c4b5ce4b86f8fee8a222bec59f50074 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 6 Oct 2016 02:32:29 +0200 Subject: [PATCH] Fix PEP257 issues and ordering (#3720) --- .../components/device_tracker/owntracks.py | 30 ++++++++++--------- .../device_tracker/test_owntracks.py | 27 ++++++++++------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/device_tracker/owntracks.py b/homeassistant/components/device_tracker/owntracks.py index 619d3f0ee5d..d903c25a5c8 100644 --- a/homeassistant/components/device_tracker/owntracks.py +++ b/homeassistant/components/device_tracker/owntracks.py @@ -19,26 +19,27 @@ from homeassistant.util import convert, slugify from homeassistant.components import zone as zone_comp from homeassistant.components.device_tracker import PLATFORM_SCHEMA -DEPENDENCIES = ['mqtt'] REQUIREMENTS = ['libnacl==1.5.0'] -REGIONS_ENTERED = defaultdict(list) -MOBILE_BEACONS_ACTIVE = defaultdict(list) - -BEACON_DEV_ID = 'beacon' - -LOCATION_TOPIC = 'owntracks/+/+' -EVENT_TOPIC = 'owntracks/+/+/event' -WAYPOINT_TOPIC = 'owntracks/{}/{}/waypoint' - _LOGGER = logging.getLogger(__name__) -LOCK = threading.Lock() +BEACON_DEV_ID = 'beacon' CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy' +CONF_SECRET = 'secret' CONF_WAYPOINT_IMPORT = 'waypoints' CONF_WAYPOINT_WHITELIST = 'waypoint_whitelist' -CONF_SECRET = 'secret' + +DEPENDENCIES = ['mqtt'] + +EVENT_TOPIC = 'owntracks/+/+/event' + +LOCATION_TOPIC = 'owntracks/+/+' +LOCK = threading.Lock() + +MOBILE_BEACONS_ACTIVE = defaultdict(list) + +REGIONS_ENTERED = defaultdict(list) VALIDATE_LOCATION = 'location' VALIDATE_TRANSITION = 'transition' @@ -46,6 +47,7 @@ VALIDATE_WAYPOINTS = 'waypoints' WAYPOINT_LAT_KEY = 'lat' WAYPOINT_LON_KEY = 'lon' +WAYPOINT_TOPIC = 'owntracks/{}/{}/waypoint' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_MAX_GPS_ACCURACY): vol.Coerce(float), @@ -70,7 +72,7 @@ def get_cipher(): def setup_scanner(hass, config, see): - """Setup an OwnTracks tracker.""" + """Set up an OwnTracks tracker.""" max_gps_accuracy = config.get(CONF_MAX_GPS_ACCURACY) waypoint_import = config.get(CONF_WAYPOINT_IMPORT) waypoint_whitelist = config.get(CONF_WAYPOINT_WHITELIST) @@ -113,7 +115,7 @@ def setup_scanner(hass, config, see): return None def validate_payload(topic, payload, data_type): - """Validate OwnTracks payload.""" + """Validate the OwnTracks payload.""" # pylint: disable=too-many-return-statements try: diff --git a/tests/components/device_tracker/test_owntracks.py b/tests/components/device_tracker/test_owntracks.py index ef3d79d089b..9ee9c80dc43 100644 --- a/tests/components/device_tracker/test_owntracks.py +++ b/tests/components/device_tracker/test_owntracks.py @@ -17,17 +17,17 @@ from tests.common import ( USER = 'greg' DEVICE = 'phone' -LOCATION_TOPIC = "owntracks/{}/{}".format(USER, DEVICE) -EVENT_TOPIC = "owntracks/{}/{}/event".format(USER, DEVICE) +LOCATION_TOPIC = 'owntracks/{}/{}'.format(USER, DEVICE) +EVENT_TOPIC = 'owntracks/{}/{}/event'.format(USER, DEVICE) WAYPOINT_TOPIC = owntracks.WAYPOINT_TOPIC.format(USER, DEVICE) USER_BLACKLIST = 'ram' -WAYPOINT_TOPIC_BLOCKED = owntracks.WAYPOINT_TOPIC.format(USER_BLACKLIST, - DEVICE) +WAYPOINT_TOPIC_BLOCKED = owntracks.WAYPOINT_TOPIC.format( + USER_BLACKLIST, DEVICE) -DEVICE_TRACKER_STATE = "device_tracker.{}_{}".format(USER, DEVICE) +DEVICE_TRACKER_STATE = 'device_tracker.{}_{}'.format(USER, DEVICE) IBEACON_DEVICE = 'keys' -REGION_TRACKER_STATE = "device_tracker.beacon_{}".format(IBEACON_DEVICE) +REGION_TRACKER_STATE = 'device_tracker.beacon_{}'.format(IBEACON_DEVICE) CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy' CONF_WAYPOINT_IMPORT = owntracks.CONF_WAYPOINT_IMPORT @@ -186,7 +186,7 @@ REGION_LEAVE_ZERO_MESSAGE = { BAD_JSON_PREFIX = '--$this is bad json#--' BAD_JSON_SUFFIX = '** and it ends here ^^' -SECRET_KEY = "s3cretkey" +SECRET_KEY = 's3cretkey' ENCRYPTED_LOCATION_MESSAGE = { # Encrypted version of LOCATION_MESSAGE using libsodium and SECRET_KEY '_type': 'encrypted', @@ -678,8 +678,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): except (ImportError, OSError): libnacl = None - @unittest.skipUnless(libnacl, - "libnacl/libsodium is not installed") + @unittest.skipUnless(libnacl, "libnacl/libsodium is not installed") def test_encrypted_payload_libsodium(self): """Test sending encrypted message payload.""" self.assertTrue(device_tracker.setup(self.hass, { @@ -705,6 +704,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher) def test_encrypted_payload(self): + """Test encrypted payload.""" self.assertTrue(device_tracker.setup(self.hass, { device_tracker.DOMAIN: { CONF_PLATFORM: 'owntracks', @@ -716,6 +716,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher) def test_encrypted_payload_topic_key(self): + """Test encrypted payload with a topic key.""" self.assertTrue(device_tracker.setup(self.hass, { device_tracker.DOMAIN: { CONF_PLATFORM: 'owntracks', @@ -728,6 +729,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher) def test_encrypted_payload_no_key(self): + """Test encrypted payload with no key.""" self.assertTrue(device_tracker.setup(self.hass, { device_tracker.DOMAIN: { CONF_PLATFORM: 'owntracks', @@ -739,6 +741,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher) def test_encrypted_payload_wrong_key(self): + """Test encrypted payload with wrong key.""" self.assertTrue(device_tracker.setup(self.hass, { device_tracker.DOMAIN: { CONF_PLATFORM: 'owntracks', @@ -750,11 +753,12 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher) def test_encrypted_payload_wrong_topic_key(self): + """Test encrypted payload with wrong topic key.""" self.assertTrue(device_tracker.setup(self.hass, { device_tracker.DOMAIN: { CONF_PLATFORM: 'owntracks', CONF_SECRET: { - LOCATION_TOPIC: "wrong key" + LOCATION_TOPIC: 'wrong key' }}})) self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE) self.assert_location_latitude(None) @@ -762,11 +766,12 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher) def test_encrypted_payload_no_topic_key(self): + """Test encrypted payload with no topic key.""" self.assertTrue(device_tracker.setup(self.hass, { device_tracker.DOMAIN: { CONF_PLATFORM: 'owntracks', CONF_SECRET: { - "owntracks/{}/{}".format(USER, "otherdevice"): "foobar" + 'owntracks/{}/{}'.format(USER, 'otherdevice'): 'foobar' }}})) self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE) self.assert_location_latitude(None)