Skip to content

Commit

Permalink
Merge pull request #223 from thegridelectric/dev
Browse files Browse the repository at this point in the history
Add PollPeriodS to PipeFlowSensorComponentGt; Code generation cleanups; dependabot merges.
  • Loading branch information
anschweitzer committed Nov 8, 2023
2 parents fc1aefc + b62bf15 commit c30993b
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 1,216 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pip==23.2.1
nox==2022.11.21
pip==23.3.1
nox==2023.4.22
nox-poetry==1.0.3
poetry==1.2.2
virtualenv==20.21.0
poetry==1.7.0
virtualenv==20.24.2
4 changes: 2 additions & 2 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run Labeler
uses: crazy-max/ghaction-github-labeler@v4.1.0
uses: crazy-max/ghaction-github-labeler@v5.0.0
with:
skip-delete: true
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

Expand Down Expand Up @@ -57,21 +57,21 @@ jobs:
- name: Publish package on PyPI
if: steps.check-version.outputs.tag
uses: pypa/[email protected].8
uses: pypa/[email protected].10
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}

- name: Publish package on TestPyPI
if: "! steps.check-version.outputs.tag"
uses: pypa/[email protected].8
uses: pypa/[email protected].10
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/

- name: Publish the release notes
uses: release-drafter/release-drafter@v5.24.0
uses: release-drafter/release-drafter@v5.25.0
with:
publish: ${{ steps.check-version.outputs.tag != '' }}
tag: ${{ steps.check-version.outputs.tag }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Check out the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
needs: tests
steps:
- name: Check out the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ cook.sh

# Code generation airtable
CodeGenerationTools/GridworksCore/SassyMQ/
CodeGenerationTools/GridworksCore/SMQL
CodeGenerationTools/GridworksCore/.ssotme/**/*.zfs
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
language: system
types: [text]
stages: [commit, push, manual]
exclude: "src/gwproto/gt/|src/gwproto/gs/|src/gwproto/enums/"
exclude: "src/gwproto/gt/|src/gwproto/gs/|src/gwproto/enums/|CodeGenerationTools/GridworksCore/ODXML/DataSchema.odxml"
# - id: flake8
# name: flake8
# entry: flake8
Expand Down
1,124 changes: 1 addition & 1,123 deletions CodeGenerationTools/GridworksCore/ODXML/DataSchema.odxml

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions CodeGenerationTools/GridworksCore/aicapture.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,7 @@
"ProjectTranspilerId": "53b850fc-d424-44fc-8797-769a7657bbf7",
"Name": "SSoT",
"RelativePath": "",
"CommandLine": "effortless/ssot"
},
{
"MatchedTranspiler": {
"TranspilerId": "19d8142a-2f4d-46ac-9de6-77441f233192",
"Name": "AirtableToXml",
"Description": "Extracts the contents of an airtable base as a single Xml file."
},
"ProjectTranspilerId": "4c3ac21a-bd4e-413c-8f71-0bdb35562ed2",
"Name": "AirtableToXml",
"RelativePath": "/SSoT",
"CommandLine": "airtable/airtable-to-xml -p baseId=appgibWM6WZW20bBx -i Entities.json -w 120000"
"CommandLine": "effortless/ssot -p ssot-key=IuUqkLn41mZ8TS"
},
{
"MatchedTranspiler": {
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
furo==2023.7.26
furo==2023.9.10
sphinx==7.1.2
sphinx-click==4.1.0
sphinx-click==5.0.1
myst_parser==2.0.0
sphinx-rtd-theme
84 changes: 61 additions & 23 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gridworks-protocol"
version = "0.6.0"
version = "0.6.1"
description = "Gridworks Protocol"
authors = ["Jessica Millar <[email protected]>"]
license = "MIT"
Expand Down
102 changes: 60 additions & 42 deletions src/gwproto/data_classes/hardware_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@
snake_add_underscore_to_camel_pattern = re.compile(r"(?<!^)(?=[A-Z])")


def camel_to_snake(name):
def camel_to_snake(name: str) -> str:
return snake_add_underscore_to_camel_pattern.sub("_", name).lower()


@dataclass
class LoadError:
type_name: str
src_dict: dict
src_dict: dict[Any, Any]
exception: Exception


def load_cacs(
layout: dict,
layout: dict[str, Any],
raise_errors: bool = True,
errors: Optional[list[LoadError]] = None,
cac_decoder: Optional[CacDecoder] = None,
) -> dict:
) -> dict[str, Any]:
if errors is None:
errors: list[LoadError] = []
errors = []
cacs = dict()
for type_name, maker_class in [
("RelayCacs", RelayCacGt_Maker),
Expand All @@ -82,7 +82,11 @@ def load_cacs(
]:
for d in layout.get(type_name, []):
try:
cacs[d["ComponentAttributeClassId"]] = maker_class.dict_to_dc(d)
cacs[
d["ComponentAttributeClassId"]
] = maker_class.dict_to_dc( # type:ignore[attr-defined]
d
)
except Exception as e:
if raise_errors:
raise e
Expand All @@ -107,13 +111,13 @@ def load_cacs(


def load_components(
layout: dict,
layout: dict[Any, Any],
raise_errors: bool = True,
errors: Optional[list[LoadError]] = None,
component_decoder: Optional[ComponentDecoder] = None,
) -> dict:
) -> dict[Any, Any]:
if errors is None:
errors: list[LoadError] = []
errors = []
components = dict()
for type_name, maker_class in [
("RelayComponents", RelayComponentGt_Maker),
Expand All @@ -125,7 +129,11 @@ def load_components(
]:
for d in layout.get(type_name, []):
try:
components[d["ComponentId"]] = maker_class.dict_to_dc(d)
components[
d["ComponentId"]
] = maker_class.dict_to_dc( # type:ignore[attr-defined]
d
)
except Exception as e:
if raise_errors:
raise e
Expand All @@ -148,12 +156,14 @@ def load_components(


def load_nodes(
layout: dict,
layout: dict[Any, Any],
raise_errors: bool = True,
errors: Optional[list[LoadError]] = None,
included_node_names: Optional[set[str]] = None,
) -> dict:
) -> dict[Any, Any]:
nodes = {}
if errors is None:
errors = []
for d in layout.get("ShNodes", []):
try:
node_name = d["Alias"]
Expand All @@ -167,11 +177,13 @@ def load_nodes(


def resolve_links(
nodes: dict[str, ShNode] = None,
components: dict[str, Component] = None,
nodes: dict[str, ShNode],
components: dict[str, Component],
raise_errors: bool = True,
errors: Optional[list[LoadError]] = None,
) -> None:
if errors is None:
errors = []
for node_name, node in nodes.items():
d = dict(node=dict(name=node_name, node=node))
try:
Expand All @@ -194,14 +206,14 @@ def resolve_links(


class HardwareLayout:
layout: dict
layout: dict[Any, Any]
cacs: dict[str, ComponentAttributeClass]
components: dict[str, Component]
nodes: dict[str, ShNode]

def __init__(
self,
layout: dict,
layout: dict[Any, Any],
cacs: Optional[dict[str, ComponentAttributeClass]] = None,
components: Optional[dict[str, Component]] = None,
nodes: Optional[dict[str, ShNode]] = None,
Expand All @@ -217,7 +229,7 @@ def __init__(
nodes = ShNode.by_id
self.nodes = dict(nodes)

def clear_property_cache(self):
def clear_property_cache(self) -> None:
for cached_prop_name in [
prop_name
for prop_name in type(self).__dict__
Expand All @@ -236,7 +248,7 @@ def load(
component_decoder: Optional[ComponentDecoder] = None,
) -> "HardwareLayout":
with Path(layout_path).open() as f:
layout: dict = json.loads(f.read())
layout = json.loads(f.read())
return cls.load_dict(
layout,
included_node_names=included_node_names,
Expand All @@ -249,15 +261,15 @@ def load(
@classmethod
def load_dict(
cls,
layout: dict,
layout: dict[Any, Any],
included_node_names: Optional[set[str]] = None,
raise_errors: bool = True,
errors: Optional[list[LoadError]] = None,
cac_decoder: Optional[CacDecoder] = None,
component_decoder: Optional[ComponentDecoder] = None,
) -> "HardwareLayout":
if errors is None:
errors: list[LoadError] = []
errors = []
load_args = dict(
cacs=load_cacs(
layout=layout,
Expand Down Expand Up @@ -296,16 +308,24 @@ def cac(self, alias: str) -> Optional[ComponentAttributeClass]:
return self.cac_from_component(self.component(alias))

def component_from_node(self, node: Optional[ShNode]) -> Optional[Component]:
return self.components.get(
node.component_id if node is not None else None, None
return (
self.components.get(
node.component_id if node.component_id is not None else "", None
)
if node is not None
else None
)

def cac_from_component(
self, component: Optional[Component]
) -> Optional[ComponentAttributeClass]:
return self.cacs.get(
component.component_attribute_class_id if component is not None else None,
None,
return (
self.cacs.get(
component.component_attribute_class_id if component is not None else "",
None,
)
if component is not None
else None
)

@classmethod
Expand All @@ -331,36 +351,36 @@ def descendants(self, alias: str) -> List[ShNode]:
return list(filter(lambda x: x.alias.startswith(alias), self.nodes.values()))

@cached_property
def atn_g_node_alias(self):
return self.layout["MyAtomicTNodeGNode"]["Alias"]
def atn_g_node_alias(self) -> str:
return self.layout["MyAtomicTNodeGNode"]["Alias"] # type: ignore[no-any-return]

@cached_property
def atn_g_node_instance_id(self):
return self.layout["MyAtomicTNodeGNode"]["GNodeId"]
def atn_g_node_instance_id(self) -> str:
return self.layout["MyAtomicTNodeGNode"]["GNodeId"] # type: ignore[no-any-return]

@cached_property
def atn_g_node_id(self):
return self.layout["MyAtomicTNodeGNode"]["GNodeId"]
def atn_g_node_id(self) -> str:
return self.layout["MyAtomicTNodeGNode"]["GNodeId"] # type: ignore[no-any-return]

@cached_property
def terminal_asset_g_node_alias(self):
def terminal_asset_g_node_alias(self) -> str:
my_atn_as_dict = self.layout["MyTerminalAssetGNode"]
return my_atn_as_dict["Alias"]
return my_atn_as_dict["Alias"] # type: ignore[no-any-return]

@cached_property
def terminal_asset_g_node_id(self):
def terminal_asset_g_node_id(self) -> str:
my_atn_as_dict = self.layout["MyTerminalAssetGNode"]
return my_atn_as_dict["GNodeId"]
return my_atn_as_dict["GNodeId"] # type: ignore[no-any-return]

@cached_property
def scada_g_node_alias(self):
def scada_g_node_alias(self) -> str:
my_scada_as_dict = self.layout["MyScadaGNode"]
return my_scada_as_dict["Alias"]
return my_scada_as_dict["Alias"] # type: ignore[no-any-return]

@cached_property
def scada_g_node_id(self):
def scada_g_node_id(self) -> str:
my_scada_as_dict = self.layout["MyScadaGNode"]
return my_scada_as_dict["GNodeId"]
return my_scada_as_dict["GNodeId"] # type: ignore[no-any-return]

@cached_property
def all_telemetry_tuples_for_agg_power_metering(self) -> List[TelemetryTuple]:
Expand Down Expand Up @@ -420,9 +440,7 @@ def power_meter_cac(self) -> ElectricMeterCac:
f"ERROR. power_meter_component cac {self.power_meter_component.component_attribute_class}"
f" / {type(self.power_meter_component.component_attribute_class)} is not an ElectricMeterCac"
)
return typing.cast(
ElectricMeterCac, self.power_meter_node.component.component_attribute_class
)
return self.power_meter_node.component.component_attribute_class # type: ignore[union-attr, return-value]

@cached_property
def all_resistive_heaters(self) -> List[ShNode]:
Expand Down
4 changes: 4 additions & 0 deletions src/gwproto/types/pipe_flow_sensor_component_gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class PipeFlowSensorComponentGt(BaseModel):
title="HwUid",
default=None,
)
PollPeriodS: Optional[float] = Field(
title="HwUid",
default=5.0,
)
TypeName: Literal["pipe.flow.sensor.component.gt"] = "pipe.flow.sensor.component.gt"
Version: str = "000"

Expand Down

0 comments on commit c30993b

Please sign in to comment.