Skip to content

Commit

Permalink
smartmeter: add DLMS asyncio, fix webif (note: DLMS asyncio needs tes…
Browse files Browse the repository at this point in the history
…ting!)
  • Loading branch information
Morg42 committed Dec 16, 2024
1 parent 9b90c04 commit b900aac
Show file tree
Hide file tree
Showing 4 changed files with 612 additions and 414 deletions.
21 changes: 8 additions & 13 deletions smartmeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def query(self, assign_values: bool = True, protocol=None) -> dict:
if not protocol:
protocol = self.protocol
ref = self._get_module(protocol)
if not ref:
self.logger.error(f'could not get module for protocol {protocol}, aborting.')
return {}

result = {}
try:
Expand Down Expand Up @@ -294,11 +297,8 @@ def _load_parameters(self):
self._config['poll'] = True
poll = self.get_parameter_value('poll')
if not poll:
if self.protocol == 'SML':
self.use_asyncio = True
self._config['poll'] = False
else:
self.logger.warning(f'async listening requested but protocol is {self.protocol} instead of SML, reverting to polling')
self.use_asyncio = True
self._config['poll'] = False

if self.use_asyncio:
self.timefilter = self.get_parameter_value('time_filter')
Expand Down Expand Up @@ -364,14 +364,9 @@ def _is_obis_code_wanted(self, code: str) -> bool:

def poll_device(self):
"""
This function aquires a lock, calls the 'query device' method of the
respective module and upon successful data readout it calls the update function
If it is not possible it passes on, issuing a warning about increasing the query interval
This function just calls the 'query device' method of the
respective module
"""
self.logger.debug(f'poll_device called, module is {self._get_module()}')
if not self._get_module():
return

self.query()

def _update_values(self, result: dict):
Expand Down Expand Up @@ -435,7 +430,7 @@ async def plugin_coro(self):
"""
self.logger.info("plugin_coro started")
try:
self.reader = sml.SmlAsyncReader(self.logger, self, self._config)
self.reader = self._get_module().AsyncReader(self.logger, self, self._config)
except ImportError as e:
# serial_asyncio not loaded/present
self.logger.error(e)
Expand Down
Loading

0 comments on commit b900aac

Please sign in to comment.