from os import sys, path USAGE = ''' python3 read.py [device] DEVICE: flora Mi Flower Care mijia Mijia Temperature & Humidity sensor ''' def UsageAndExit(msg): if msg: print(msg) print(USAGE) sys.exit(0) if __name__ == '__main__' and __package__ is None: sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from dynamo import save_data argv = sys.argv[1:] if len(argv) != 2: UsageAndExit() supported_devices = ['flora', 'mijia'] if argv[0] not in supported_devices: UsageAndExit("Unsupported devices") device, mac_addr = argv if device == 'flora': from miflora.miflora.miflora_poller import MiFloraPoller poller = MiFloraPoller(mac_addr) elif device == 'mijia': from mijia.mijia.mijia_poller import MijiaPoller poller = MijiaPoller(mac_addr) save_data(device, poller)