A Python package for Misty II development

Overview

Misty2py

Code style: black GitHub license

Misty2py is a Python 3 package for Misty II development using Misty's REST API.

Read the full documentation here!

Installation

Poetry

To install misty2py, run pip install misty2py.

From source

  • If this is your first time using misty2py from source, do following:

    • Get Poetry (python -m pip install poetry) if you do not have it yet.
    • Copy .env.example to .env.
    • Replace the placeholder values in the new .env file.
    • Run poetry install to obtain all dependencies.
  • Run the desired script via poetry run python -m [name] where [name] is the placeholder for the module location (in Python notation).

  • If the scripts run but your Misty does not seem to respond, you have most likely provided an incorrect IP address for MISTY_IP_ADDRESS in .env.

  • Pytests can be run via poetry run pytest ..

  • The coverage report can be obtained via poetry run pytest --cov-report html --cov=misty2py tests for HTML output or via poetry run pytest --cov=misty2py tests for terminal output.

Features

Misty2py can be used to develop complex skills (behaviours) for the Misty II robot utilising:

  • actions via sending a POST or DELETE requests to Misty's API;
  • informations via sending a GET request to Misty's API;
  • continuous streams of data via subscribing to event types on Misty's websockets.

Misty2py uses following concepts for easy of usage:

  • action keywords - customisable python-styled keywords for endpoints of Misty's API that correspond to performing actions;
  • information keywords - customisable python-styled keywords for endpoints of Misty's API that correspond to retrieving information;
  • data shortcuts - customisable python-styled keywords for commonly used data that are supplied to Misty's API as the body of a POST request.

Usage

Getting started

The main object of this package is Misty, which is an abstract representation of Misty the robot. To initialise this object, it is required to know the IP address of the Misty robot that should be used.

The most direct way to initialise a Misty object is to use the IP address directly, which allows the user to get the object in one step via:

from misty2py.robot import Misty

my_misty = Misty("192.168.0.1")  #example IP address

This may be impractical and potentially even unsafe, so it is recommended to create a .env file in the project's directory, specify the IP address there via MISTY_IP_ADDRESS="[ip_address_here]" and use Misty2py's EnvLoader to load the IP address via:

from misty2py.robot import Misty
from misty2py.utils.env_loader import EnvLoader

env_loader = EnvLoader()
my_misty = Misty(env_loader.get_ip())

Assuming a Misty object called my_misty was obtained, all required actions can be performed via the following three methods:

# Performing an action (a POST or DELETE request):
my_misty.perform_action("<action_keyword>")

# Obtaining information (a GET request):
my_misty.get_info("<information_keyword>")

# Event related methods 
# (subscribing to an event, getting event data
# or event log and unsubscribing from an event):
my_misty.event("<parameter>")

Responses

Any action performed via Misty2py which contains communication with Misty's APIs returns the Misty2pyResponse object. Misty2pyResponse is a uniform representation of two sub-responses that are present in any HTTP or WebSocket communication with Misty's APIs using Misty2py. The first sub-response is always from Misty2py and is represented by the attributes Misty2pyResponse.misty2py_status (True if no Misty2py-related errors were encountered) and potentially empty Misty2pyResponse.error_msg and Misty2pyResponse.error_type that contain error information if a Misty2py-related error was encountered. The other sub-response is either from Misty's REST API or Misty's WebSocket API. In the first case, it is represented by the attribute Misty2pyResponse.rest_response (Dict), and in the second case, it is represented by the attribute Misty2pyResponse.ws_response. One of these is always empty, because no action in Misty2py includes simultaneous communication with both APIs. For convenience, a Misty2pyResponse object can be easily parsed to a dictionary via the method Misty2pyResponse.parse_to_dict.

Obtaining information

Obtaining digital information is handled by misty2py.robot::get_info method which has two arguments. The argument info_name is required and it specifies the string information keyword corresponding to an endpoint in Misty's REST API. The argument params is optional and it supplies a dictionary of parameter name and parameter value pairs. This argument defaults to {} (an empty dictionary).

Performing actions

Performing physical and digital actions including removal of non-system files is handled by misty2py.robot::perform_action() method which takes two arguments. The argument action_name is required and it specifies the string action keyword corresponding to an endpoint in Misty’s REST API. The second argument, data, is optional and it specifies the data to pass to the request as a dictionary or a data shortcut (string). The data argument defaults to {} (an empty dictionary).

Event types

Misty's WebSocket API follows PUB-SUB architecture, which means that in order to obtain event data in Misty's framework, it is required to subscribe to an event type on Misty's WebSocket API. The WebSocket server then streams data to the WebSocket client, which receives it a separate thread. To access the data, misty2py.robot::event method must be called with "get_data" parameter from the main thread. When the data are no longer required to be streamed to the client, an event type can be unsubscribed which both kills the event thread and stops the API from sending more data.

Subscribing to an event is done via misty2py.robot::event with the parameter "subscribe" and following keyword arguments:

  • type - required; event type string as documented in Event Types Docs.
  • name - optional; a custom event name string; must be unique.
  • return_property - optional; the property to return from Misty's websockets; all properties are returned if return_property is not supplied.
  • debounce - optional; the interval in ms at which new information is sent; defaults to 250.
  • len_data_entries - optional; the maximum number of data entries to keep (discards in fifo style); defaults to 10.
  • event_emitter - optional; an event emitter function which emits an event upon message recieval. Supplies the message content as an argument.

Accessing the data of an event or its log is done via misty2py.robot::event with the parameter "get_data" or "get_log" and a keyword argument name (the name of the event).

Unsubscribing from an event is done via misty2py.robot::event with the parameter "unsubscribe" and a keyword argument name (the name of the event).

A bare-bones implementation of event subscription can be seen below.

import time

from misty2py.robot import Misty
from misty2py.utils.env_loader import EnvLoader

env_loader = EnvLoader

m = Misty(env_loader.get_ip())

d = m.event("subscribe", type = "BatteryCharge")
e_name = d.get("event_name")

time.sleep(1)

d = m.event("get_data", name = e_name)

d = m.event("unsubscribe", name = e_name)

The following example shows a more realistic scenario which includes an event emitter and an event listener.

import time
from pymitter import EventEmitter

from misty2py.robot import Misty
from misty2py.utils.env_loader import EnvLoader

env_loader = EnvLoader

m = Misty(env_loader.get_ip())
ee = EventEmitter()
event_name = "myevent_001"

@ee.on(event_name)
def listener(data):
    print(data)

d = m.event("subscribe", type = "BatteryCharge", 
            name = event_name, event_emitter = ee)

time.sleep(2)

d = m.event("unsubscribe", name = event_name)

Adding custom keywords and shortcuts

Custom keywords and shortcuts can be passed to a Misty object while declaring a new instance by using the optional arguments custom_info, custom_actions and custom_data.

The argument custom_info can be used to pass custom information keywords as a dictionary with keys being the information keywords and values being the endpoints. An information keyword can only be used for a GET method supporting endpoint.

The argument custom_actions can be used to pass custom action keywords as a dictionary with keys being the action keywords and values being a dictionary of an "endpoint" key (str) and a "method" key (str). The "method" values must be one of post, delete, put, head, options and patch. However, it should be noted that Misty's REST API currently only has GET, POST and DELETE methods. The rest of the methods was implement in Misty2py for forwards-compatibility.

The argument custom_data can be used to pass custom data shortcuts as a dictionary with keys being the data shortcuts and values being the dictionary of data values.

For futher illustration, an example of passing custom keywords and shortcuts can be seen below.

custom_allowed_infos = {
    "hazards_settings": "api/hazards/settings"
}

custom_allowed_data = {
    "amazement": {
        "FileName": "s_Amazement.wav"
    },
    "red": {
        "red": "255",
        "green": "0",
        "blue": "0"
    }
}

custom_allowed_actions = {
    "audio_play" : {
        "endpoint" : "api/audio/play",
        "method" : "post"
    },
    "delete_audio" : {
        "endpoint" : "api/audio",
        "method" : "delete"
    }
}

misty_robot = Misty("0.0.0.0", 
    custom_info=custom_allowed_infos, 
    custom_actions=custom_allowed_actions, 
    custom_data=custom_allowed_data)
You might also like...
🌈 Lightweight Python package that makes it easy and fast to print terminal messages in colors. 🌈
🌈 Lightweight Python package that makes it easy and fast to print terminal messages in colors. 🌈

🌈 Colorist for Python 🌈 Lightweight Python package that makes it easy and fast to print terminal messages in colors. Prerequisites Python 3.9 or hig

gget is a free and open-source command-line tool and Python package that enables efficient querying of genomic databases.
gget is a free and open-source command-line tool and Python package that enables efficient querying of genomic databases.

gget is a free and open-source command-line tool and Python package that enables efficient querying of genomic databases. gget consists of a collection of separate but interoperable modules, each designed to facilitate one type of database querying in a single line of code.

commandpack - A package of modules for working with commands, command packages, files with command packages.
commandpack - A package of modules for working with commands, command packages, files with command packages.

commandpack Help the project financially: Donate: https://smartlegion.github.io/donate/ Yandex Money: https://yoomoney.ru/to/4100115206129186 PayPal:

🐍The nx-python plugin allows users to create a basic python application using nx commands.
🐍The nx-python plugin allows users to create a basic python application using nx commands.

🐍 NxPy: Nx Python plugin This project was generated using Nx. The nx-python plugin allows users to create a basic python application using nx command

Simple Python Library to display text with color in Python Terminal
Simple Python Library to display text with color in Python Terminal

pyTextColor v1.0 Introduction pyTextColor is a simple Python Library to display colorful outputs in Terminal, etc. Note: Your Terminal or any software

cli simple python script to interact with iphone afc api based on python library( tidevice )
cli simple python script to interact with iphone afc api based on python library( tidevice )

afcclient cli simple python script to interact with iphone afc api based on python library( tidevice ) installation pip3 install -U tidevice cp afccli

Zecwallet-Python is a simple wrapper around the Zecwallet Command Line LightClient written in Python

A wrapper around Zecwallet Command Line LightClient, written in Python Table of Contents About Installation Usage Examples About Zecw

Python command line tool and python engine to label table fields and fields in data files.

Python command line tool and python engine to label table fields and fields in data files. It could help to find meaningful data in your tables and data files or to find Personal identifable information (PII).

xonsh is a Python-powered, cross-platform, Unix-gazing shell
xonsh is a Python-powered, cross-platform, Unix-gazing shell

xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

Releases(v5.0.0)
  • v5.0.0(Jun 27, 2021)

    Changed

    • The class Post was renamed to the class BodyRequest as it represents all HTTP requests with a body.
    • Classes Action, Info, Get, Post, MistyEvent and MistyEventHandler now require a protocol parameter.
    • Classes MistyEvent and MistyEventHandler now require an endpoint parameter.
    • The class Misty has new optional parameters rest_protocol, websocket_protocol and websocket_endpoint.
    • Updated documentation.

    Added

    • Action supports all HTTP request methods except for GET, which is supported by Info.
    • Different protocols (http, https, ws and wss) are now supported by Action (http, https), Info (http, https) and MistyEvent (ws and wss).
    • Unit tests for Status, ActionLog and every module in misty2py.basic_skills.
    • The module misty2py.response to represent responses.

    Fixed

    • The method misty2py.utils.status::get_ returns None if queried for a non-existent key.
    • Other minor fixes in tests, documentation and print statements.

    Removed

    • The entire module misty2py.utils.messages as it was replaced by misty2py.response.
    Source code(tar.gz)
    Source code(zip)
  • v4.2.1(Jun 20, 2021)

  • v4.2.0(Jun 20, 2021)

  • v4.1.5(Jun 18, 2021)

  • v4.1.4(Jun 15, 2021)

  • v4.1.3(Jun 15, 2021)

  • v4.1.2(Jun 15, 2021)

    Added

    • misty2py.basic_skills with useful basic skills: cancel_skills, expression, free_memory, movement and speak
    • added several utility functions to misty2py.utils, including misty2py.utils.status to track the execution status of skills and path and message manipulating functions

    Changed

    • fixed missing type hinting
    • black formatting
    Source code(tar.gz)
    Source code(zip)
  • v4.1.1(Jun 1, 2021)

    Added

    • additional unit tests for the utils.utils sub-package
    • pytest-cov for measuring the test coverage

    Changed

    • README.md now contains clearer instructions on running the tests and obtaining the test coverage report
    Source code(tar.gz)
    Source code(zip)
  • v4.1.0(May 19, 2021)

    Changed

    • misty2py.utils.env_loader now contains optional parameter env_path for custom path to the environmental values

    Added

    • a pytest for custom env_path for env_loader
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0(May 19, 2021)

    Removed

    • the sub-package skills -> this will become a separate package due to different dependencies which basic misty2py does not use
    • the dependencies that are no longer needed
    • documentation concerning skills sub-package
    • misty2py.utils.status module removed as it is only used in the skills subpackage
    Source code(tar.gz)
    Source code(zip)
  • v3.0.2(May 19, 2021)

    Added

    • new skills remote_control, explore and face_recognition
    • new utility module status to track the execution status of a script

    Changed

    • renamed misty2py/skills/greeting.py to misty2py/skills/hey_misty.py
    Source code(tar.gz)
    Source code(zip)
  • v3.0.1(May 11, 2021)

  • v3.0.0(May 11, 2021)

    Misty2py now has:

    • new architecture, including sub-packages misty2py.skills and misty2py.utils
    • new skills: greeting and free_memory, both a part of misty2py.skills module
    • updated documentation
    Source code(tar.gz)
    Source code(zip)
  • v2.0.2(May 7, 2021)

    Added

    • skills/template.py - a template for developing a skill with misty2py
    • skills/greeting.py - a skill of Misty reacting to the "Hey Misty" keyphrase
    • skills/free_memory.py - a skill that removes non-system audio, video, image and recording files from Misty's memory
    • misty2py.utils sub-package - various utility functions, some of which were used before in misty2py.utils module

    Changed

    • changed the architecture of the entire package to be easier to understand and use:
      • moved misty2py.utils module to misty2py.utils.utils
      • added a sub-package misty2py.skills
    • updated pytests to match changes in architecture
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(May 4, 2021)

    Added

    • skills folder for example skills
    • skills/battery_printer.py as an example skill involving an event emitter
    • skills/listening_expression.py
    • skills/angry_expression.py

    Changed

    • automatically generated event names now contain the event type

    Fixed

    • construct_transition_dict raised TypeError when attempting to compare str to int; fix: explicitly casting str to int
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(May 4, 2021)

    Added

    • data shortcuts for system images
    • MistyEventHandler class that allows for an event emitter integration
    • event_emitter in MistyEvent and MistyEventHandler

    Changed

    • documentation of data shortcuts in README.md to include added data shortcuts
    • refinement the event-related architecture to be clearer
    • documentation of event-related changes in README.md
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Mar 10, 2021)

    Added

    • Support for custom defined action and information keywords.
    • Support for custom defined data shortcuts.
    • Unit tests to test the added features.
    • Support for all currently available Misty API endpoints for GET, POST and DELETE methods.
    • Event types support.

    Changed

    • Misty.perform_action() now takes one optional argument data instead of three optional arguments dict, string and data_method.
    • Several functions now return keyword "status" instead of "result".
    • README to reflect support for custom definitions and event types.
    • README to include documentation of supported keywords and shortcuts.
    • Renamed tests\test_unit.py to tests\test_base.py to reflect on purposes of the tests.

    Note

    This release was wrongly tagged as it is not downstream compatible and was published without documentation by mistake.

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Feb 21, 2021)

    Added

    • CHANGELOG to track changes.
    • README with basic information.
    • The package misty2py itself supporting:
      • api/led endpoint under the keyword led,
      • api/blink/settings endpoint under the keyword blink_settings,
      • the keyword led_off for a json dictionary with values 0 for red, green and blue.
    Source code(tar.gz)
    Source code(zip)
Freaky fast fuzzy Denite/CtrlP matcher for vim/neovim

Freaky fast fuzzy Denite/CtrlP matcher for vim/neovim This is a matcher plugin for denite.nvim and CtrlP.

Raghu 113 Sep 29, 2022
WebApp Maker make web apps (Duh). It is open source and make with python and shell.

WebApp Maker make web apps (Duh). It is open source and make with python and shell. This app can take any website and turn it into an app. I highly recommend turning these few websites into webapps:

2 Jan 09, 2022
Notion-cli-list-manager - A simple command-line tool for managing Notion databases

A simple command-line tool for managing Notion List databases. ✨

Giacomo Salici 75 Dec 04, 2022
Wappalyzer CLI tool to find Web Technologies

Wappalyzer CLI tool to find Web Technologies

GOKUL A.P 17 Dec 15, 2022
Command-line script to upload videos to Youtube using theYoutube APIv3.

Introduction Command-line script to upload videos to Youtube using theYoutube APIv3. It should work on any platform (GNU/Linux, BSD, OS X, Windows, ..

Arnau Sanchez 1.9k Jan 09, 2023
Albert launcher extension for converting units of length, mass, speed, temperature, time, current, luminosity, printing measurements, molecular substance, and more

unit-converter-albert-ext Extension for converting units of length, mass, speed, temperature, time, current, luminosity, printing measurements, molecu

Jonah Lawrence 2 Jan 13, 2022
Custom 64 bit shellcode encoder that evades detection and removes some common badchars (\x00\x0a\x0d\x20)

x64-shellcode-encoder Custom 64 bit shellcode encoder that evades detection and removes some common badchars (\x00\x0a\x0d\x20) Usage Using a generato

Cole Houston 2 Jan 26, 2022
A CLI application that downloads your AC submissions from OJ's like Atcoder,Codeforces,CodeChef and distil it into beautiful Submission HeatMap.

Yoda A CLI that takes away the hassle of managing your submission files on different online-judges by automating the entire process of collecting and organizing your code submissions in one single Di

Nikhar Manchanda 1 Jul 28, 2022
NudeNet wrapper made to provide a simple cli interface to the library

Nudenet Wrapper. Small warpper script for NudeNet Made to provide a small and easy to use cli interface with the library. You can indicate a single im

1 Oct 20, 2021
Python CLI for accessing CSCI320 PDM Database

p320_14 Python CLI for accessing CSCI320 PDM Database Authors: Aidan Mellin Dan Skigen Jacob Auger Kyle Baptiste Before running the application for th

Aidan Mellin 1 Nov 23, 2021
Hurry is a CLI tool to speed setting up MoniGoMani HyperStrategy & co. #freqtrade #hyperopting #trading #strategy

Hurry is a CLI tool to speed setting up MoniGoMani HyperStrategy & co. #freqtrade #hyperopting #trading #strategy

10 Dec 29, 2022
🎈 `st` is a CLI to quickly kick-off your new Streamlit project

🎈 st - a friendly Streamlit CLI st is a CLI that helps you kick-off a new Streamlit project so you can start crafting the app as soon as possible! Ho

Arnaud 18 Dec 19, 2022
A very simple python script to encode and decode PowerShell one-liners.

PowerShell Encoder A very simple python script to encode and decode PowerShell one-liners. I used Raikia's PowerShell encoder ALOT, but one day it wen

John Tear 5 Jul 29, 2022
Python Command Line Application (CLI) using Typer, SQLModel, Async-PostgrSQL, and FastAPI

pyflycli is a command-line interface application built with Typer that allows you to view flights above your location.

Kevin Zehnder 14 Oct 01, 2022
You'll never want to use cd again.

Jmp Description Have you ever used the cd command? You'll never touch that outdated thing again when you try jmp. Navigate your filesystem with unprec

Grant Holmes 21 Nov 03, 2022
Convert shellcode into :sparkles: different :sparkles: formats!

Bluffy Convert shellcode into ✨ different ✨ formats! Bluffy is a utility which was used in experiments to bypass Anti-Virus products (statically) by f

pre.empt.dev 305 Dec 17, 2022
A simple python script to execute a command when a YubiKey is disconnected

YubiKeyExecute A python script to execute a command when a YubiKey / YubiKeys are disconnected. β€β€β€Ž β€Ž How to use: 1. Download the latest release and d

6 Mar 12, 2022
tiptop is a command-line system monitoring tool in the spirit of top.

Command-line system monitoring. tiptop is a command-line system monitoring tool in the spirit of top. It displays various interesting system stats, gr

Nico SchlΓΆmer 1.3k Jan 08, 2023
A CLI for creating styled-components for React projects quickly

new-component Ian Cleary (iancleary) Description Welcome! This is a CLI for creating styled-components for React projects quickly. Note: I've rewrote

Ian Cleary (he/him/his) 1 Feb 15, 2022
AutoSub is a CLI application to generate subtitle files (.srt, .vtt, and .txt transcript) for any video file using Mozilla DeepSpeech.

AutoSub About Motivation Installation Docker How-to example How it works TO-DO Contributing References About AutoSub is a CLI application to generate

Abhiroop Talasila 414 Jan 06, 2023