3 from dataclasses import dataclass
6 from typing import Callable, Optional
11 logger = logging.getLogger(__name__)
12 args = config.add_commandline_args(
14 'Args related to __file__'
17 '--site_config_override_location',
21 choices=('HOUSE', 'CABIN', 'NONE'),
22 help='Where are we, HOUSE, CABIN?',
27 class SiteConfig(object):
31 network_router_ip: str
32 presence_location: presence.Location
33 is_anyone_present: Callable[None, bool]
40 >>> location = get_location()
41 >>> location == 'HOUSE' or location == 'CABIN'
45 return get_config().location
48 def is_anyone_present_wrapper(location: presence.Location):
49 p = presence.PresenceDetection()
50 return p.is_anyone_in_location_now(location)
55 Get a configuration dataclass with information that is
56 site-specific including the current running location.
58 >>> cfg = get_config()
59 >>> cfg.location == 'HOUSE' or cfg.location == 'CABIN'
63 hostname = platform.node()
65 location_override = config.config['site_config_override_location']
67 location_override = 'NONE'
68 if location_override == 'NONE':
69 if '.house' in hostname:
71 elif '.cabin' in hostname:
73 if location == 'HOUSE':
76 network = '10.0.0.0/24',
77 network_netmask = '255.255.255.0',
78 network_router_ip = '10.0.0.1',
79 presence_location = presence.Location.HOUSE,
80 is_anyone_present = lambda x=presence.Location.HOUSE: is_anyone_present_wrapper(x),
82 elif location == 'CABIN':
85 network = '192.168.0.0/24',
86 network_netmask = '255.255.255.0',
87 network_router_ip = '192.168.0.1',
88 presence_location = presence.Location.CABIN,
89 is_anyone_present = lambda x=presence.Location.CABIN: is_anyone_present_wrapper(x),
92 raise Exception(f'Unknown site location: {location}')
95 if __name__ == '__main__':