Skip to content

Commit

Permalink
improve House0Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamillar committed Nov 2, 2024
1 parent 5a5697a commit 824cec8
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/gwproto/data_classes/house_0_layout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
from pathlib import Path
from typing import Any, List, Optional

from gw.errors import DcError
Expand All @@ -6,9 +8,15 @@
from gwproto.data_classes.data_channel import DataChannel
from gwproto.data_classes.hardware_layout import (
HardwareLayout,
LoadArgs,
LoadError,
)
from gwproto.data_classes.house_0_names import H0N
from gwproto.data_classes.sh_node import ShNode
from gwproto.default_decoders import (
CacDecoder,
ComponentDecoder,
)
from gwproto.named_types import ComponentAttributeClassGt


Expand Down Expand Up @@ -64,6 +72,84 @@ def __init__(
raise ValueError("Must have between 1 and 6 store zones")
self.short_names = H0N(self.total_store_tanks, self.zone_list)

# overwrites base class to return correct object
@classmethod
def load( # noqa: PLR0913
cls,
layout_path: Path | str,
*,
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,
) -> "House0Layout":
with Path(layout_path).open() as f:
layout = json.loads(f.read())
return cls.load_dict(
layout,
included_node_names=included_node_names,
raise_errors=raise_errors,
errors=errors,
cac_decoder=cac_decoder,
component_decoder=component_decoder,
)

# overwrites base class to return correct object
@classmethod
def load_dict( # noqa: PLR0913
cls,
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,
) -> "House0Layout":
if errors is None:
errors = []
cacs = cls.load_cacs(
layout=layout,
raise_errors=raise_errors,
errors=errors,
cac_decoder=cac_decoder,
)
components = cls.load_components(
layout=layout,
cacs=cacs,
raise_errors=raise_errors,
errors=errors,
component_decoder=component_decoder,
)
nodes = cls.load_nodes(
layout=layout,
components=components,
raise_errors=raise_errors,
errors=errors,
included_node_names=included_node_names,
)
data_channels = cls.load_data_channels(
layout=layout,
nodes=nodes,
raise_errors=raise_errors,
errors=errors,
)
load_args: LoadArgs = {
"cacs": cacs,
"components": components,
"nodes": nodes,
"data_channels": data_channels,
}
cls.resolve_links(
load_args["nodes"],
load_args["components"],
raise_errors=raise_errors,
errors=errors,
)
cls.validate_layout(load_args, raise_errors=raise_errors, errors=errors)
return House0Layout(layout, **load_args)

@property
def chg_dschg_relay(self) -> ShNode:
return next(
Expand Down

0 comments on commit 824cec8

Please sign in to comment.