コード例 #1
0
ファイル: mqread.py プロジェクト: EdGetMeLink/pizstrip
def main():  # pragma: no cover
    cfg = load_config()
    queue = Queue()
    mqttc = setup_mqtt(cfg, queue)
    mqttc.loop_start()
    exit = 0
    while exit <= 10:
        time.sleep(1)
        exit += 1
    mqttc.loop_stop()
コード例 #2
0
ファイル: test_config.py プロジェクト: EdGetMeLink/pizstrip
def test_load_mqtt_no_server_settings():
    '''
    load mqtt settings from config file
    '''
    cfg = load_config(
        filename='app.test.no_mqtt_server.ini',
        lookup_options={'search_path': 'tests/testdata'})
    try:
        load_mqtt_settings(cfg)
        ret = False
    except NoMqttServerSetting:
        ret = True
    assert ret
コード例 #3
0
ファイル: test_config.py プロジェクト: EdGetMeLink/pizstrip
def test_load_missing_mqtt_settings():
    '''
    load mqtt settings from config file
    '''
    cfg = load_config(
        filename='app.test.nomqtt.ini',
        lookup_options={'search_path': 'tests/testdata'})
    try:
        load_mqtt_settings(cfg)
        result = False
    except NoMqttConfigSection:
        result = True
    assert result
コード例 #4
0
ファイル: test_config.py プロジェクト: EdGetMeLink/pizstrip
def test_load_mqtt_default_settings():
    '''
    load mqtt settings from config file
    '''
    cfg = load_config(
        filename='app.test.default_mqtt.ini',
        lookup_options={'search_path': 'tests/testdata'})
    mqtt = load_mqtt_settings(cfg)
    expected = {
        "server": "test.server.local",
        "port": 1883,
        "fg_topic": "pizstrip/fg",
        "bg_topic": "pizstrip/bg",
    }

    assert mqtt == expected
コード例 #5
0
ファイル: main.py プロジェクト: EdGetMeLink/pizstrip
def start():
    cfg = load_config()
    clear_screen()
    setup_logging()
    queue = Queue()
    runner = start_runner(queue, cfg)
    mqttc = setup_mqtt(cfg, queue)
    mqttc.loop_start()

    color = get_color_class()
    alive_timer = 10
    timer = 0
    mqttc.publish(mqttc.config["alive_topic"], cfg.get("mqtt",
                                                       "alive_message"))

    while runner.is_alive():
        try:
            time.sleep(1)
            if timer == alive_timer:
                mqttc.publish(mqttc.config["alive_topic"],
                              cfg.get("mqtt", "alive_message"))
            else:
                timer += 1
        except (KeyboardInterrupt, SystemExit):
            LOG.info("Stopped by Keyboard or System Exit")
            runner.exitflag = True
            runner.join()
            mqttc.will_clear()
            mqttc.publish(mqttc.config["alive_topic"],
                          cfg.get("mqtt", "dead_message"))
            mqttc.loop_stop()
        except Exception:
            LOG.exception("Exception caused crash")
            runner.exitflag = True
            runner.join()
            mqttc.will_clear()
            mqttc.publish(mqttc.config["alive_topic"],
                          cfg.get("mqtt", "dead_message"))
            mqttc.loop_stop()
            raise