WIP: Initial work on configurable source device
This commit is contained in:
parent
82ee08a1d7
commit
fa9d5d73c4
5 changed files with 50 additions and 2 deletions
|
@ -5,7 +5,8 @@ import time
|
|||
from decimal import Decimal
|
||||
from typing import cast
|
||||
|
||||
from bluepy import btle
|
||||
from bluepy.btle import BTLEDisconnectError
|
||||
from serial import SerialException
|
||||
|
||||
from .config import get_config, get_consumers
|
||||
from .constants import MAC
|
||||
|
@ -15,12 +16,19 @@ from .solar_types import DataName
|
|||
from .util import Periodical, log
|
||||
|
||||
|
||||
class CommunicationError(BTLEDisconnectError, SerialException):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
conf = get_config()
|
||||
consumers = get_consumers(conf)
|
||||
|
||||
per_voltages = Periodical(interval=15)
|
||||
per_current_hist = Periodical(interval=60)
|
||||
# import serial
|
||||
|
||||
# ser = serial.Serial()
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
@ -96,7 +104,7 @@ def main():
|
|||
# else:
|
||||
# write(wd, CMD_ENABLE_LOAD)
|
||||
|
||||
except btle.BTLEDisconnectError:
|
||||
except CommunicationError:
|
||||
log("ERROR: Disconnected")
|
||||
time.sleep(1)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import importlib
|
||||
import os
|
||||
from io import RawIOBase
|
||||
from time import sleep
|
||||
from typing import Any, Dict, List, Optional, Type
|
||||
|
||||
|
@ -52,6 +53,23 @@ def get_consumers(conf: Optional[Dict[str, Any]] = None) -> List[BaseConsumer]:
|
|||
return consumers
|
||||
|
||||
|
||||
def get_producers(conf: Optional[Dict[str, Any]] = None) -> List[RawIOBase]:
|
||||
raise NotImplementedError
|
||||
if conf is None:
|
||||
conf = get_config()
|
||||
|
||||
consumers = []
|
||||
for name, consumer_config in conf["consumers"].items():
|
||||
# print(name, consumer_config)
|
||||
mod = get_consumer(name)
|
||||
if mod:
|
||||
# print(mod)
|
||||
consumers.append(mod(consumer_config))
|
||||
|
||||
write_config(conf)
|
||||
return consumers
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = get_config()
|
||||
|
||||
|
|
7
srnemqtt/sources/__init__.py
Normal file
7
srnemqtt/sources/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from abc import ABCMeta
|
||||
from io import RawIOBase
|
||||
|
||||
|
||||
class BaseSource(RawIOBase, metaclass=ABCMeta):
|
||||
pass
|
7
srnemqtt/sources/feasycom.py
Normal file
7
srnemqtt/sources/feasycom.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# from ..lib.feasycom_ble import BTLEUart
|
||||
from . import BaseSource
|
||||
|
||||
|
||||
class FeasycomSource(BaseSource):
|
||||
pass
|
8
srnemqtt/sources/serial.py
Normal file
8
srnemqtt/sources/serial.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# import serial
|
||||
|
||||
from . import BaseSource
|
||||
|
||||
|
||||
class SerialSource(BaseSource):
|
||||
pass
|
Loading…
Reference in a new issue