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

Updates to support new driver topic devices/<device>/multi #16

Merged
merged 6 commits into from
Oct 2, 2024
Merged
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
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "volttron-lib-base-historian"
version = "0.2.0-rc"
version = "2.0.0rc0"
description = "A base library with extension points for using with the VOLTTRON platform."
authors = ["VOLTTRON Team <[email protected]>"]
license = "Apache License 2.0"
Expand All @@ -12,8 +12,8 @@ packages = [ { include = "historian", from = "src" }, { include = "historian", f

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
volttron = ">=10.0.3a9,<11.0"

#volttron-core = { path="../volttron-core", develop = true}
volttron-core =">=2.0.0rc"
ply = "^3.11"

[tool.poetry.group.dev.dependencies]
Expand All @@ -30,7 +30,7 @@ coverage = "^6.3.2"
pytest-cov = "^3.0.0"
Sphinx = "^6.0.0"
sphinx-rtd-theme = "^1.2.0"
volttron-testing = "^0.4.0rc3"
#volttron-testing = "^0.4.0rc3"

[tool.yapfignore]
ignore_patterns = [
Expand Down
15 changes: 10 additions & 5 deletions src/historian/base/base_historian.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ def loads(data_string):
time_parser = None

ACTUATOR_TOPIC_PREFIX_PARTS = len(topics.ACTUATOR_VALUE.split('/'))
ALL_REX = re.compile('.*/all$')

# Register a better datetime parser in sqlite3.
fix_sqlite3_datetime()
Expand Down Expand Up @@ -353,6 +352,7 @@ def __init__(self,
time_tolerance=None,
time_tolerance_topics=None,
cache_only_enabled=False,
devices_topic_suffix="multi",
**kwargs):

super(BaseHistorianAgent, self).__init__(**kwargs)
Expand Down Expand Up @@ -417,6 +417,9 @@ def __init__(self,
else:
raise ValueError(f"cache_only_enabled should be either True or False")

self._devices_topic_suffix = devices_topic_suffix

self._all_multi_regex = re.compile(f'.*/{self._devices_topic_suffix}$')
self._default_config = {
"retry_period":self._retry_period,
"submit_size_limit": self._submit_size_limit,
Expand All @@ -438,7 +441,8 @@ def __init__(self,
"all_platforms": self._all_platforms,
"time_tolerance": self._time_tolerance,
"time_tolerance_topics": self._time_tolerance_topics,
"cache_only_enabled": self._cache_only_enabled
"cache_only_enabled": self._cache_only_enabled,
"devices_topic_suffix": self._devices_topic_suffix
}

self.vip.config.set_default("config", self._default_config)
Expand Down Expand Up @@ -586,7 +590,8 @@ def _configure(self, config_name, action, contents):
self._message_publish_count = message_publish_count
self._time_tolerance = time_tolerance
self._time_tolerance_topics = time_tolerance_topics

self._devices_topic_suffix = config.get("devices_topic_suffix", "multi")
self._all_multi_regex = re.compile(f'.*/{self._devices_topic_suffix}$')
custom_topics_list = []
for handler, topic_list in config.get("custom_topics", {}).items():
if handler == "capture_device_data":
Expand Down Expand Up @@ -851,10 +856,10 @@ def _capture_device_data(self, peer, sender, bus, topic, headers,
message):
"""Capture device data and submit it to be published by a historian.

Filter out only the */all topics for publishing to the historian.
Filter out only the */all or */multi topics for publishing to the historian.
"""

if not ALL_REX.match(topic):
if not self._all_multi_regex.match(topic):
return

# Anon the topic if necessary.
Expand Down
3 changes: 0 additions & 3 deletions tests/test_base_historian.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
# ===----------------------------------------------------------------------===
# }}}

from datetime import datetime
from time import sleep

from volttron.utils import format_timestamp

from historian.base import BaseHistorianAgent


Expand Down Expand Up @@ -56,7 +53,7 @@
# header_mod.DATE: now,
# header_mod.TIMESTAMP: now
# }
agent = ConcreteHistorianAgent(cache_only_enabled=True)

Check failure on line 56 in tests/test_base_historian.py

View workflow job for this annotation

GitHub Actions / run-tests (ubuntu-22.04, 3.10)

test_cache_enable ModuleNotFoundError: No module named 'volttron.messagebus'

Check failure on line 56 in tests/test_base_historian.py

View workflow job for this annotation

GitHub Actions / run-tests (ubuntu-22.04, 3.11)

test_cache_enable ModuleNotFoundError: No module named 'volttron.messagebus'
assert agent is not None
device = "devices/testcampus/testbuilding/testdevice"
agent._capture_data(peer="foo",
Expand Down
2 changes: 0 additions & 2 deletions tests/test_base_historian_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import pytest
from pytz import UTC

from volttrontesting.server_mock import TestServer
from volttron.client import Agent

from historian.base import BaseHistorianAgent

Expand Down
Loading