summaryrefslogtreecommitdiff
path: root/site_config.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-02-04 09:48:56 -0800
committerScott Gasch <[email protected]>2022-02-04 09:48:56 -0800
commit65e6f781dffb268be6ef0a015f4cc89b57b62a5e (patch)
tree80ac6d76f9590b2884fe988a99f39f12fc8ffcdc /site_config.py
parent94c8a54eadbf8552fa4d33dc349616d125e1a638 (diff)
Stop trying to cache mac addresses from house and cabin in the same
file.
Diffstat (limited to 'site_config.py')
-rw-r--r--site_config.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/site_config.py b/site_config.py
index 2335899..3bf049e 100644
--- a/site_config.py
+++ b/site_config.py
@@ -3,7 +3,7 @@
import logging
import platform
from dataclasses import dataclass
-from typing import Callable
+from typing import Callable, Optional
# Note: this module is fairly early loaded. Be aware of dependencies.
import config
@@ -35,6 +35,7 @@ class SiteConfig(object):
presence_location: Location
is_anyone_present: Callable
arper_minimum_device_count: int
+ arper_cache_file: str
def get_location_name():
@@ -69,7 +70,29 @@ def is_anyone_present_wrapper(location: Location):
return p.is_anyone_in_location_now(location)
-def get_config():
+def other_location() -> str:
+ hostname = platform.node()
+ if '.house' in hostname:
+ location = 'CABIN'
+ elif '.cabin' in hostname:
+ location = 'HOUSE'
+ else:
+ raise Exception(f"{hostname} doesn't help me know where I'm running?!")
+ return location
+
+
+def this_location() -> str:
+ hostname = platform.node()
+ if '.house' in hostname:
+ location = 'HOUSE'
+ elif '.cabin' in hostname:
+ location = 'CABIN'
+ else:
+ raise Exception(f"{hostname} doesn't help me know where I'm running?!")
+ return location
+
+
+def get_config(location_override: Optional[str] = None):
"""
Get a configuration dataclass with information that is
site-specific including the current running location.
@@ -79,16 +102,17 @@ def get_config():
True
"""
- hostname = platform.node()
- try:
- location_override = config.config['site_config_override_location']
- except KeyError:
- location_override = 'NONE'
- if location_override == 'NONE':
- if '.house' in hostname:
- location = 'HOUSE'
- elif '.cabin' in hostname:
- location = 'CABIN'
+ if location_override is None:
+ try:
+ location_override = config.config['site_config_override_location']
+ except KeyError:
+ location_override = None
+
+ if location_override is None or location_override == 'NONE':
+ location = this_location()
+ else:
+ location = location_override
+
if location == 'HOUSE':
return SiteConfig(
location_name='HOUSE',
@@ -99,6 +123,7 @@ def get_config():
presence_location=Location.HOUSE,
is_anyone_present=lambda x=Location.HOUSE: is_anyone_present_wrapper(x),
arper_minimum_device_count=50,
+ arper_cache_file='/home/scott/cache/.arp_table_cache_house',
)
elif location == 'CABIN':
return SiteConfig(
@@ -110,6 +135,7 @@ def get_config():
presence_location=Location.CABIN,
is_anyone_present=lambda x=Location.CABIN: is_anyone_present_wrapper(x),
arper_minimum_device_count=15,
+ arper_cache_file='/home/scott/cache/.arp_table_cache_cabin',
)
else:
raise Exception(f'Unknown site location: {location}')