Exemple #1
0
def test_parse_config(
    mock_sqlite,
):
    config = MockConfigParser('sqlite', include_extra_section=True)
    emitters = parse_config(config)
    assert len(emitters) == 1
    assert str(type(emitters[0])) == "<class 'tilty.emitters.sqlite.SQLite'>"
Exemple #2
0
def scan_and_emit_thread(device: tilt_device.TiltDevice,
                         config: configparser.ConfigParser,
                         keep_running: bool = False) -> None:
    """ method that calls the needful

    Args:
        device (TiltDevice): The bluetooth device to operate on.
        config (dict): The parsed configuration
        keep_running (bool): Whether or not to keep running. Default: False
    """
    emitters = parse_config(config)
    click.echo('Scanning for Tilt data...')

    gravity_offset = float(
        safe_get_key(CONFIG, 'general', {}).get('gravity_offset', '0'))
    LOGGER.debug('Gravity offset: %f', gravity_offset)
    temperature_offset = float(
        safe_get_key(CONFIG, 'general', {}).get('temperature_offset', '0'))
    LOGGER.debug('Temperature offset: %f', temperature_offset)

    scan_and_emit(device, emitters, gravity_offset, temperature_offset)
    while keep_running:
        LOGGER.debug('Scanning for Tilt data...')
        try:
            scan_and_emit(device, emitters, gravity_offset, temperature_offset)
        except Exception as exception:  # pylint: disable=broad-except
            LOGGER.error("%s\n%s", str(exception),
                         traceback.format_tb(exception.__traceback__))
        sleep_time = int(CONFIG['general'].get('sleep_interval', '1'))
        LOGGER.debug('Sleeping for %s....', sleep_time)
        sleep(sleep_time)
Exemple #3
0
def scan_and_emit_thread(
    device: tilt_device.TiltDevice,
    config: configparser.ConfigParser,
    keep_running: bool = False
) -> None:
    """ method that calls the needful

    Args:
        device (TiltDevice): The bluetooth device to operate on.
        config (dict): The parsed configuration
        keep_running (bool): Whether or not to keep running. Default: False
    """
    emitters = parse_config(config)
    click.echo('Scanning for Tilt data...')
    scan_and_emit(device, emitters)
    while keep_running:
        LOGGER.debug('Scanning for Tilt data...')
        scan_and_emit(device, emitters)
        sleep_time = int(CONFIG['general'].get('sleep_interval', '1'))
        LOGGER.debug('Sleeping for %s....', sleep_time)
        sleep(sleep_time)
Exemple #4
0
def scan_and_emit_thread(device: tilt_device.TiltDevice,
                         config: configparser.ConfigParser,
                         keep_running: threading.Event) -> None:
    """ method that calls the needful

    Args:
        device (TiltDevice): The bluetooth device to operate on.
        config (dict): The parsed configuration
        keep_running (threading.Event): Whether or not to keep running. Default: False
    """
    emitters = parse_config(config)
    click.echo('Scanning for Tilt data...')
    scan_and_emit(device, emitters)
    while keep_running.is_set():
        LOGGER.debug('Scanning for Tilt data...')
        try:
            scan_and_emit(device, emitters)
        except Exception as exception:  # pylint: disable=broad-except
            LOGGER.error("%s\n%s", str(exception),
                         traceback.format_tb(exception.__traceback__))
        sleep_time = int(CONFIG['general'].get('sleep_interval', '1'))
        LOGGER.debug('Sleeping for %s....', sleep_time)
        sleep(sleep_time)
Exemple #5
0
def test_parse_config_invalid_emitter():
    with pytest.raises(ModuleNotFoundError):
        config = MockConfigParser('', include_extra_section=True)
        emitters = parse_config(config)
        assert not emitters
Exemple #6
0
def test_parse_config_empty():
    with pytest.raises(ConfigurationFileEmptyException):
        config = MockConfigParser('', return_empty=True)
        emitters = parse_config(config)
        assert not emitters