2. Train

from intelino.trainlib_async import Train
class trainlib_async.Train

Train class with async API.

property id: str

Connection ID / address.

property name: str

Advertised name.

property alias: str

User-defined nickname (train alias).

property connection_status: Observable
property is_connected: bool
property notifications: Observable

Response and event stream from the train.

This observable stream emits all messages coming from the train as TrainMsg. It can be filtered based on the type of the message.

property writes: Observable
await connect(force: bool = False, **kwargs)

Connect to the train.

await disconnect()

Disconnect from the train.

await get_mac_address()
await get_uuid()
await get_version_info()
await get_stats_lifetime_odometer()

Get lifetime odometer value in meters (precision in cm).

await drive_at_speed(speed_cmps: int | float, direction: MovementDirection = MovementDirection.FORWARD, play_feedback: bool = True)

Drive with speed control at the given speed in cm/s.

Parameters:
  • speed_cmps – Desired speed in cm/s. Possible (drivable) values are 15-75 cm/s, but not all values are possible (only multiples of 0.9425 cm).

  • direction – Movement direction forward (1), backward (2), stop (3) etc.

  • play_feedback – Sound and lights.

await drive_at_speed_level(speed_level: SpeedLevel, direction: MovementDirection = MovementDirection.FORWARD, play_feedback: bool = True)

Start driving at a speed level defined by the train (and green snaps).

Parameters:
  • speed_level – 1, 2, 3.

  • direction – Movement direction forward (1), backward (2), stop (3) etc.

  • play_feedback – Sound and lights.

await drive_with_constant_pwm(pwm: int, direction: MovementDirection = MovementDirection.FORWARD, play_feedback: bool = True)

Drive without speed control directly setting the motor’s PWM level.

Parameters:
  • pwm – Motor’s PWM value from 0 (stopped) to 255 (full power).

  • direction – Movement direction forward (1), backward (2), stop (3) etc.

  • play_feedback – Sound and lights.

await stop_driving(play_feedback_type: StopDrivingFeedbackType = StopDrivingFeedbackType.MOVEMENT_STOP)

Stop the train.

Parameters:

play_feedback – Sound and lights.

await pause_driving(time: float, play_feedback: bool = True)

Stop (pause) movement for the given time and restore it after the time passes.

Parameters:
  • time (float) – Time in seconds (max 25.5).

  • play_feedback (bool) – Sound and lights.

await set_next_split_steering_decision(next_decision: SteeringDecision)
This steering decision is valid for the next split (detected by it’s snaps).

It overrides the snap value (if set) or the random choice.

Parameters:

next – The next decision.

await set_top_led_color(r: int, g: int, b: int)

Set the top RGB LED color.

Parameters:
  • r (int) – 8bit RGB value for red.

  • g (int) – 8bit RGB value for green.

  • b (int) – 8bit RGB value for blue.

await set_headlight_color(front: Iterable[int] | None = None, back: Iterable[int] | None = None)
Set front and back headlight color (for driving). They switch based

on movement direction. To reset colors call without parameters.

Parameters:
  • front – Front 8bit RGB value array [red, green, blue].

  • back – Back 8bit RGB value array [red, green, blue].

await get_movement_notification() TrainMsgMovement

Get a single movement notification.

await movement_notification_stream(streaming: bool = True, interval: float = 0.1) Observable

Start or stop movement notification stream.

Parameters:
  • streaming (bool) – True/False to start/stop stream. Null to leave it as is (e.g. when only getting once).

  • interval (float) – Delay between streamed notifications in seconds. Minimal value is 0.1s (100ms) and maximal value is 2.550s (2550ms). Precision is 0.010s (10ms).

await set_snap_command_feedback(sound: bool, lights: bool)

Set snap behavior feedback (from BLE API v1.2).

Parameters:
  • sound (bool) – Sounds on/off.

  • lights (bool) – Blink top LED on/off.

await set_snap_command_execution(on: bool)

Enable or disable snap command execution on the train (from BLE API v1.2).

Parameters:

on (bool) – Snap execution on/off.

await clear_custom_snap_commands()

Clear user defined custom snap commands stored in the train to avoid collisions in behavior in case we would listen and react to these events.

await decouple_wagon(play_feedback: bool = True)

Decouple wagon.

Parameters:

play_feedback – Sound and lights.