summaryrefslogtreecommitdiff
path: root/site_config.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-10-23 23:49:08 -0700
committerScott Gasch <[email protected]>2021-10-23 23:49:08 -0700
commitd08bad64a6884f25d28a2c38c6cd1c87b4335188 (patch)
tree9d0e4381b4da1a543acf907b769d1d4d88a3377e /site_config.py
parent351e77c767c9084aa486eedbdc9902c635b06261 (diff)
Adds site_config; adds Tuya lights. Bugfixes.
Diffstat (limited to 'site_config.py')
-rw-r--r--site_config.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/site_config.py b/site_config.py
new file mode 100644
index 0000000..81185bf
--- /dev/null
+++ b/site_config.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+
+from dataclasses import dataclass
+import logging
+import platform
+from typing import Optional
+
+import config
+
+logger = logging.getLogger(__name__)
+args = config.add_commandline_args(
+ f'({__file__})',
+ 'Args related to __file__'
+)
+
+args.add_argument(
+ '--site_config_location',
+ default='AUTO',
+ const='AUTO',
+ nargs='?',
+ choices=('HOUSE', 'CABIN', 'AUTO'),
+ help='Where are we, HOUSE or CABIN?'
+)
+
+
+@dataclass
+class SiteConfig(object):
+ network: str
+ network_netmask: str
+ network_router_ip: str
+
+
+def get_location():
+ location = config.config['site_config_location']
+ if location == 'AUTO':
+ hostname = platform.node()
+ if '.house' in hostname:
+ location = 'HOUSE'
+ elif '.cabin' in hostname:
+ location = 'CABIN'
+ else:
+ raise Exception(f'Unknown hostname {hostname}, help.')
+ return location
+
+
+def get_config():
+ location = get_location()
+ if location == 'HOUSE':
+ return SiteConfig(
+ network = '10.0.0.0/24',
+ network_netmask = '255.255.255.0',
+ network_router_ip = '10.0.0.1',
+ )
+ elif location == 'CABIN':
+ return SiteConfig(
+ network = '192.168.0.0/24',
+ network_netmask = '255.255.255.0',
+ network_router_ip = '192.168.0.1',
+ )
+ else:
+ raise Exception('Unknown site location')