Skip to content

Commit

Permalink
fix: Fix imports in main script.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjw committed Dec 9, 2021
1 parent 9318a4c commit 6fa43c8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
12 changes: 3 additions & 9 deletions bin/prom433
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ import threading
import subprocess
import sys

from prom433 import get_arguments, connect, serve, update_stats

def run_subprocess(args):
rtl = subprocess.run(f"rtl_433 {args.rtl} -F json", stdout=subprocess.PIPE)

for line in rtl.stdout:
update_stats(line)
from prom433 import get_arguments, serve, rtl433, prometheus

def main():
args = get_arguments(sys.argv[1:])

threading.Thread(target=run_subprocess,
args=(args, ),
threading.Thread(target=rtl433,
args=(args.rtl, prometheus),
daemon=True).start()

serve(args)
Expand Down
1 change: 1 addition & 0 deletions prom433/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .arguments import get_arguments
from .child_process import rtl433
from .exceptions import InvalidArguments
from .prometheus import prometheus, get_metrics
from .server import serve
Expand Down
2 changes: 1 addition & 1 deletion prom433/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
parser = argparse.ArgumentParser(
description='Listens to meter reports from Glow (glowmarkt.com) MQTT and'
+ ' exposes them as prometheus metrics')
parser.add_argument('--rtl', type=str, nargs='?',
parser.add_argument('--rtl', type=str, nargs='?', default="",
help='Arguments to pass to rtl_433')
parser.add_argument('--bind', type=str, nargs='?', default="0.0.0.0:9100",
help='the ip address and port to bind to')
Expand Down
3 changes: 2 additions & 1 deletion prom433/child_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@


def rtl433(args, callback, _popen=subprocess.Popen):
process = _popen(["rtl_433", "-f", "json"] + args, stdout=subprocess.PIPE)
process = _popen(["rtl_433", "-f", "json"] + args.split(" "),
stdout=subprocess.PIPE)
for line in process.stdout.readlines():
if not line.startswith("{"):
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/test_prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, buffer):

class TestPrometheus(unittest.TestCase):
def test_prometheus(self):
child_process.rtl433([], prometheus, _popen=mock_popen)
child_process.rtl433("", prometheus, _popen=mock_popen)

prom = get_metrics()
print(prom)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_error(self):
self.assertTrue("404" in handler.wfile.read().decode("utf8"))

def test_metrics(self):
child_process.rtl433([], prometheus, _popen=mock_popen)
child_process.rtl433("", prometheus, _popen=mock_popen)

handler = MockHandler()
handler.path = "/metrics"
Expand Down

0 comments on commit 6fa43c8

Please sign in to comment.