Domain¶
Pure domain logic — no I/O, no framework dependencies. These modules are independently testable and reusable.
Schmitt Trigger¶
gas2mqtt.domain.schmitt
¶
Schmitt trigger for gas meter rotation detection.
A Schmitt trigger is a comparator with hysteresis. It converts the continuous Bz magnetic field value into a clean binary signal by using two thresholds: level + hysteresis (upper) and level - hysteresis (lower). This prevents rapid toggling when Bz is near the threshold.
State transitions
LOW → HIGH: when bz > level + hysteresis (magnet present) HIGH → LOW: when bz < level - hysteresis (magnet absent) Rising edge (LOW → HIGH): counts as one gas meter tick
TriggerState
¶
Bases: Enum
Binary state of the Schmitt trigger.
TriggerEvent
dataclass
¶
TriggerEvent(
previous: TriggerState,
current: TriggerState,
is_rising_edge: bool,
)
Record of a state transition in the Schmitt trigger.
Attributes:
| Name | Type | Description |
|---|---|---|
previous |
TriggerState
|
State before the transition. |
current |
TriggerState
|
State after the transition. |
is_rising_edge |
bool
|
True when transitioning LOW → HIGH (one gas tick). |
SchmittTrigger
¶
Schmitt trigger with configurable level and hysteresis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
Centre threshold for the Bz magnetic field value. |
required |
hysteresis
|
int
|
Half-width of the dead band around level. |
required |
Source code in packages/src/gas2mqtt/domain/schmitt.py
update
¶
update(bz: int) -> TriggerEvent | None
Feed a Bz magnetometer value and return any state change.
Returns:
| Type | Description |
|---|---|
TriggerEvent | None
|
A |
Source code in packages/src/gas2mqtt/domain/schmitt.py
Consumption Tracker¶
gas2mqtt.domain.consumption
¶
Gas consumption tracker.
Tracks cumulative gas consumption in cubic meters. Each gas meter tick represents a configurable amount of gas (default: 10 liters = 0.01 m³).
The consumption value can be: - Incremented by ticks (each tick adds liters_per_tick / 1000 m³) - Set to an absolute value via MQTT command - Reset to zero
This is an optional feature (enabled via settings).