Skip to content

Commit

Permalink
Merge pull request #16 from davidraker/driver_service_work
Browse files Browse the repository at this point in the history
Updates for modular RC.
  • Loading branch information
craig8 authored Oct 3, 2024
2 parents 366c7ae + e430fe4 commit 4f9a12c
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 475 deletions.
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# volttron-lib-base-driver

[![Eclipse VOLTTRON™](https://img.shields.io/badge/Eclips%20VOLTTRON--red.svg)](https://volttron.readthedocs.io/en/latest/)
![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)
![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)
![Passing?](https://github.com/eclipse-volttron/volttron-lib-base-driver/actions/workflows/run-tests.yml/badge.svg)
[![pypi version](https://img.shields.io/pypi/v/volttron-lib-base-driver.svg)](https://pypi.org/project/volttron-lib-base-driver/)


# Requires
## Requirements

* python >= 3.10
* volttron >= 10.0

* volttron-core >= 2.0.0rc0

# Documentation
More detailed documentation can be found on [ReadTheDocs](https://volttron.readthedocs.io/en/modular/). The RST source
More detailed information about the VOLTTRON Driver Framework can be found [ReadTheDocs](https://eclipse-volttron.readthedocs.io/en/latest/external-docs/volttron-platform-driver/index.html#platform-driver-framework). The RST source
of the documentation for this component is located in the "docs" directory of this repository.

## Installation
Expand All @@ -25,13 +24,7 @@ Information on how to install of the VOLTTRON platform can be found
Install the library. You have two options. You can install this library using the version on PyPi:

```shell
pip install volttron-lib-base-driver
```

Or you can install the local version of this library from this repo:

```shell
pip install -e .
poetry add --directory $VOLTTRON_HOME volttron-lib-base-driver
```

## Development
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ignore_missing_imports = true

[tool.poetry]
name = "volttron-lib-base-driver"
version = "0.2.1rc0"
version = "2.0.0rc0"
description = "Volttron Driver libraries used to support development within the Volttron Driver Framework."
authors = ["Mark Bonicillo <[email protected]>"]
license = "Apache License 2.0"
Expand All @@ -52,8 +52,7 @@ classifiers = [

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

volttron-core = ">=2.0.0rc0"

[tool.poetry.group.dev.dependencies]
pytest = "^6.2.5"
Expand Down
80 changes: 80 additions & 0 deletions src/volttron/driver/base/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from datetime import timedelta
from enum import Enum
from pydantic import BaseModel, computed_field, ConfigDict, Field, field_validator

# TODO: Wire up the data_source field to poll scheduling (everything is currently short-poll because this isn't used).
# TODO: Should NEVER actually be an option? Could it just be None?
class DataSource(Enum):
SHORT_POLL = "short_poll"
LONG_POLL = "long_poll"
NEVER = "never"
POLL_ONCE = "poll_once"
STATIC = "static"


class EquipmentConfig(BaseModel):
model_config = ConfigDict(validate_assignment=True, populate_by_name=True)
active: bool | None = None
group: str | None = None
# TODO: If this needs to be an int, we may need to use milliseconds someplace.
polling_interval: int | None = Field(default=None, alias='interval')
publish_single_depth: bool | None = Field(default=None, alias='publish_depth_first_single')
publish_single_breadth: bool | None = Field(default=None, alias='publish_breadth_first_single')
publish_multi_depth: bool | None = Field(default=None, alias='publish_depth_first_multi')
publish_multi_breadth: bool | None = Field(default=None, alias='publish_breadth_first_multi')
publish_all_depth: bool | None = Field(default=None, alias='publish_depth_first_all')
publish_all_breadth: bool | None = Field(default=None, alias='publish_breadth_first_all')
reservation_required_for_write: bool = False

@field_validator('polling_interval', mode='before')
@classmethod
def _normalize_polling_interval(cls, v):
# TODO: This does not match int above, but we may need to convert to ms in calculations.
return None if v == '' or v is None else float(v)

class PointConfig(EquipmentConfig):
data_source: DataSource = Field(default='short_poll', alias='Data Source')
notes: str = Field(default='', alias='Notes')
reference_point_name: str = Field(default='', alias='Reference Point Name')
stale_timeout_configured: float | None = Field(default=None, alias='stale_timeout')
stale_timeout_multiplier: float = Field(default=3)
units: str = Field(default='', alias='Units')
units_details: str = Field(default='', alias='Unit Details')
volttron_point_name: str = Field(alias='Volttron Point Name')
writable: bool = Field(default=False, alias='Writable')

@field_validator('data_source', mode='before')
@classmethod
def _normalize_data_source(cls, v):
# TODO: This never converts to DataSource.
# TODO: Data Source enum needs something to tell Data Point how to serialize it, otherwise enable/disable will fail.
return v.lower()

@computed_field
@property
def stale_timeout(self) -> timedelta | None:
if self.stale_timeout_configured is None and self.polling_interval is None:
return None
else:
return timedelta(seconds=(self.stale_timeout_configured
if self.stale_timeout_configured is not None
else self.polling_interval * self.stale_timeout_multiplier))

@stale_timeout.setter
def stale_timeout(self, value):
self.stale_timeout_configured = value


class DeviceConfig(EquipmentConfig):
all_publish_interval: float = 0.0
allow_duplicate_remotes: bool = False
equipment_specific_fields: dict = {}
registry_config: list[PointConfig] = []


class RemoteConfig(BaseModel):
model_config = ConfigDict(extra='allow', validate_assignment=True)
debug: bool = False
driver_type: str
heart_beat_point: str | None = None
module: str | None = None
Loading

0 comments on commit 4f9a12c

Please sign in to comment.