dm_mac.models.machine module¶
Model representing a machine.
- class dm_mac.models.machine.Machine(name: str, authorizations_or: List[str], unauthorized_warn_only: bool = False, always_enabled: bool = False, alias: str | None = None)¶
Bases:
objectObject representing a machine and its state and configuration.
- alias: str | None¶
Optional human-friendly alias for the machine
- always_enabled: bool¶
Whether machine is always enabled without RFID authentication
- property as_dict: Dict[str, Any]¶
Return a dict representation of this machine.
- authorizations_or: List[str]¶
List of OR’ed authorizations, any of which is sufficient
- property display_name: str¶
Return the display name for this machine (alias if present, else name).
- async lockout(slack: SlackHandler | None = None) None¶
Pass directly to self.state.
- name: str¶
The name of the machine
- async oops(slack: SlackHandler | None = None) None¶
Pass directly to self.state.
- state: MachineState¶
state of the machine
- unauthorized_warn_only: bool¶
Whether to allow anyone to operate machine regardless of authorization, just logging/displaying a warning if unauthorized
- async unlock(slack: SlackHandler | None = None) None¶
Pass directly to self.state.
- async unoops(slack: SlackHandler | None = None) None¶
Pass directly to self.state.
- async update(users: UsersConfig, **kwargs: Any) Dict[str, str | bool | float | List[float]]¶
Pass directly to self.state and return result.
- class dm_mac.models.machine.MachineState(machine: Machine, load_state: bool = True)¶
Bases:
objectObject representing frozen state in time of a machine.
- ALWAYS_ON_DISPLAY_TEXT: str = 'Always On'¶
- DEFAULT_DISPLAY_TEXT: str = 'Please Insert\nRFID Card'¶
- LOCKOUT_DISPLAY_TEXT: str = 'Down for\nmaintenance'¶
- OOPS_DISPLAY_TEXT: str = 'Oops!! Please\ncheck/post Slack'¶
- STATUS_LED_BRIGHTNESS: float = 0.5¶
- async _handle_oops(users: UsersConfig) None¶
Handle oops button press.
- async _handle_reboot() None¶
Handle when the ESP32 (MCU) has rebooted since last checkin.
This logs out the current user if logged in and resets the machine state. For always-enabled machines, restores the always-on state.
- async _handle_rfid_insert(users: UsersConfig, rfid_value: str) None¶
Handle change in the RFID value.
- async _handle_rfid_remove() None¶
Handle RFID card removed.
- async _handle_rfid_tracking_always_enabled(users: UsersConfig, rfid_value: str | None) None¶
Track RFID changes for always-enabled machines without changing state.
This method logs RFID insertions and removals for auditing purposes while maintaining the always-on state of the machine.
- _load_from_cache() None¶
Load machine state cache from disk.
- _lock: allocate_lock¶
- _save_cache() None¶
Save machine state cache to disk.
- _state_dir: str¶
Path to the directory to save machine state in
- _state_path: str¶
Path to pickled state file
- async _user_is_authorized(user: User, slack: SlackHandler | None = None) bool¶
Return whether user is authorized for this machine.
- current_amps: float¶
Last reported output ammeter reading (if equipped).
- display_text: str¶
Text currently displayed on the machine LCD screen
- internal_temperature_c: float | None¶
ESP32 internal temperature in °C
- is_locked_out: bool¶
Whether the machine is locked out from use.
- is_oopsed: bool¶
Whether the machine’s Oops button has been pressed.
- last_checkin: float | None¶
Float timestamp of the machine’s last checkin time
- last_update: float | None¶
Float timestamp of the last time that machine state changed in a meaningful way, i.e. RFID value or Oops
- lockout() None¶
Lock-out the machine.
- property machine_response: Dict[str, str | bool | float | List[float]]¶
Return the response dict to send to the machine.
- oops(do_locking: bool = True) None¶
Oops the machine.
- relay_desired_state: bool¶
Whether the output relay should be on or not.
- rfid_present_since: float | None¶
Float timestamp when rfid_value last changed to a non-None value.
- rfid_value: str | None¶
Value of the RFID card/fob in use, or None if not present.
- status_led_brightness: float¶
status LED brightness value; float 0 to 1
- status_led_rgb: Tuple[float, float, float]¶
RGB values for status LED; floats 0 to 1
- unlock() None¶
Un-lock-out the machine.
- unoops(do_locking: bool = True) None¶
Un-oops the machine.
- async update(users: UsersConfig, oops: bool = False, rfid_value: str | None = None, uptime: float | None = None, wifi_signal_db: float | None = None, wifi_signal_percent: float | None = None, internal_temperature_c: float | None = None, amps: float | None = None) Dict[str, str | bool | float | List[float]]¶
Handle an update to the machine via API.
- uptime: float¶
Uptime of the machine’s ESP32 in seconds
- wifi_signal_db: float | None¶
ESP32 WiFi signal strength in dB
- wifi_signal_percent: float | None¶
ESP32 WiFi signal strength in percent
- class dm_mac.models.machine.MachinesConfig¶
Bases:
objectClass representing machines configuration file.
- _load_and_validate_config() Dict[str, Dict[str, Any]]¶
Load and validate the config file.
- load_time: float¶
- static validate_config(config: Dict[str, Dict[str, Any]]) None¶
Validate configuration via jsonschema.