Added dynamic platform loader

This commit is contained in:
Pünkösd Marcell 2021-11-19 02:18:58 +01:00
parent 8f976721ab
commit 6b47c3f555
8 changed files with 28 additions and 10 deletions

View File

@ -1,9 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import random
import os
import os.path
from .abcactuator import AbcActuator from .abcactuator import AbcActuator
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformPlaybackDriver, BirbnetesIoTPlatformStatusDriver from utils import BirbnetesIoTPlatformPlaybackDriver, BirbnetesIoTPlatformStatusDriver
""" """
Abstract base class for Sender Abstract base class for Sender

View File

@ -6,7 +6,7 @@ import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.logging import LoggingIntegration
from utils import LoopingTimer from utils import LoopingTimer
from signal_processor import SoundSignalProcessor from signal_processor import SoundSignalProcessor
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver, BirbnetesIoTPlatformRecordDriver from utils import BirbnetesIoTPlatformStatusDriver, BirbnetesIoTPlatformRecordDriver
from actuator import Loudspeaker from actuator import Loudspeaker
import paho.mqtt.client import paho.mqtt.client
import json import json

View File

@ -15,7 +15,7 @@ if not config.DISABLE_AI:
from pyAudioAnalysis import MidTermFeatures from pyAudioAnalysis import MidTermFeatures
import numpy import numpy
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver from utils import BirbnetesIoTPlatformStatusDriver
""" """
Abstract base class for Sender Abstract base class for Sender
@ -150,7 +150,7 @@ class SoundPreProcessorLegit(AbcPreProcessor):
class SoundPreProcessorDummy(AbcPreProcessor): class SoundPreProcessorDummy(AbcPreProcessor):
def __init__(self): def __init__(self):
print("AI is disabled! Initializing dummy sound pre-processor...") logging.info("AI is disabled! Initializing dummy sound pre-processor...")
def preprocesssignal(self, file_path) -> bool: def preprocesssignal(self, file_path) -> bool:
return True return True

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from typing import Optional from typing import Optional
from .abcsensor import AbcSensor from .abcsensor import AbcSensor
from utils import config from utils import config, BirbnetesIoTPlatformRecordDriver
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformRecordDriver
""" """
Sound sensor high level API Sound sensor high level API

View File

@ -7,7 +7,7 @@ from preprocessor import SoundPreProcessor
from .abcsignalprocessor import AbcSignalProcessor from .abcsignalprocessor import AbcSignalProcessor
import os import os
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver from utils import BirbnetesIoTPlatformStatusDriver
""" """
Abstract base class for signalprocessor Abstract base class for signalprocessor

View File

@ -1,2 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from .loopingtimer import LoopingTimer from .loopingtimer import LoopingTimer
from .platform import BirbnetesIoTPlatformStatusDriver, BirbnetesIoTPlatformRecordDriver, \
BirbnetesIoTPlatformPlaybackDriver

View File

@ -34,3 +34,5 @@ REPORT_URL = os.environ.get("REPORT_URL", None)
REPORT_INTERVAL = float(os.environ.get("REPORT_INTERVAL", 15)) REPORT_INTERVAL = float(os.environ.get("REPORT_INTERVAL", 15))
DISABLE_AI = os.environ.get("DISABLE_AI").lower() in ['yes', '1', 'true'] DISABLE_AI = os.environ.get("DISABLE_AI").lower() in ['yes', '1', 'true']
PLATFORM = os.environ.get("PLATFORM", "raspberry")

18
src/utils/platform.py Normal file
View File

@ -0,0 +1,18 @@
import config
if config.PLATFORM == 'raspberry':
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver, BirbnetesIoTPlatformRecordDriver, \
BirbnetesIoTPlatformPlaybackDriver
elif config.PLATFORM == 'emulator':
from birbnetes_iot_platform_emulator import BirbnetesIoTPlatformStatusDriver, BirbnetesIoTPlatformRecordDriver, \
BirbnetesIoTPlatformPlaybackDriver
else:
raise ModuleNotFoundError(f"Could not load platform driver for {config.PLATFORM}")
__all__ = [
'BirbnetesIoTPlatformStatusDriver',
'BirbnetesIoTPlatformRecordDriver',
'BirbnetesIoTPlatformPlaybackDriver'
]