From caaffb1aa3b46463561260c24b6562bb6a2edcc8 Mon Sep 17 00:00:00 2001 From: Jessica Millar Date: Sun, 10 Nov 2024 17:33:11 -0500 Subject: [PATCH] Updates to FsmEvent etc --- src/gwproto/data_classes/house_0_names.py | 20 ++++-- src/gwproto/enums/__init__.py | 20 ++++-- src/gwproto/enums/aquastat_control.py | 36 ++++++++++ .../enums/change_store_flow_direction.py | 31 -------- src/gwproto/enums/change_store_flow_relay.py | 36 ++++++++++ src/gwproto/enums/fsm_event_type.py | 70 ------------------- src/gwproto/enums/heat_pump_control.py | 36 ++++++++++ src/gwproto/enums/heatcall_source.py | 38 ++++++++++ src/gwproto/enums/pico_cycler_event.py | 46 ++++++++++++ src/gwproto/enums/pico_cycler_state.py | 2 + src/gwproto/enums/primary_pump_control.py | 36 ++++++++++ src/gwproto/enums/store_flow_direction.py | 35 ---------- src/gwproto/enums/store_flow_relay.py | 39 +++++++++++ src/gwproto/named_types/fsm_atomic_report.py | 10 +-- src/gwproto/named_types/fsm_event.py | 61 ++++++++-------- src/gwproto/named_types/relay_actor_config.py | 16 ++--- src/gwproto/type_helpers/__init__.py | 2 - .../type_helpers/event_enum_by_name.py | 21 ------ tests/enums/aquastat_control_test.py | 16 +++++ .../enums/change_store_flow_direction_test.py | 15 ---- tests/enums/change_store_flow_relay_test.py | 16 +++++ tests/enums/fsm_event_type_test.py | 28 -------- tests/enums/heat_pump_control_test.py | 16 +++++ tests/enums/heatcall_source_test.py | 16 +++++ tests/enums/pico_cycler_event_test.py | 21 ++++++ tests/enums/pico_cycler_state_test.py | 1 + tests/enums/primary_pump_control_test.py | 16 +++++ tests/enums/store_flow_direction_test.py | 17 ----- tests/enums/store_flow_relay_test.py | 16 +++++ tests/named_types/test_fsm_atomic_report.py | 30 +++++--- tests/named_types/test_fsm_event.py | 12 +--- tests/named_types/test_fsm_full_report.py | 28 ++++---- .../named_types/test_fsm_trigger_from_atn.py | 4 +- ..._i2c_multichannel_dt_relay_component_gt.py | 69 +++++++----------- tests/named_types/test_relay_actor_config.py | 9 +-- 35 files changed, 516 insertions(+), 369 deletions(-) create mode 100644 src/gwproto/enums/aquastat_control.py delete mode 100644 src/gwproto/enums/change_store_flow_direction.py create mode 100644 src/gwproto/enums/change_store_flow_relay.py delete mode 100644 src/gwproto/enums/fsm_event_type.py create mode 100644 src/gwproto/enums/heat_pump_control.py create mode 100644 src/gwproto/enums/heatcall_source.py create mode 100644 src/gwproto/enums/pico_cycler_event.py create mode 100644 src/gwproto/enums/primary_pump_control.py delete mode 100644 src/gwproto/enums/store_flow_direction.py create mode 100644 src/gwproto/enums/store_flow_relay.py delete mode 100644 src/gwproto/type_helpers/event_enum_by_name.py create mode 100644 tests/enums/aquastat_control_test.py delete mode 100644 tests/enums/change_store_flow_direction_test.py create mode 100644 tests/enums/change_store_flow_relay_test.py delete mode 100644 tests/enums/fsm_event_type_test.py create mode 100644 tests/enums/heat_pump_control_test.py create mode 100644 tests/enums/heatcall_source_test.py create mode 100644 tests/enums/pico_cycler_event_test.py create mode 100644 tests/enums/primary_pump_control_test.py delete mode 100644 tests/enums/store_flow_direction_test.py create mode 100644 tests/enums/store_flow_relay_test.py diff --git a/src/gwproto/data_classes/house_0_names.py b/src/gwproto/data_classes/house_0_names.py index 420f5332..ef362560 100644 --- a/src/gwproto/data_classes/house_0_names.py +++ b/src/gwproto/data_classes/house_0_names.py @@ -104,13 +104,19 @@ class H0N: store_charge_discharge_relay: Literal["relay3"] = ( f"relay{House0RelayIdx.store_charge_disharge}" ) - hp_failsafe_relay = f"relay{House0RelayIdx.hp_failsafe}" - hp_scada_ops_relay = f"relay{House0RelayIdx.hp_scada_ops}" - aquastat_ctrl_relay = f"relay{House0RelayIdx.aquastat_ctrl}" - store_pump_failsafe = f"relay{House0RelayIdx.store_pump_failsafe}" - boiler_scada_ops = f"relay{House0RelayIdx.boiler_scada_ops}" - primary_pump_scada_ops = f"relay{House0RelayIdx.primary_pump_ops}" - primary_pump_failsafe = f"relay{House0RelayIdx.primary_pump_failsafe}" + hp_failsafe_relay: Literal["relay5"] = f"relay{House0RelayIdx.hp_failsafe}" + hp_scada_ops_relay: Literal["relay6"] = f"relay{House0RelayIdx.hp_scada_ops}" + aquastat_ctrl_relay: Literal["relay8"] = f"relay{House0RelayIdx.aquastat_ctrl}" + store_pump_failsafe: Literal["relay9"] = ( + f"relay{House0RelayIdx.store_pump_failsafe}" + ) + boiler_scada_ops: Literal["relay10"] = f"relay{House0RelayIdx.boiler_scada_ops}" + primary_pump_scada_ops: Literal["relay11"] = ( + f"relay{House0RelayIdx.primary_pump_ops}" + ) + primary_pump_failsafe: Literal["relay12"] = ( + f"relay{House0RelayIdx.primary_pump_failsafe}" + ) hubitat = "hubitat" # finite state machines diff --git a/src/gwproto/enums/__init__.py b/src/gwproto/enums/__init__.py index 2a262752..91cee0dc 100644 --- a/src/gwproto/enums/__init__.py +++ b/src/gwproto/enums/__init__.py @@ -32,28 +32,32 @@ from gwproto.enums.actor_class import ActorClass from gwproto.enums.alert_priority import AlertPriority +from gwproto.enums.aquastat_control import AquastatControl from gwproto.enums.change_aquastat_control import ChangeAquastatControl from gwproto.enums.change_heat_pump_control import ChangeHeatPumpControl from gwproto.enums.change_heatcall_source import ChangeHeatcallSource from gwproto.enums.change_primary_pump_control import ChangePrimaryPumpControl from gwproto.enums.change_relay_pin import ChangeRelayPin from gwproto.enums.change_relay_state import ChangeRelayState -from gwproto.enums.change_store_flow_direction import ChangeStoreFlowDirection +from gwproto.enums.change_store_flow_relay import ChangeStoreFlowRelay from gwproto.enums.change_valve_state import ChangeValveState from gwproto.enums.fsm_action_type import FsmActionType -from gwproto.enums.fsm_event_type import FsmEventType from gwproto.enums.fsm_name import FsmName from gwproto.enums.fsm_report_type import FsmReportType from gwproto.enums.gpm_from_hz_method import GpmFromHzMethod +from gwproto.enums.heat_pump_control import HeatPumpControl +from gwproto.enums.heatcall_source import HeatcallSource from gwproto.enums.hz_calc_method import HzCalcMethod from gwproto.enums.kind_of_param import KindOfParam from gwproto.enums.make_model import MakeModel +from gwproto.enums.pico_cycler_event import PicoCyclerEvent from gwproto.enums.pico_cycler_state import PicoCyclerState +from gwproto.enums.primary_pump_control import PrimaryPumpControl from gwproto.enums.relay_closed_or_open import RelayClosedOrOpen from gwproto.enums.relay_energization_state import RelayEnergizationState from gwproto.enums.relay_pin_set import RelayPinSet from gwproto.enums.relay_wiring_config import RelayWiringConfig -from gwproto.enums.store_flow_direction import StoreFlowDirection +from gwproto.enums.store_flow_relay import StoreFlowRelay from gwproto.enums.telemetry_name import TelemetryName from gwproto.enums.temp_calc_method import TempCalcMethod from gwproto.enums.thermistor_data_method import ThermistorDataMethod @@ -62,28 +66,32 @@ __all__ = [ "ActorClass", # [sh.actor.class.002](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#shactorclass) "AlertPriority", # [alert.priority.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#alertpriority) + "AquastatControl", # [aquastat.control.state.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#aquastatcontrolstate) "ChangeAquastatControl", # [change.aquastat.control.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changeaquastatcontrol) "ChangeHeatPumpControl", # [change.heat.pump.control.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changeheatpumpcontrol) "ChangeHeatcallSource", # [change.heatcall.source.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changeheatcallsource) "ChangePrimaryPumpControl", # [change.primary.pump.control.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changeprimarypumpcontrol) "ChangeRelayPin", # [change.relay.pin.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changerelaypin) "ChangeRelayState", # [change.relay.state.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changerelaystate) - "ChangeStoreFlowDirection", # [change.store.flow.direction.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changestoreflowdirection) + "ChangeStoreFlowRelay", # [change.store.flow.relay.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changestoreflowrelay) "ChangeValveState", # [change.valve.state.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changevalvestate) "FsmActionType", # [sh.fsm.action.type.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#shfsmactiontype) - "FsmEventType", # [sh.fsm.event.type.001](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#shfsmeventtype) "FsmName", # [sh.fsm.name.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#shfsmname) "FsmReportType", # [fsm.report.type.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#fsmreporttype) "GpmFromHzMethod", # [gpm.from.hz.method.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#gpmfromhzmethod) + "HeatPumpControl", # [heat.pump.control.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#heatpumpcontrol) + "HeatcallSource", # [heatcall.source.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#heatcallsource) "HzCalcMethod", # [hz.calc.method.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#hzcalcmethod) "KindOfParam", # [spaceheat.kind.of.param.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#spaceheatkindofparam) "MakeModel", # [spaceheat.make.model.003](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#spaceheatmakemodel) + "PicoCyclerEvent", # [pico.cycler.event.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#picocyclerevent) "PicoCyclerState", # [pico.cycler.state.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#picocyclerstate) + "PrimaryPumpControl", # [primary.pump.control.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#primarypumpcontrol) "RelayClosedOrOpen", # [relay.closed.or.open.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#relayclosedoropen) "RelayEnergizationState", # [relay.energization.state.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#relayenergizationstate) "RelayPinSet", # [relay.pin.set.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#relaypinset) "RelayWiringConfig", # [relay.wiring.config.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#relaywiringconfig) - "StoreFlowDirection", # [store.flow.direction.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#storeflowdirection) + "StoreFlowRelay", # [store.flow.relay.000](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#storeflowrelay) "TelemetryName", # [spaceheat.telemetry.name.001](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) diff --git a/src/gwproto/enums/aquastat_control.py b/src/gwproto/enums/aquastat_control.py new file mode 100644 index 00000000..d70f39e5 --- /dev/null +++ b/src/gwproto/enums/aquastat_control.py @@ -0,0 +1,36 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class AquastatControl(GwStrEnum): + """ + + Values: + - Boiler + - Scada + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#aquastatcontrolstate) + """ + + Boiler = auto() + Scada = auto() + + @classmethod + def default(cls) -> "AquastatControl": + return cls.Boiler + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "aquastat.control.state" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/enums/change_store_flow_direction.py b/src/gwproto/enums/change_store_flow_direction.py deleted file mode 100644 index 2fd5458c..00000000 --- a/src/gwproto/enums/change_store_flow_direction.py +++ /dev/null @@ -1,31 +0,0 @@ -# Literal Enum: -# - no additional values can be added over time. -# - Sent as-is, not in hex symbol -from enum import auto -from typing import List - -from gwproto.enums.relay_event_base import RelayEventBase - - -class ChangeStoreFlowDirection(RelayEventBase): - """ - Events that trigger changing StoreFlowDirection finite state machine - """ - - Discharge = auto() - Charge = auto() - - @classmethod - def values(cls) -> List[str]: - """ - Returns enum choices - """ - return [elt.value for elt in cls] - - @classmethod - def default(cls) -> "ChangeStoreFlowDirection": - return cls.Discharge - - @classmethod - def enum_name(cls) -> str: - return "change.store.flow.direction" diff --git a/src/gwproto/enums/change_store_flow_relay.py b/src/gwproto/enums/change_store_flow_relay.py new file mode 100644 index 00000000..dd7902c3 --- /dev/null +++ b/src/gwproto/enums/change_store_flow_relay.py @@ -0,0 +1,36 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class ChangeStoreFlowRelay(GwStrEnum): + """ + Events that trigger changing StoreFlowDirection finite state machine + Values: + - DischargeStore + - ChargeStore + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#changestoreflowrelay) + """ + + DischargeStore = auto() + ChargeStore = auto() + + @classmethod + def default(cls) -> "ChangeStoreFlowRelay": + return cls.DischargeStore + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "change.store.flow.relay" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/enums/fsm_event_type.py b/src/gwproto/enums/fsm_event_type.py deleted file mode 100644 index 8812a5b0..00000000 --- a/src/gwproto/enums/fsm_event_type.py +++ /dev/null @@ -1,70 +0,0 @@ -from enum import auto -from typing import List - -from gw.enums import GwStrEnum - - -class FsmEventType(GwStrEnum): - """ - The name of a set of events for a particular Spaceheat finite state machine. - Values: - - PicoCyclerEvent - - ChangeRelayPin: Meant to be used between a single relay actor and a multiplexer - (for example, an i2c relay actor and an i2c relay multiplexer). The associated values - are DeEnergized and Energized. Note that the multiplexer does not concern itself with - the configuration of the relay (NormallyOpen, NormallyClosed, DoubleThrow). Instead, - it just makes sure it is receiving a ChangeRelayPin command from one of its known relays. - - ChangeRelayState: Meant to be used for a relay whose RelayConfig is NormallyOpen - or NormallyClosed (not DoubleThrow). Associated values are CloseRelay and OpenRelay - - so it is meant to be a layer up in abstraction from sending energization/de-energization - commands to the pin. The sender indeed does not need to know whether the relay is normally - open or normally closed (although obviously the receiver must know). - - SetAnalog010V - - SetAnalog420mA - - ChangeValveState - - ChangeStoreFlowDirection - - ChangeHeatcallSource - - ChangeAquastatControl - - ChangeHeatPumpControl - - ChangeLgOperatingMode - - TimerFinished - - ChangePrimaryPumpState - - ChangePrimaryPumpControl: Change control of the primary pump between the Heat - pump and the SCADA - - For more information: - - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) - - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#shfsmeventtype) - - [More Info](https://gridworks-protocol.readthedocs.io/en/latest/finite-state-machines.html) - """ - - PicoCyclerEvent = auto() - ChangeRelayPin = auto() - ChangeRelayState = auto() - SetAnalog010V = auto() - SetAnalog420mA = auto() - ChangeValveState = auto() - ChangeStoreFlowDirection = auto() - ChangeHeatcallSource = auto() - ChangeAquastatControl = auto() - ChangeHeatPumpControl = auto() - ChangeLgOperatingMode = auto() - TimerFinished = auto() - ChangePrimaryPumpState = auto() - ChangePrimaryPumpControl = auto() - - @classmethod - def default(cls) -> "FsmEventType": - return cls.ChangeRelayState - - @classmethod - def values(cls) -> List[str]: - return [elt.value for elt in cls] - - @classmethod - def enum_name(cls) -> str: - return "sh.fsm.event.type" - - @classmethod - def enum_version(cls) -> str: - return "001" diff --git a/src/gwproto/enums/heat_pump_control.py b/src/gwproto/enums/heat_pump_control.py new file mode 100644 index 00000000..902445a0 --- /dev/null +++ b/src/gwproto/enums/heat_pump_control.py @@ -0,0 +1,36 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class HeatPumpControl(GwStrEnum): + """ + + Values: + - BufferTankAquastat + - Scada + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#heatpumpcontrol) + """ + + BufferTankAquastat = auto() + Scada = auto() + + @classmethod + def default(cls) -> "HeatPumpControl": + return cls.BufferTankAquastat + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "heat.pump.control" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/enums/heatcall_source.py b/src/gwproto/enums/heatcall_source.py new file mode 100644 index 00000000..08c1111e --- /dev/null +++ b/src/gwproto/enums/heatcall_source.py @@ -0,0 +1,38 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class HeatcallSource(GwStrEnum): + """ + Used for reflecting the state of a double-throw relay that can toggle between a failsafe + for providing a 24V heat call to a zone controller (aka Wall Thermostat) and the SCADA providing + that heat call + Values: + - WallThermostat + - Scada + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#heatcallsource) + """ + + WallThermostat = auto() + Scada = auto() + + @classmethod + def default(cls) -> "HeatcallSource": + return cls.WallThermostat + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "heatcall.source" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/enums/pico_cycler_event.py b/src/gwproto/enums/pico_cycler_event.py new file mode 100644 index 00000000..b8ae52c0 --- /dev/null +++ b/src/gwproto/enums/pico_cycler_event.py @@ -0,0 +1,46 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class PicoCyclerEvent(GwStrEnum): + """ + + Values: + - PicoMissing + - ConfirmOpened + - StartClosing + - ConfirmClosed + - ConfirmRebooted + - AllZombies + - RebootDud + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#picocyclerevent) + """ + + PicoMissing = auto() + ConfirmOpened = auto() + StartClosing = auto() + ConfirmClosed = auto() + ConfirmRebooted = auto() + AllZombies = auto() + RebootDud = auto() + + @classmethod + def default(cls) -> "PicoCyclerEvent": + return cls.ConfirmRebooted + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "pico.cycler.event" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/enums/pico_cycler_state.py b/src/gwproto/enums/pico_cycler_state.py index aad232e3..6a424548 100644 --- a/src/gwproto/enums/pico_cycler_state.py +++ b/src/gwproto/enums/pico_cycler_state.py @@ -13,6 +13,7 @@ class PicoCyclerState(GwStrEnum): - RelayOpen - RelayClosing - PicosRebooting + - AllZombies For more information: - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) @@ -24,6 +25,7 @@ class PicoCyclerState(GwStrEnum): RelayOpen = auto() RelayClosing = auto() PicosRebooting = auto() + AllZombies = auto() @classmethod def default(cls) -> "PicoCyclerState": diff --git a/src/gwproto/enums/primary_pump_control.py b/src/gwproto/enums/primary_pump_control.py new file mode 100644 index 00000000..1d6d7746 --- /dev/null +++ b/src/gwproto/enums/primary_pump_control.py @@ -0,0 +1,36 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class PrimaryPumpControl(GwStrEnum): + """ + + Values: + - HeatPump + - Scada + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#primarypumpcontrol) + """ + + HeatPump = auto() + Scada = auto() + + @classmethod + def default(cls) -> "PrimaryPumpControl": + return cls.HeatPump + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "primary.pump.control" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/enums/store_flow_direction.py b/src/gwproto/enums/store_flow_direction.py deleted file mode 100644 index e1420d73..00000000 --- a/src/gwproto/enums/store_flow_direction.py +++ /dev/null @@ -1,35 +0,0 @@ -# Literal Enum: -# - no additional values can be added over time. -# - Sent as-is, not in hex symbol -from enum import auto -from typing import List - -from gw.enums import GwStrEnum - - -class StoreFlowDirection(GwStrEnum): - """ - Used for a double-throw relay that can toggle between a thermal store heating up (flow is - in the charging direction) or cooling down (flow is in the discharging direction). Events - in the StoreFlowDirection finite state machine - """ - - ValvedtoDischargeStore = auto() - ValvesMovingToCharging = auto() - ValvedtoChargeStore = auto() - ValvesMovingToDischarging = auto() - - @classmethod - def values(cls) -> List[str]: - """ - Returns enum choices - """ - return [elt.value for elt in cls] - - @classmethod - def default(cls) -> "StoreFlowDirection": - return cls.ValvedtoDischargeStore - - @classmethod - def enum_name(cls) -> str: - return "store.flow.direction" diff --git a/src/gwproto/enums/store_flow_relay.py b/src/gwproto/enums/store_flow_relay.py new file mode 100644 index 00000000..65b1eb84 --- /dev/null +++ b/src/gwproto/enums/store_flow_relay.py @@ -0,0 +1,39 @@ +from enum import auto +from typing import List + +from gw.enums import GwStrEnum + + +class StoreFlowRelay(GwStrEnum): + """ + Used for a double-throw relay that can toggle between a thermal store heating up (flow is + in the charging direction) or cooling down (flow is in the discharging direction). Events + in the StoreFlowDirection finite state machine + Values: + - DischargingStore: Thermal store is discharging (and heating the building) + - ChargingStore: Thermal store is charging from an external source (like a heat + pump or oil boiler). + + For more information: + - [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/) + - [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#storeflowrelay) + """ + + DischargingStore = auto() + ChargingStore = auto() + + @classmethod + def default(cls) -> "StoreFlowRelay": + return cls.DischargingStore + + @classmethod + def values(cls) -> List[str]: + return [elt.value for elt in cls] + + @classmethod + def enum_name(cls) -> str: + return "store.flow.relay" + + @classmethod + def enum_version(cls) -> str: + return "000" diff --git a/src/gwproto/named_types/fsm_atomic_report.py b/src/gwproto/named_types/fsm_atomic_report.py index d698d830..9e562f0f 100644 --- a/src/gwproto/named_types/fsm_atomic_report.py +++ b/src/gwproto/named_types/fsm_atomic_report.py @@ -5,7 +5,7 @@ from pydantic import BaseModel, ConfigDict, StrictInt, model_validator from typing_extensions import Self -from gwproto.enums import FsmActionType, FsmEventType, FsmName, FsmReportType +from gwproto.enums import FsmActionType, FsmReportType from gwproto.property_format import ( HandleName, UTCMilliseconds, @@ -14,12 +14,12 @@ class FsmAtomicReport(BaseModel): - FromHandle: HandleName - AboutFsm: FsmName + MachineHandle: HandleName + StateEnum: str ReportType: FsmReportType ActionType: Optional[FsmActionType] = None Action: Optional[StrictInt] = None - EventType: Optional[FsmEventType] = None + EventEnum: Optional[str] = None Event: Optional[str] = None FromState: Optional[str] = None ToState: Optional[str] = None @@ -28,7 +28,7 @@ class FsmAtomicReport(BaseModel): TypeName: Literal["fsm.atomic.report"] = "fsm.atomic.report" Version: Literal["000"] = "000" - model_config = ConfigDict(use_enum_values=True) + model_config = ConfigDict(extra="allow") @model_validator(mode="after") def check_axiom_1(self) -> Self: diff --git a/src/gwproto/named_types/fsm_event.py b/src/gwproto/named_types/fsm_event.py index a56f61ad..4b7bf0cd 100644 --- a/src/gwproto/named_types/fsm_event.py +++ b/src/gwproto/named_types/fsm_event.py @@ -12,11 +12,11 @@ ChangePrimaryPumpControl, ChangeRelayPin, ChangeRelayState, - ChangeStoreFlowDirection, - FsmEventType, + ChangeStoreFlowRelay, ) from gwproto.property_format import ( HandleName, + LeftRightDotStr, UTCMilliseconds, UUID4Str, ) @@ -25,7 +25,7 @@ class FsmEvent(BaseModel): FromHandle: HandleName ToHandle: HandleName - EventType: FsmEventType + EventType: LeftRightDotStr EventName: str TriggerId: UUID4Str SendTimeUnixMs: UTCMilliseconds @@ -41,71 +41,66 @@ def check_axiom_1(self) -> Self: """ if ( - self.EventType == "ChangeAquastatControl" + self.EventType == ChangeAquastatControl.enum_name() and self.EventName not in ChangeAquastatControl.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeAquastatControl values {ChangeAquastatControl.values()}" + f"EventName {self.EventName} must belong to EventType {ChangeAquastatControl.enum_name()} values {ChangeAquastatControl.values()}" ) if ( - self.EventType == "ChangeHeatcallSource" + self.EventType == ChangeHeatcallSource.enum_name() and self.EventName not in ChangeHeatcallSource.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeHeatcallSource values {ChangeHeatcallSource.values()}" + f"EventName {self.EventName} must belong to EventType {ChangeHeatcallSource.enum_name()} values {ChangeHeatcallSource.values()}" ) if ( - self.EventType == "ChangeHeatPumpControl" + self.EventType == ChangeHeatPumpControl.enum_name() and self.EventName not in ChangeHeatPumpControl.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeHeatPumpControl values {ChangeHeatPumpControl.values()}" + f"EventName {self.EventName} must belong to EventType {ChangeHeatPumpControl.enum_name()} values {ChangeHeatPumpControl.values()}" ) if ( - self.EventType == "ChangePrimaryPumpControl" + self.EventType == ChangePrimaryPumpControl.enum_name() and self.EventName not in ChangePrimaryPumpControl.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangePrimaryPumpControl values {ChangePrimaryPumpControl.values()}" + f"EventName {self.EventName} must belong to EventType {ChangePrimaryPumpControl.enum_name()} values {ChangePrimaryPumpControl.values()}" ) if ( - self.EventType == "ChangeRelayPin" + self.EventType == ChangeRelayPin.enum_name() and self.EventName not in ChangeRelayPin.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeRelayPin values {ChangeRelayPin.values()}" + f"EventName {self.EventName} must belong to EventType {ChangeRelayPin.enum_name()} values {ChangeRelayPin.values()}" ) if ( - self.EventType == "ChangeRelayState" + self.EventType == ChangeRelayState.enum_name() and self.EventName not in ChangeRelayState.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeRelayState values {ChangeRelayState.values()}" + f"EventName {self.EventName} must belong to EventType {ChangeRelayState.enum_name()} values {ChangeRelayState.values()}" ) if ( - self.EventType == "ChangeStoreFlowDirection" - and self.EventName not in ChangeStoreFlowDirection.values() + self.EventType == ChangeStoreFlowRelay.enum_name() + and self.EventName not in ChangeStoreFlowRelay.values() ): raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeStoreFlowDirection values {ChangeStoreFlowDirection.values()}" - ) - if ( - self.EventType == "ChangeStoreFlowDirection" - and self.EventName not in ChangeStoreFlowDirection.values() - ): - raise ValueError( - f"EventName {self.EventName} must belong to EventType ChangeStoreFlowDirection values {ChangeStoreFlowDirection.values()}" + f"EventName {self.EventName} must belong to EventType {ChangeStoreFlowRelay.enum_name()} values {ChangeStoreFlowRelay.values()}" ) if self.EventType not in [ - "ChangeAquastatControl", - "ChangeHeatcallSource", - "ChangeHeatPumpControl", - "ChangePrimaryPumpControl", - "ChangeRelayPin", - "ChangeRelayState", - "ChangeStoreFlowDirection", + ChangeAquastatControl.enum_name(), + ChangeHeatcallSource.enum_name(), + ChangeHeatPumpControl.enum_name(), + ChangePrimaryPumpControl.enum_name(), + ChangeRelayPin.enum_name(), + ChangeRelayState.enum_name(), + ChangeStoreFlowRelay.enum_name(), ]: - raise ValueError(f"Unrecognized event type {self.EventType}!") + raise ValueError( + f"Axiom 1 violated! Unrecognized event type {self.EventType}!" + ) return self @model_validator(mode="after") diff --git a/src/gwproto/named_types/relay_actor_config.py b/src/gwproto/named_types/relay_actor_config.py index 678bc6f8..8417c707 100644 --- a/src/gwproto/named_types/relay_actor_config.py +++ b/src/gwproto/named_types/relay_actor_config.py @@ -5,18 +5,16 @@ from pydantic import ConfigDict, PositiveInt, model_validator from typing_extensions import Self -from gwproto.enums import FsmEventType, RelayWiringConfig +from gwproto.enums import RelayWiringConfig from gwproto.named_types.channel_config import ChannelConfig -from gwproto.property_format import ( - SpaceheatName, -) +from gwproto.property_format import LeftRightDotStr, SpaceheatName class RelayActorConfig(ChannelConfig): RelayIdx: PositiveInt ActorName: SpaceheatName WiringConfig: RelayWiringConfig - EventType: FsmEventType + EventType: LeftRightDotStr DeEnergizingEvent: str TypeName: Literal["relay.actor.config"] = "relay.actor.config" Version: Literal["000"] = "000" @@ -27,13 +25,7 @@ class RelayActorConfig(ChannelConfig): def check_axiom_1(self) -> Self: """ Axiom 1: EventType, DeEnergizingEvent consistency. - a) The EventType must belong to one of the boolean choices for FsmEventType (for example, it is NOT SetAnalog010V): - ChangeRelayState ChangeValveState - ChangeStoreFlowDirection - ChangeHeatcallSource - ChangeBoilerControl - ChangeHeatPumpControl - ChangeLgOperatingMode + a) The EventType must belong to one of the boolean choices for EventType b) The DeEnergizingEvent string must be one of the two choices for the EventType as an enum. For example, if the EventType is ChangeValveState then the DeEnergizingEvent must either be OpenValve or CloseValve. diff --git a/src/gwproto/type_helpers/__init__.py b/src/gwproto/type_helpers/__init__.py index c6e26382..cb04b19b 100644 --- a/src/gwproto/type_helpers/__init__.py +++ b/src/gwproto/type_helpers/__init__.py @@ -16,11 +16,9 @@ ) from gwproto.named_types.web_server_gt import WebServerGt from gwproto.type_helpers.cacs_by_make_model import CACS_BY_MAKE_MODEL -from gwproto.type_helpers.event_enum_by_name import EVENT_ENUM_BY_NAME __all__ = [ "CACS_BY_MAKE_MODEL", - "EVENT_ENUM_BY_NAME", "AioHttpClientTimeout", "FibaroTempSensorSettings", "FibaroTempSensorSettingsGt", diff --git a/src/gwproto/type_helpers/event_enum_by_name.py b/src/gwproto/type_helpers/event_enum_by_name.py deleted file mode 100644 index 14be7794..00000000 --- a/src/gwproto/type_helpers/event_enum_by_name.py +++ /dev/null @@ -1,21 +0,0 @@ -from typing import Dict - -from gw.enums import GwStrEnum - -from gwproto.enums import ( - ChangeAquastatControl, - ChangeHeatcallSource, - ChangeHeatPumpControl, - ChangePrimaryPumpControl, - ChangeRelayState, - ChangeStoreFlowDirection, -) - -EVENT_ENUM_BY_NAME: Dict[str, GwStrEnum] = { - "ChangeAquastatControl": ChangeAquastatControl, - "ChangeHeatPumpControl": ChangeHeatPumpControl, - "ChangeHeatcallSource": ChangeHeatcallSource, - "ChangePrimaryPumpControl": ChangePrimaryPumpControl, - "ChangeRelayState": ChangeRelayState, - "ChangeStoreFlowDirection": ChangeStoreFlowDirection, -} diff --git a/tests/enums/aquastat_control_test.py b/tests/enums/aquastat_control_test.py new file mode 100644 index 00000000..e05ad902 --- /dev/null +++ b/tests/enums/aquastat_control_test.py @@ -0,0 +1,16 @@ +""" +Tests for enum aquastat.control.state.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import AquastatControl + + +def test_aquastat_control() -> None: + assert set(AquastatControl.values()) == { + "Boiler", + "Scada", + } + + assert AquastatControl.default() == AquastatControl.Boiler + assert AquastatControl.enum_name() == "aquastat.control.state" + assert AquastatControl.enum_version() == "000" diff --git a/tests/enums/change_store_flow_direction_test.py b/tests/enums/change_store_flow_direction_test.py deleted file mode 100644 index 0c6212fc..00000000 --- a/tests/enums/change_store_flow_direction_test.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -Tests for enum change.store.flow.direction.000 from the GridWorks Type Registry. -""" - -from gwproto.enums import ChangeStoreFlowDirection - - -def test_change_store_flow_direction() -> None: - assert set(ChangeStoreFlowDirection.values()) == { - "Discharge", - "Charge", - } - - assert ChangeStoreFlowDirection.default() == ChangeStoreFlowDirection.Discharge - assert ChangeStoreFlowDirection.enum_name() == "change.store.flow.direction" diff --git a/tests/enums/change_store_flow_relay_test.py b/tests/enums/change_store_flow_relay_test.py new file mode 100644 index 00000000..5de20b88 --- /dev/null +++ b/tests/enums/change_store_flow_relay_test.py @@ -0,0 +1,16 @@ +""" +Tests for enum change.store.flow.relay.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import ChangeStoreFlowRelay + + +def test_change_store_flow_relay() -> None: + assert set(ChangeStoreFlowRelay.values()) == { + "DischargeStore", + "ChargeStore", + } + + assert ChangeStoreFlowRelay.default() == ChangeStoreFlowRelay.DischargeStore + assert ChangeStoreFlowRelay.enum_name() == "change.store.flow.relay" + assert ChangeStoreFlowRelay.enum_version() == "000" diff --git a/tests/enums/fsm_event_type_test.py b/tests/enums/fsm_event_type_test.py deleted file mode 100644 index fd770811..00000000 --- a/tests/enums/fsm_event_type_test.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -Tests for enum sh.fsm.event.type.001 from the GridWorks Type Registry. -""" - -from gwproto.enums import FsmEventType - - -def test_fsm_event_type() -> None: - assert set(FsmEventType.values()) == { - "PicoCyclerEvent", - "ChangeRelayPin", - "ChangeRelayState", - "SetAnalog010V", - "SetAnalog420mA", - "ChangeValveState", - "ChangeStoreFlowDirection", - "ChangeHeatcallSource", - "ChangeAquastatControl", - "ChangeHeatPumpControl", - "ChangeLgOperatingMode", - "TimerFinished", - "ChangePrimaryPumpState", - "ChangePrimaryPumpControl", - } - - assert FsmEventType.default() == FsmEventType.ChangeRelayState - assert FsmEventType.enum_name() == "sh.fsm.event.type" - assert FsmEventType.enum_version() == "001" diff --git a/tests/enums/heat_pump_control_test.py b/tests/enums/heat_pump_control_test.py new file mode 100644 index 00000000..d910cae8 --- /dev/null +++ b/tests/enums/heat_pump_control_test.py @@ -0,0 +1,16 @@ +""" +Tests for enum heat.pump.control.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import HeatPumpControl + + +def test_heat_pump_control() -> None: + assert set(HeatPumpControl.values()) == { + "BufferTankAquastat", + "Scada", + } + + assert HeatPumpControl.default() == HeatPumpControl.BufferTankAquastat + assert HeatPumpControl.enum_name() == "heat.pump.control" + assert HeatPumpControl.enum_version() == "000" diff --git a/tests/enums/heatcall_source_test.py b/tests/enums/heatcall_source_test.py new file mode 100644 index 00000000..7c120378 --- /dev/null +++ b/tests/enums/heatcall_source_test.py @@ -0,0 +1,16 @@ +""" +Tests for enum heatcall.source.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import HeatcallSource + + +def test_heatcall_source() -> None: + assert set(HeatcallSource.values()) == { + "WallThermostat", + "Scada", + } + + assert HeatcallSource.default() == HeatcallSource.WallThermostat + assert HeatcallSource.enum_name() == "heatcall.source" + assert HeatcallSource.enum_version() == "000" diff --git a/tests/enums/pico_cycler_event_test.py b/tests/enums/pico_cycler_event_test.py new file mode 100644 index 00000000..fa7ac929 --- /dev/null +++ b/tests/enums/pico_cycler_event_test.py @@ -0,0 +1,21 @@ +""" +Tests for enum pico.cycler.event.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import PicoCyclerEvent + + +def test_pico_cycler_event() -> None: + assert set(PicoCyclerEvent.values()) == { + "PicoMissing", + "ConfirmOpened", + "StartClosing", + "ConfirmClosed", + "ConfirmRebooted", + "AllZombies", + "RebootDud", + } + + assert PicoCyclerEvent.default() == PicoCyclerEvent.ConfirmRebooted + assert PicoCyclerEvent.enum_name() == "pico.cycler.event" + assert PicoCyclerEvent.enum_version() == "000" diff --git a/tests/enums/pico_cycler_state_test.py b/tests/enums/pico_cycler_state_test.py index e586c188..0bc5091b 100644 --- a/tests/enums/pico_cycler_state_test.py +++ b/tests/enums/pico_cycler_state_test.py @@ -12,6 +12,7 @@ def test_pico_cycler_state() -> None: "RelayOpen", "RelayClosing", "PicosRebooting", + "AllZombies", } assert PicoCyclerState.default() == PicoCyclerState.PicosLive diff --git a/tests/enums/primary_pump_control_test.py b/tests/enums/primary_pump_control_test.py new file mode 100644 index 00000000..fdee498a --- /dev/null +++ b/tests/enums/primary_pump_control_test.py @@ -0,0 +1,16 @@ +""" +Tests for enum primary.pump.control.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import PrimaryPumpControl + + +def test_primary_pump_control() -> None: + assert set(PrimaryPumpControl.values()) == { + "HeatPump", + "Scada", + } + + assert PrimaryPumpControl.default() == PrimaryPumpControl.HeatPump + assert PrimaryPumpControl.enum_name() == "primary.pump.control" + assert PrimaryPumpControl.enum_version() == "000" diff --git a/tests/enums/store_flow_direction_test.py b/tests/enums/store_flow_direction_test.py deleted file mode 100644 index 4ee8b823..00000000 --- a/tests/enums/store_flow_direction_test.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Tests for enum store.flow.direction.000 from the GridWorks Type Registry. -""" - -from gwproto.enums import StoreFlowDirection - - -def test_store_flow_direction() -> None: - assert set(StoreFlowDirection.values()) == { - "ValvedtoDischargeStore", - "ValvesMovingToCharging", - "ValvedtoChargeStore", - "ValvesMovingToDischarging", - } - - assert StoreFlowDirection.default() == StoreFlowDirection.ValvedtoDischargeStore - assert StoreFlowDirection.enum_name() == "store.flow.direction" diff --git a/tests/enums/store_flow_relay_test.py b/tests/enums/store_flow_relay_test.py new file mode 100644 index 00000000..d9f15f53 --- /dev/null +++ b/tests/enums/store_flow_relay_test.py @@ -0,0 +1,16 @@ +""" +Tests for enum store.flow.relay.000 from the GridWorks Type Registry. +""" + +from gwproto.enums import StoreFlowRelay + + +def test_store_flow_relay() -> None: + assert set(StoreFlowRelay.values()) == { + "DischargingStore", + "ChargingStore", + } + + assert StoreFlowRelay.default() == StoreFlowRelay.DischargingStore + assert StoreFlowRelay.enum_name() == "store.flow.relay" + assert StoreFlowRelay.enum_version() == "000" diff --git a/tests/named_types/test_fsm_atomic_report.py b/tests/named_types/test_fsm_atomic_report.py index 4a2d6026..0128fe0a 100644 --- a/tests/named_types/test_fsm_atomic_report.py +++ b/tests/named_types/test_fsm_atomic_report.py @@ -1,23 +1,35 @@ """Tests fsm.atomic.report type, version 000""" +import json + +from gwproto.enums import FsmReportType from gwproto.named_types import FsmAtomicReport def test_fsm_atomic_report_generated() -> None: d = { - "FromHandle": "h.admin.store-charge-discharge.relay3", - "AboutFsm": "RelayState", - "ReportType": "Action", - "ActionType": "RelayPinSet", - "Action": 0, - "UnixTimeMs": 1710158001624, + "MachineHandle": "h.pico-cycler.relay1", + "StateEnum": "relay.closed.or.open", + "ReportType": "Event", + "EventEnum": "change.relay.state", + "Event": "CloseRelay", + "FromState": "RelayOpen", + "ToState": "RelayClosed", + "UnixTimeMs": 1709923792000, "TriggerId": "12da4269-63c3-44f4-ab65-3ee5e29329fe", "TypeName": "fsm.atomic.report", "Version": "000", } - d2 = FsmAtomicReport.model_validate(d).model_dump(exclude_none=True) + t = FsmAtomicReport.model_validate(d).model_dump_json(exclude_none=True) + d2 = json.loads(t) + assert d == d2 + + ###################################### + # Enum related + ###################################### - assert d2 == d + assert type(d2["ReportType"]) is str - assert type(d2["AboutFsm"]) is str + d2 = dict(d, ReportType="unknown_enum_thing") + assert FsmAtomicReport(**d2).ReportType == FsmReportType.default() diff --git a/tests/named_types/test_fsm_event.py b/tests/named_types/test_fsm_event.py index 16e752cc..f51279be 100644 --- a/tests/named_types/test_fsm_event.py +++ b/tests/named_types/test_fsm_event.py @@ -1,6 +1,5 @@ """Tests fsm.event type, version 000""" -from gwproto.enums import FsmEventType from gwproto.named_types import FsmEvent @@ -8,7 +7,7 @@ def test_fsm_event_generated() -> None: d = { "FromHandle": "h.s.admin", "ToHandle": "h.s.admin.iso-valve", - "EventType": "ChangeRelayState", + "EventType": "change.relay.state", "EventName": "OpenRelay", "TriggerId": "12da4269-63c3-44f4-ab65-3ee5e29329fe", "SendTimeUnixMs": 1709923791330, @@ -19,12 +18,3 @@ def test_fsm_event_generated() -> None: d2 = FsmEvent.model_validate(d).model_dump(exclude_none=True) assert d2 == d - - ###################################### - # Enum related - ###################################### - - assert type(d2["EventType"]) is str - - d2 = dict(d, EventType="unknown_enum_thing") - assert FsmEvent(**d2).EventType == FsmEventType.default() diff --git a/tests/named_types/test_fsm_full_report.py b/tests/named_types/test_fsm_full_report.py index 2f16afca..07d7449b 100644 --- a/tests/named_types/test_fsm_full_report.py +++ b/tests/named_types/test_fsm_full_report.py @@ -9,23 +9,23 @@ def test_fsm_full_report_generated() -> None: "TriggerId": "12da4269-63c3-44f4-ab65-3ee5e29329fe", "AtomicList": [ { - "FromHandle": "h.admin.store-charge-discharge", - "AboutFsm": "StoreFlowDirection", + "MachineHandle": "h.admin.store-charge-discharge", + "StateEnum": "store.flow.relay", "ReportType": "Event", - "EventType": "ChangeStoreFlowDirection", - "Event": "Discharge", - "FromState": "ValvedtoChargeStore", - "ToState": "ValvesMovingToDischarging", + "EventType": "change.store.flow.relay", + "Event": "DischargeStore", + "FromState": "ChargingStore", + "ToState": "DischargingStore", "UnixTimeMs": 1710158001595, "TriggerId": "12da4269-63c3-44f4-ab65-3ee5e29329fe", "TypeName": "fsm.atomic.report", "Version": "000", }, { - "FromHandle": "h.admin.store-charge-discharge.relay3", - "AboutFsm": "RelayState", + "MachineHandle": "h.admin.store-charge-discharge.relay3", + "StateEnum": "relay.closed.or.open", "ReportType": "Event", - "EventType": "ChangeRelayState", + "EventType": "change.relay.state", "Event": "OpenRelay", "FromState": "RelayClosed", "ToState": "RelayOpen", @@ -35,8 +35,8 @@ def test_fsm_full_report_generated() -> None: "Version": "000", }, { - "FromHandle": "h.admin.store-charge-discharge.relay3", - "AboutFsm": "RelayState", + "MachineHandle": "h.admin.store-charge-discharge.relay3", + "StateEnum": "relay.closed.or.open", "ReportType": "Action", "ActionType": "RelayPinSet", "Action": 0, @@ -46,10 +46,10 @@ def test_fsm_full_report_generated() -> None: "Version": "000", }, { - "FromHandle": "h.admin.store-charge-discharge", - "AboutFsm": "StoreFlowDirection", + "MachineHandle": "h.admin.store-charge-discharge", + "StateEnum": "store.flow", "ReportType": "Event", - "EventType": "TimerFinished", + "EventType": "timer.finished", "Event": "Belimo BallValve232VS 45 second opening timer", "FromState": "ValvesMovingToDischarging", "ToState": "ValvedtoDischargeStore", diff --git a/tests/named_types/test_fsm_trigger_from_atn.py b/tests/named_types/test_fsm_trigger_from_atn.py index a41c99dd..a49e7953 100644 --- a/tests/named_types/test_fsm_trigger_from_atn.py +++ b/tests/named_types/test_fsm_trigger_from_atn.py @@ -11,8 +11,8 @@ def test_fsm_trigger_from_atn_generated() -> None: "Trigger": { "FromHandle": "a", "ToHandle": "a.store-charge-discharge", - "EventType": "ChangeStoreFlowDirection", - "EventName": "Discharge", + "EventType": "change.store.flow.relay", + "EventName": "DischargeStore", "TriggerId": "12da4269-63c3-44f4-ab65-3ee5e29329fe", "SendTimeUnixMs": 1709923791330, "TypeName": "fsm.event", diff --git a/tests/named_types/test_i2c_multichannel_dt_relay_component_gt.py b/tests/named_types/test_i2c_multichannel_dt_relay_component_gt.py index 741ce161..a324aa00 100644 --- a/tests/named_types/test_i2c_multichannel_dt_relay_component_gt.py +++ b/tests/named_types/test_i2c_multichannel_dt_relay_component_gt.py @@ -8,74 +8,55 @@ def test_i2c_multichannel_dt_relay_component_gt_generated() -> None: d = { "ComponentAttributeClassId": "29eab8b1-100f-4230-bb44-3a2fcba33cc3", - "ComponentId": "cadd18d8-29f4-4909-9fe6-143380093fd0", + "ComponentId": "b95e75a3-1483-484f-954f-65d202d50e6d", "ConfigList": [ { - "ChannelName": "relay3-energization", - "ActorName": "relay3", - "DeEnergizingEvent": "Discharge", - "EventType": "ChangeStoreFlowDirection", - "RelayIdx": 3, - "WiringConfig": "NormallyOpen", + "ActorName": "relay1", "AsyncCapture": True, - "AsyncCaptureDelta": 1, "CapturePeriodS": 300, + "ChannelName": "vdc-relay1", + "DeEnergizingEvent": "CloseRelay", + "EventType": "change.relay.state", "Exponent": 0, - "PollPeriodMs": 5000, - "Unit": "Unitless", + "PollPeriodMs": 200, + "RelayIdx": 1, "TypeName": "relay.actor.config", - "Version": "000", - }, - { - "ActorName": "relay5", - "DeEnergizingEvent": "SwitchToTankAquastat", - "EventType": "ChangeHeatPumpControl", - "RelayIdx": 5, - "WiringConfig": "DoubleThrow", - "AsyncCapture": True, - "AsyncCaptureDelta": 1, - "CapturePeriodS": 300, - "ChannelName": "relay5-energization", - "Exponent": 0, - "PollPeriodMs": 5000, "Unit": "Unitless", - "TypeName": "relay.actor.config", "Version": "000", + "WiringConfig": "NormallyClosed", }, { - "ActorName": "relay6", - "DeEnergizingEvent": "CloseRelay", - "EventType": "ChangeRelayState", - "RelayIdx": 6, - "WiringConfig": "NormallyClosed", + "ActorName": "relay2", "AsyncCapture": True, - "AsyncCaptureDelta": 1, "CapturePeriodS": 300, - "ChannelName": "relay6-energization", + "ChannelName": "tstat-common-relay2", + "DeEnergizingEvent": "CloseRelay", + "EventType": "change.relay.state", "Exponent": 0, - "PollPeriodMs": 5000, - "Unit": "Unitless", + "PollPeriodMs": 200, + "RelayIdx": 2, "TypeName": "relay.actor.config", + "Unit": "Unitless", "Version": "000", + "WiringConfig": "NormallyClosed", }, { - "ActorName": "relay8", - "DeEnergizingEvent": "SwitchToBoiler", - "EventType": "ChangeAquastatControl", - "RelayIdx": 6, - "WiringConfig": "DoubleThrow", + "ActorName": "relay3", "AsyncCapture": True, - "AsyncCaptureDelta": 1, "CapturePeriodS": 300, - "ChannelName": "aquastat-ctrl-relay-energization", + "ChannelName": "charge-discharge-relay3", + "DeEnergizingEvent": "DischargeStore", + "EventType": "change.store.flow.relay", "Exponent": 0, - "PollPeriodMs": 5000, - "Unit": "Unitless", + "PollPeriodMs": 200, + "RelayIdx": 3, "TypeName": "relay.actor.config", + "Unit": "Unitless", "Version": "000", + "WiringConfig": "NormallyOpen", }, ], - "DisplayName": "GSCADA double 16-pin Krida I2c Relay boards, as component", + "DisplayName": "i2c krida relay boards", "I2cAddressList": [32, 33], "TypeName": "i2c.multichannel.dt.relay.component.gt", "Version": "000", diff --git a/tests/named_types/test_relay_actor_config.py b/tests/named_types/test_relay_actor_config.py index 5b63bf5c..47846d62 100644 --- a/tests/named_types/test_relay_actor_config.py +++ b/tests/named_types/test_relay_actor_config.py @@ -1,6 +1,6 @@ """Tests relay.actor.config type, version 000""" -from gwproto.enums import FsmEventType, RelayWiringConfig +from gwproto.enums import RelayWiringConfig from gwproto.named_types import RelayActorConfig @@ -16,7 +16,7 @@ def test_relay_actor_config_generated() -> None: "RelayIdx": 18, "ActorName": "zone1-ctrl-relay", "WiringConfig": "NormallyOpen", - "EventType": "ChangeRelayState", + "EventType": "change.relay.state", "DeEnergizingEvent": "OpenRelay", "TypeName": "relay.actor.config", "Version": "000", @@ -34,8 +34,3 @@ def test_relay_actor_config_generated() -> None: d2 = dict(d, WiringConfig="unknown_enum_thing") assert RelayActorConfig(**d2).WiringConfig == RelayWiringConfig.default() - - assert type(d2["EventType"]) is str - - d2 = dict(d, EventType="unknown_enum_thing") - assert RelayActorConfig(**d2).EventType == FsmEventType.default()