3 from dataclasses import dataclass
6 from typing import Callable
8 # Note: this module is fairly early loaded. Be aware of dependencies.
12 logger = logging.getLogger(__name__)
13 args = config.add_commandline_args(
15 'Args related to __file__'
18 '--site_config_override_location',
22 choices=('HOUSE', 'CABIN', 'NONE'),
23 help='Where are we, HOUSE, CABIN?',
28 class SiteConfig(object):
32 network_router_ip: str
33 presence_location: presence.Location
34 is_anyone_present: Callable[None, bool]
35 arper_minimum_device_count: int
42 >>> location = get_location()
43 >>> location == 'HOUSE' or location == 'CABIN'
47 return get_config().location
50 def is_anyone_present_wrapper(location: presence.Location):
51 p = presence.PresenceDetection()
52 return p.is_anyone_in_location_now(location)
57 Get a configuration dataclass with information that is
58 site-specific including the current running location.
60 >>> cfg = get_config()
61 >>> cfg.location == 'HOUSE' or cfg.location == 'CABIN'
65 hostname = platform.node()
67 location_override = config.config['site_config_override_location']
69 location_override = 'NONE'
70 if location_override == 'NONE':
71 if '.house' in hostname:
73 elif '.cabin' in hostname:
75 if location == 'HOUSE':
78 network = '10.0.0.0/24',
79 network_netmask = '255.255.255.0',
80 network_router_ip = '10.0.0.1',
81 presence_location = presence.Location.HOUSE,
82 is_anyone_present = lambda x=presence.Location.HOUSE: is_anyone_present_wrapper(x),
83 arper_minimum_device_count = 50,
85 elif location == 'CABIN':
88 network = '192.168.0.0/24',
89 network_netmask = '255.255.255.0',
90 network_router_ip = '192.168.0.1',
91 presence_location = presence.Location.CABIN,
92 is_anyone_present = lambda x=presence.Location.CABIN: is_anyone_present_wrapper(x),
93 arper_minimum_device_count = 15,
96 raise Exception(f'Unknown site location: {location}')
99 if __name__ == '__main__':