From d08bad64a6884f25d28a2c38c6cd1c87b4335188 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 23 Oct 2021 23:49:08 -0700 Subject: Adds site_config; adds Tuya lights. Bugfixes. --- site_config.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 site_config.py (limited to 'site_config.py') 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') -- cgit v1.3