Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make modbus available to plugins #211

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/deye_plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
from deye_config import DeyeConfig
from deye_mqtt import DeyeMqttClient
from deye_events import DeyeEventProcessor
from deye_modbus import DeyeModbus


class DeyePluginContext:
def __init__(self, config: DeyeConfig, mqtt_client: DeyeMqttClient):
def __init__(self, config: DeyeConfig, mqtt_client: DeyeMqttClient, modbus: DeyeModbus):
self.config = config
self.mqtt_client = mqtt_client
self.modbus = modbus


class DeyePluginLoader:
Expand Down
6 changes: 3 additions & 3 deletions src/deye_processor_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
from deye_sensor import Sensor
from deye_plugin_loader import DeyePluginContext, DeyePluginLoader
from deye_multi_inverter_data_aggregator import DeyeMultiInverterDataAggregator

from deye_modbus import DeyeModbus
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@belowm Remove this extra import, otherwise the PR check will not pass and will block the merge of the PR


class DeyeProcessorFactory:
def __init__(self, config: DeyeConfig, mqtt_client: DeyeMqttClient):
self.__log = logging.getLogger(DeyeProcessorFactory.__name__)
self.__config = config
self.__mqtt_client = mqtt_client
self.__first_run = True
plugin_context = DeyePluginContext(config, mqtt_client)
self.plugin_loader = DeyePluginLoader(config)
self.plugin_loader.load_plugins(plugin_context)

def create_processors(
self, logger_config: DeyeLoggerConfig, modbus: DeyeModbus, sensors: list[Sensor]
) -> list[DeyeEventProcessor]:
plugin_context = DeyePluginContext(self.__config, self.__mqtt_client, modbus)
self.plugin_loader.load_plugins(plugin_context)
processors = (
self.__create_builtin_processors(logger_config, modbus, sensors) + self.plugin_loader.get_event_processors()
)
Expand Down