Module misty2py_skills.demonstrations.battery_printer

This module implements a skill that prints the battery status every 250ms for the duration specified by the system argument.

Global variables

var DEFAULT_DURATION

The defaults duration of the skill in seconds.

Functions

def battery_printer(misty: misty2py.robot.Misty, duration: int | float = 2) ‑> Dict
Expand source code
def battery_printer(
    misty: Misty, duration: Union[int, float] = DEFAULT_DURATION
) -> Dict:
    """Prints the battery status every 250ms for `duration` seconds.

    Args:
        misty (Misty): The Misty whose battery status to print.
        duration (Union[int, float], optional): The duration of the skill. Defaults to DEFAULT_DURATION.

    Returns:
        Dict: The dictionary with `"overall_success"` key (bool) and keys for every action performed (dictionarised Misty2pyResponse).
    """
    cancel_skills(misty)

    events = []
    event_type = "BatteryCharge"

    subscription = misty.event(
        "subscribe", type=event_type, name=event_name, event_emitter=ee
    ).parse_to_dict()
    events.append({"subscription": subscription})

    time.sleep(duration)
    events.extend(actions.get_())

    unsubscription = misty.event("unsubscribe", name=event_name).parse_to_dict()
    events.append({"unsubscription": unsubscription})

    return success_of_action_list(events)

Prints the battery status every 250ms for duration seconds.

Args

misty : Misty
The Misty whose battery status to print.
duration : Union[int, float], optional
The duration of the skill. Defaults to DEFAULT_DURATION.

Returns

Dict
The dictionary with "overall_success" key (bool) and keys for every action performed (dictionarised Misty2pyResponse).
def listener(data: Dict)
Expand source code
@ee.on(event_name)
def listener(data: Dict):
    """Prints received battery data and appends it to the list of actions."""
    print(data)
    actions.append_(
        {"battery_status": {"message": data, "status": status_of_battery_event(data)}}
    )

Prints received battery data and appends it to the list of actions.

def status_of_battery_event(data: Dict) ‑> bool
Expand source code
def status_of_battery_event(data: Dict) -> bool:
    """Verifies whether the receives data indicates a valid battery status."""
    for required in [
        "chargePercent",
        "created",
        "current",
        "healthPercent",
        "isCharging",
        "sensorId",
        "state",
        "temperature",
        "trained",
        "voltage",
    ]:
        if isinstance(data.get(required), type(None)):
            return False
    return True

Verifies whether the receives data indicates a valid battery status.