jmri_core.state

Shared state enums matching JMRI's Java values.

Each enum mirrors the integer constants used in JMRI's wire formats and XML files. Do not renumber these — the values are part of the persisted contract that golden XML files in stage-0/contracts/xml/golden/ depend on.

Per-bean state enums also live in this module so persistence code can import a single namespace without circular imports through beans.

  1"""Shared state enums matching JMRI's Java values.
  2
  3Each enum mirrors the integer constants used in JMRI's wire formats and XML
  4files. **Do not renumber these** — the values are part of the persisted
  5contract that golden XML files in stage-0/contracts/xml/golden/ depend on.
  6
  7Per-bean state enums also live in this module so persistence code can import
  8a single namespace without circular imports through ``beans``.
  9"""
 10from __future__ import annotations
 11
 12from enum import IntEnum, IntFlag
 13
 14
 15class TurnoutState(IntEnum):
 16    """Matches ``jmri.Turnout.UNKNOWN/CLOSED/THROWN/INCONSISTENT`` Java constants."""
 17
 18    UNKNOWN      = 1
 19    CLOSED       = 2
 20    THROWN       = 4
 21    INCONSISTENT = 8
 22
 23
 24class TurnoutFeedback(IntFlag):
 25    """Matches ``jmri.Turnout`` feedback-mode flags."""
 26
 27    DIRECT     = 1
 28    ONESENSOR  = 2
 29    TWOSENSOR  = 4
 30    EXACT      = 8
 31    SIGNAL     = 16
 32    MONITORING = 32
 33    DELAYED    = 64
 34    LN_ALM     = 128
 35    PUSHBUTTON = 256
 36
 37
 38class SensorState(IntEnum):
 39    """Matches ``jmri.Sensor.UNKNOWN/ACTIVE/INACTIVE/INCONSISTENT``."""
 40
 41    UNKNOWN      = 1
 42    ACTIVE       = 2
 43    INACTIVE     = 4
 44    INCONSISTENT = 8
 45
 46
 47class SignalAppearance(IntEnum):
 48    """Matches ``jmri.SignalHead`` appearance constants — the 9 standard aspects.
 49
 50    Custom signals may add manufacturer-specific appearances via the
 51    SignalMast layer; SignalHead is restricted to this set.
 52    """
 53
 54    DARK          = 0
 55    RED           = 1
 56    YELLOW        = 2
 57    GREEN         = 4
 58    LUNAR         = 8
 59    FLASHRED      = 16
 60    FLASHYELLOW   = 32
 61    FLASHGREEN    = 64
 62    FLASHLUNAR    = 128
 63
 64
 65class BlockState(IntEnum):
 66    """Matches ``jmri.Block.UNDETECTED/UNOCCUPIED/OCCUPIED/UNKNOWN``."""
 67
 68    UNKNOWN    = 1
 69    OCCUPIED   = 2
 70    UNOCCUPIED = 4
 71    UNDETECTED = 256
 72
 73
 74class LightState(IntEnum):
 75    """Matches ``jmri.Light.OFF/ON/INTERMEDIATE``."""
 76
 77    UNKNOWN      = 1
 78    OFF          = 2
 79    ON           = 4
 80    INTERMEDIATE = 8
 81
 82
 83class PowerState(IntEnum):
 84    """Matches ``jmri.PowerManager.UNKNOWN/ON/OFF/IDLE``."""
 85
 86    UNKNOWN = 0
 87    ON      = 2
 88    OFF     = 4
 89    IDLE    = 8
 90
 91
 92class RouteState(IntEnum):
 93    """Internal route state — JMRI has no equivalent integer enum, this maps
 94    to behavior of ``jmri.Route`` (set / unlocked / locked)."""
 95
 96    UNLOCKED = 0
 97    LOCKED   = 1
 98    UNKNOWN  = 2
 99
100
101class ThrottleDirection(IntEnum):
102    """Locomotive direction. Matches NMRA convention."""
103
104    REVERSE = 0
105    FORWARD = 1
class TurnoutState(enum.IntEnum):
16class TurnoutState(IntEnum):
17    """Matches ``jmri.Turnout.UNKNOWN/CLOSED/THROWN/INCONSISTENT`` Java constants."""
18
19    UNKNOWN      = 1
20    CLOSED       = 2
21    THROWN       = 4
22    INCONSISTENT = 8

Matches jmri.Turnout.UNKNOWN/CLOSED/THROWN/INCONSISTENT Java constants.

UNKNOWN = <TurnoutState.UNKNOWN: 1>
CLOSED = <TurnoutState.CLOSED: 2>
THROWN = <TurnoutState.THROWN: 4>
INCONSISTENT = <TurnoutState.INCONSISTENT: 8>
class TurnoutFeedback(enum.IntFlag):
25class TurnoutFeedback(IntFlag):
26    """Matches ``jmri.Turnout`` feedback-mode flags."""
27
28    DIRECT     = 1
29    ONESENSOR  = 2
30    TWOSENSOR  = 4
31    EXACT      = 8
32    SIGNAL     = 16
33    MONITORING = 32
34    DELAYED    = 64
35    LN_ALM     = 128
36    PUSHBUTTON = 256

Matches jmri.Turnout feedback-mode flags.

DIRECT = <TurnoutFeedback.DIRECT: 1>
ONESENSOR = <TurnoutFeedback.ONESENSOR: 2>
TWOSENSOR = <TurnoutFeedback.TWOSENSOR: 4>
EXACT = <TurnoutFeedback.EXACT: 8>
SIGNAL = <TurnoutFeedback.SIGNAL: 16>
MONITORING = <TurnoutFeedback.MONITORING: 32>
DELAYED = <TurnoutFeedback.DELAYED: 64>
LN_ALM = <TurnoutFeedback.LN_ALM: 128>
PUSHBUTTON = <TurnoutFeedback.PUSHBUTTON: 256>
class SensorState(enum.IntEnum):
39class SensorState(IntEnum):
40    """Matches ``jmri.Sensor.UNKNOWN/ACTIVE/INACTIVE/INCONSISTENT``."""
41
42    UNKNOWN      = 1
43    ACTIVE       = 2
44    INACTIVE     = 4
45    INCONSISTENT = 8

Matches jmri.Sensor.UNKNOWN/ACTIVE/INACTIVE/INCONSISTENT.

UNKNOWN = <SensorState.UNKNOWN: 1>
ACTIVE = <SensorState.ACTIVE: 2>
INACTIVE = <SensorState.INACTIVE: 4>
INCONSISTENT = <SensorState.INCONSISTENT: 8>
class SignalAppearance(enum.IntEnum):
48class SignalAppearance(IntEnum):
49    """Matches ``jmri.SignalHead`` appearance constants — the 9 standard aspects.
50
51    Custom signals may add manufacturer-specific appearances via the
52    SignalMast layer; SignalHead is restricted to this set.
53    """
54
55    DARK          = 0
56    RED           = 1
57    YELLOW        = 2
58    GREEN         = 4
59    LUNAR         = 8
60    FLASHRED      = 16
61    FLASHYELLOW   = 32
62    FLASHGREEN    = 64
63    FLASHLUNAR    = 128

Matches jmri.SignalHead appearance constants — the 9 standard aspects.

Custom signals may add manufacturer-specific appearances via the SignalMast layer; SignalHead is restricted to this set.

DARK = <SignalAppearance.DARK: 0>
YELLOW = <SignalAppearance.YELLOW: 2>
GREEN = <SignalAppearance.GREEN: 4>
LUNAR = <SignalAppearance.LUNAR: 8>
FLASHRED = <SignalAppearance.FLASHRED: 16>
FLASHYELLOW = <SignalAppearance.FLASHYELLOW: 32>
FLASHGREEN = <SignalAppearance.FLASHGREEN: 64>
FLASHLUNAR = <SignalAppearance.FLASHLUNAR: 128>
class BlockState(enum.IntEnum):
66class BlockState(IntEnum):
67    """Matches ``jmri.Block.UNDETECTED/UNOCCUPIED/OCCUPIED/UNKNOWN``."""
68
69    UNKNOWN    = 1
70    OCCUPIED   = 2
71    UNOCCUPIED = 4
72    UNDETECTED = 256

Matches jmri.Block.UNDETECTED/UNOCCUPIED/OCCUPIED/UNKNOWN.

UNKNOWN = <BlockState.UNKNOWN: 1>
OCCUPIED = <BlockState.OCCUPIED: 2>
UNOCCUPIED = <BlockState.UNOCCUPIED: 4>
UNDETECTED = <BlockState.UNDETECTED: 256>
class LightState(enum.IntEnum):
75class LightState(IntEnum):
76    """Matches ``jmri.Light.OFF/ON/INTERMEDIATE``."""
77
78    UNKNOWN      = 1
79    OFF          = 2
80    ON           = 4
81    INTERMEDIATE = 8

Matches jmri.Light.OFF/ON/INTERMEDIATE.

UNKNOWN = <LightState.UNKNOWN: 1>
OFF = <LightState.OFF: 2>
ON = <LightState.ON: 4>
INTERMEDIATE = <LightState.INTERMEDIATE: 8>
class PowerState(enum.IntEnum):
84class PowerState(IntEnum):
85    """Matches ``jmri.PowerManager.UNKNOWN/ON/OFF/IDLE``."""
86
87    UNKNOWN = 0
88    ON      = 2
89    OFF     = 4
90    IDLE    = 8

Matches jmri.PowerManager.UNKNOWN/ON/OFF/IDLE.

UNKNOWN = <PowerState.UNKNOWN: 0>
ON = <PowerState.ON: 2>
OFF = <PowerState.OFF: 4>
IDLE = <PowerState.IDLE: 8>
class RouteState(enum.IntEnum):
93class RouteState(IntEnum):
94    """Internal route state — JMRI has no equivalent integer enum, this maps
95    to behavior of ``jmri.Route`` (set / unlocked / locked)."""
96
97    UNLOCKED = 0
98    LOCKED   = 1
99    UNKNOWN  = 2

Internal route state — JMRI has no equivalent integer enum, this maps to behavior of jmri.Route (set / unlocked / locked).

UNLOCKED = <RouteState.UNLOCKED: 0>
LOCKED = <RouteState.LOCKED: 1>
UNKNOWN = <RouteState.UNKNOWN: 2>
class ThrottleDirection(enum.IntEnum):
102class ThrottleDirection(IntEnum):
103    """Locomotive direction. Matches NMRA convention."""
104
105    REVERSE = 0
106    FORWARD = 1

Locomotive direction. Matches NMRA convention.

REVERSE = <ThrottleDirection.REVERSE: 0>
FORWARD = <ThrottleDirection.FORWARD: 1>