Skip to content

Commit

Permalink
Merge pull request #408 from thegridelectric/dev
Browse files Browse the repository at this point in the history
v1.2.1: RelayActorConfig includes Energized/DeEnergized states as well as events
  • Loading branch information
jessicamillar authored Jan 1, 2025
2 parents 2425f7d + 0a33140 commit 14a8618
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
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 = "1.2.0"
version = "1.2.1"
description = "Gridworks Protocol"
authors = ["Jessica Millar <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/gwproto/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"RelayWiringConfig", # [relay.wiring.config.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#relaywiringconfig)
"StoreFlowRelay", # [store.flow.relay.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#storeflowrelay)
"Strategy", # [spaceheat.strategy.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#spaceheatstrategy)
"TelemetryName", # [spaceheat.telemetry.name.003](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#spaceheattelemetryname)
"TelemetryName", # [spaceheat.telemetry.name.004](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#spaceheattelemetryname)
"TempCalcMethod", # [temp.calc.method.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#tempcalcmethod)
"ThermistorDataMethod", # [thermistor.data.method.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#thermistordatamethod)
"Unit", # [spaceheat.unit.001](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#spaceheatunit)
Expand Down
3 changes: 2 additions & 1 deletion src/gwproto/enums/telemetry_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TelemetryName(GwStrEnum):
- MicroVolts: Microvolts RMS
- VoltsTimesTen
- WattHours
- StorageLayer
For more information:
- [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/)
Expand Down Expand Up @@ -73,4 +74,4 @@ def enum_name(cls) -> str:

@classmethod
def enum_version(cls) -> str:
return "003"
return "004"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class I2cMultichannelDtRelayComponentGt(ComponentGt):
TypeName: Literal["i2c.multichannel.dt.relay.component.gt"] = (
"i2c.multichannel.dt.relay.component.gt"
)
Version: Literal["001"] = "001"
Version: Literal["002"] = "002"

model_config = ConfigDict(extra="allow", use_enum_values=True)

Expand Down
49 changes: 46 additions & 3 deletions src/gwproto/named_types/relay_actor_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Type relay.actor.config, version 001"""
"""Type relay.actor.config, version 002"""

from typing import Literal

from pydantic import PositiveInt
from pydantic import PositiveInt, model_validator
from typing_extensions import Self

from gwproto.enums import RelayWiringConfig
from gwproto.named_types import ChannelConfig
Expand All @@ -12,11 +13,53 @@


class RelayActorConfig(ChannelConfig):
"""
Relay Actor Config.
Used to associate individual relays on a multi-channel relay board to specific SpaceheatNode
actors. Each actor managed by the Spaceheat SCADA has an associated SpaceheatNode. That
Node will be associated to a relay board component with multiple relays. Th relay board
will have a list of relay actor configs so that the actor can identify which relay it has
purview over. Has DeEnergizedState and EnergizedState
[More info](https://gridworks-protocol.readthedocs.io/en/latest/spaceheat-actor.html)
"""

RelayIdx: PositiveInt
ActorName: SpaceheatName
WiringConfig: RelayWiringConfig
EventType: str
DeEnergizingEvent: str
EnergizingEvent: str
StateType: str
DeEnergizedState: str
EnergizedState: str
TypeName: Literal["relay.actor.config"] = "relay.actor.config"
Version: Literal["001"] = "001"
Version: Literal["002"] = "002"

@model_validator(mode="after")
def check_axiom_1(self) -> Self:
"""
Axiom 1: EventType, DeEnergizingEvent/EnergizingEvent consistency.
If the event type is the name of a known enum, then the DeEnergizingEvent, EnergizingEvent pair are the values of that enum.
"""
# Implement check for axiom 1"
return self

@model_validator(mode="after")
def check_axiom_2(self) -> Self:
"""
Axiom 2: StateType, EnergizedState/DeEnergizedState consistency.
If the state type is the name of a known enum, then the DeEnergizedState, EnergizedState pair are the values of that enum.
"""
# Implement check for axiom 2"
return self

@model_validator(mode="after")
def check_axiom_3(self) -> Self:
"""
Axiom 3: Events and States match. .
E.g. if RelayOpen is the EnergizedState then the EnergizingEvent is OpenRelay.
"""
# Implement check for axiom 3"
return self
4 changes: 2 additions & 2 deletions tests/enums/telemetry_name_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Tests for enum spaceheat.telemetry.name.003 from the GridWorks Type Registry.
Tests for enum spaceheat.telemetry.name.004 from the GridWorks Type Registry.
"""

from gwproto.enums import TelemetryName
Expand Down Expand Up @@ -29,4 +29,4 @@ def test_telemetry_name() -> None:

assert TelemetryName.default() == TelemetryName.Unknown
assert TelemetryName.enum_name() == "spaceheat.telemetry.name"
assert TelemetryName.enum_version() == "003"
assert TelemetryName.enum_version() == "004"
17 changes: 13 additions & 4 deletions tests/named_types/test_i2c_multichannel_dt_relay_component_gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ def test_i2c_multichannel_dt_relay_component_gt_generated() -> None:
"ChannelName": "vdc-relay1",
"DeEnergizingEvent": "CloseRelay",
"EnergizingEvent": "OpenRelay",
"DeEnergizedState": "RelayClosed",
"EnergizedState": "RelayOpen",
"EventType": "change.relay.state",
"StateType": "relay.closed.or.open",
"Exponent": 0,
"PollPeriodMs": 200,
"RelayIdx": 1,
"TypeName": "relay.actor.config",
"Unit": "Unitless",
"Version": "001",
"Version": "002",
"WiringConfig": "NormallyClosed",
},
{
Expand All @@ -33,13 +36,16 @@ def test_i2c_multichannel_dt_relay_component_gt_generated() -> None:
"ChannelName": "tstat-common-relay2",
"DeEnergizingEvent": "CloseRelay",
"EnergizingEvent": "OpenRelay",
"DeEnergizedState": "RelayClosed",
"EnergizedState": "RelayOpen",
"EventType": "change.relay.state",
"StateType": "relay.closed.or.open",
"Exponent": 0,
"PollPeriodMs": 200,
"RelayIdx": 2,
"TypeName": "relay.actor.config",
"Unit": "Unitless",
"Version": "001",
"Version": "002",
"WiringConfig": "NormallyClosed",
},
{
Expand All @@ -49,20 +55,23 @@ def test_i2c_multichannel_dt_relay_component_gt_generated() -> None:
"ChannelName": "charge-discharge-relay3",
"DeEnergizingEvent": "DischargeStore",
"EnergizingEvent": "ChargeStore",
"DeEnergizedState": "DischargingStore",
"EnergizedState": "ChargingStore",
"EventType": "change.store.flow.relay",
"StateType": "store.flow.relay",
"Exponent": 0,
"PollPeriodMs": 200,
"RelayIdx": 3,
"TypeName": "relay.actor.config",
"Unit": "Unitless",
"Version": "001",
"Version": "002",
"WiringConfig": "NormallyOpen",
},
],
"DisplayName": "i2c krida relay boards",
"I2cAddressList": [32, 33],
"TypeName": "i2c.multichannel.dt.relay.component.gt",
"Version": "001",
"Version": "002",
}

d2 = I2cMultichannelDtRelayComponentGt.model_validate(d).model_dump(
Expand Down
5 changes: 4 additions & 1 deletion tests/named_types/test_relay_actor_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ def test_relay_actor_config_generated() -> None:
"ActorName": "zone1-ctrl-relay",
"WiringConfig": "NormallyOpen",
"EventType": "change.relay.state",
"StateType": "relay.open.or.closed",
"DeEnergizingEvent": "OpenRelay",
"EnergizingEvent": "CloseRelay",
"DeEnergizedState": "RelayOpen",
"EnergizedState": "RelayClosed",
"TypeName": "relay.actor.config",
"Version": "001",
"Version": "002",
}

t = RelayActorConfig.model_validate(d).model_dump_json(exclude_none=True)
Expand Down

0 comments on commit 14a8618

Please sign in to comment.