Skip to content
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
12 changes: 10 additions & 2 deletions PIconnect/AF.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ def default_server(cls) -> dotnet.AF.PISystem | None:
return None

def __init__(self, server: str | None = None, database: str | None = None) -> None:
#: The PI AF server connection.
self.server = self._initialise_server(server)
#: The PI AF database connection.
self.database = self._initialise_database(database)
self.search = Search.Search(self.database)
#: Search reference for searching objects in the database.
#: See :class:`.Search.Search` for more information.
self.search: Search.Search = Search.Search(self.database)

def _initialise_server(self, server: str | None) -> dotnet.AF.PISystem:
"""Initialise the server connection."""
Expand Down Expand Up @@ -151,7 +155,11 @@ def event_frames(


class PIAFDatabase(AFDatabase):
"""Context manager for connections to the PI Asset Framework database."""
"""Context manager for connections to the PI Asset Framework database.

.. deprecated:: 1.0.0
Use :class:`AFDatabase` instead.
"""

version = "0.3.0"

Expand Down
55 changes: 4 additions & 51 deletions PIconnect/Asset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Mirror of the OSISoft.AF.Asset namespace."""

import dataclasses
from typing import Generic, Self, TypeVar, overload
from typing import Generic, Self, TypeVar

import pandas as pd # type: ignore

Expand All @@ -10,11 +10,12 @@

__all__ = [
"AFDataReference",
"AFElement",
"AFElementList",
"AFAttribute",
"AFAttributeList",
]

T = TypeVar("T")
ElementType = TypeVar("ElementType", bound=dotnet.AF.Asset.AFBaseElement)


Expand All @@ -41,54 +42,6 @@ def pi_point(self) -> PI.PIPoint | None:
return PI.PIPoint(self.data_reference.PIPoint)


class AFEnumerationValue:
"""Representation of an AF enumeration value."""

def __init__(self, value: dotnet.AF.Asset.AFEnumerationValue) -> None:
self._value = value

def __str__(self) -> str:
"""Return the string representation of the enumeration value."""
return self._value.Name

def __int__(self) -> int:
"""Return the integer representation of the enumeration value."""
return self._value.Value

def __repr__(self):
"""Return the string representation of the enumeration value."""
return f"{self.__class__.__qualname__}({self._value.Name})"

@property
def name(self) -> str:
"""Return the name of the enumeration value."""
return self._value.Name

@property
def value(self) -> int:
"""Return the integer value of the enumeration value."""
return self._value.Value

@overload
@staticmethod
def wrap_enumeration_value(
value: dotnet.AF.Asset.AFEnumerationValue,
) -> "AFEnumerationValue": ...
@overload
@staticmethod
def wrap_enumeration_value(
value: T,
) -> T: ...
@staticmethod
def wrap_enumeration_value(
value: T | dotnet.AF.Asset.AFEnumerationValue,
) -> "T | AFEnumerationValue":
"""Wrap the value in an AFEnumerationValue if it is an enumeration value."""
if isinstance(value, dotnet.lib.AF.Asset.AFEnumerationValue):
return AFEnumerationValue(value)
return value


class AFAttribute(Data.DataContainer):
"""Representation of an AF attribute."""

Expand Down Expand Up @@ -158,7 +111,7 @@ def _normalize_filter_expression(self, filter_expression: str) -> str:

def _current_value(self) -> object:
"""Return the current value of the attribute."""
return AFEnumerationValue.wrap_enumeration_value(self.attribute.GetValue().Value)
return self.attribute.GetValue().Value

def _filtered_summaries(
self,
Expand Down
Loading
Loading