Used isort to sort imports. Also added to the git pre-commit hook.
[python_utils.git] / site_config.py
index 2d0c4c3f866c748027ccc5ab84f15d2b0f26d554..233589970ea2058b2768de16ec649602eda2be2f 100644 (file)
@@ -1,27 +1,27 @@
 #!/usr/bin/env python3
 
-from dataclasses import dataclass
 import logging
 import platform
+from dataclasses import dataclass
 from typing import Callable
 
 # Note: this module is fairly early loaded.  Be aware of dependencies.
 import config
-from locations import Location
+from type.locations import Location
 
 logger = logging.getLogger(__name__)
 
 args = config.add_commandline_args(
-    f'({__file__})',
-    'Args related to __file__'
+    f'Global Site Config ({__file__})',
+    'Args related to global site-specific configuration',
 )
 args.add_argument(
     '--site_config_override_location',
     default='NONE',
     const='NONE',
     nargs='?',
-    choices=('HOUSE', 'CABIN', 'NONE'),
-    help='Where are we, HOUSE, CABIN?',
+    choices=['HOUSE', 'CABIN', 'NONE'],
+    help='Where are we, HOUSE, CABIN?  Overrides standard detection code.',
 )
 
 
@@ -33,7 +33,7 @@ class SiteConfig(object):
     network_netmask: str
     network_router_ip: str
     presence_location: Location
-    is_anyone_present: Callable[None, bool]
+    is_anyone_present: Callable
     arper_minimum_device_count: int
 
 
@@ -53,7 +53,7 @@ def get_location():
     """
     Returns location as an enum instead of a string.
 
-    >>> from locations import Location
+    >>> from type.locations import Location
     >>> location = get_location()
     >>> location == Location.HOUSE or location == Location.CABIN
     True
@@ -63,8 +63,9 @@ def get_location():
 
 
 def is_anyone_present_wrapper(location: Location):
-    import presence
-    p = presence.PresenceDetection()
+    import base_presence
+
+    p = base_presence.PresenceDetection()
     return p.is_anyone_in_location_now(location)
 
 
@@ -90,25 +91,25 @@ def get_config():
             location = 'CABIN'
     if location == 'HOUSE':
         return SiteConfig(
-            location_name = 'HOUSE',
-            location = Location.HOUSE,
-            network = '10.0.0.0/24',
-            network_netmask = '255.255.255.0',
-            network_router_ip = '10.0.0.1',
-            presence_location = Location.HOUSE,
-            is_anyone_present = lambda x=Location.HOUSE: is_anyone_present_wrapper(x),
-            arper_minimum_device_count = 50,
+            location_name='HOUSE',
+            location=Location.HOUSE,
+            network='10.0.0.0/24',
+            network_netmask='255.255.255.0',
+            network_router_ip='10.0.0.1',
+            presence_location=Location.HOUSE,
+            is_anyone_present=lambda x=Location.HOUSE: is_anyone_present_wrapper(x),
+            arper_minimum_device_count=50,
         )
     elif location == 'CABIN':
         return SiteConfig(
-            location_name = 'CABIN',
-            location = Location.CABIN,
-            network = '192.168.0.0/24',
-            network_netmask = '255.255.255.0',
-            network_router_ip = '192.168.0.1',
-            presence_location = Location.CABIN,
-            is_anyone_present = lambda x=Location.CABIN: is_anyone_present_wrapper(x),
-            arper_minimum_device_count = 15,
+            location_name='CABIN',
+            location=Location.CABIN,
+            network='192.168.0.0/24',
+            network_netmask='255.255.255.0',
+            network_router_ip='192.168.0.1',
+            presence_location=Location.CABIN,
+            is_anyone_present=lambda x=Location.CABIN: is_anyone_present_wrapper(x),
+            arper_minimum_device_count=15,
         )
     else:
         raise Exception(f'Unknown site location: {location}')
@@ -116,4 +117,5 @@ def get_config():
 
 if __name__ == '__main__':
     import doctest
+
     doctest.testmod()