summaryrefslogtreecommitdiff
path: root/src/home/mqtt/util.py
blob: 78cbcaa70d5643a41f7db75c6f4f01a4c2f8a9d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import time
import os
import re
import importlib

from typing import List


def poll_tick(freq):
    t = time.time()
    while True:
        t += freq
        yield max(t - time.time(), 0)


def get_modules() -> List[str]:
    modules = []
    for name in os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'module')):
        name = re.sub(r'\.py$', '', name)
        modules.append(name)
    return modules


def import_module(module: str):
    return importlib.import_module(
        f'..module.{module}', __name__)