Skip to content

Commit

Permalink
Merge pull request #44 from Betree/staging
Browse files Browse the repository at this point in the history
Release 0.6.0 - Support for time schedules and documentation
  • Loading branch information
Betree authored Jan 21, 2018
2 parents cc9caaa + bbbd339 commit 649bdda
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 60 deletions.
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Developing

- Pull the repo
- (optional) Create a virtual env and activate it
- (optional) Create a virtual env and activate it:

```
virtualenv ./venv
source ./venv/bin/activate
```

- Install glib `sudo apt-get install libglib2.0-dev`
- Install dependencies `pip install bluepy webcolors`
- Install dependencies `pip install -r requirements.txt`
- Run magicblueshell with `sudo ./venv/bin/python3 magicblue/magicblueshell.py`

# Important
Expand Down
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
![MagicBlue Bulb](https://lut.im/xpaCaUNTaU/k6WRbc71KMMSFIln.jpg)

# MagicBlue - Control your Magic Blue bulbs over bluetooth
# MagicBlue - Cheap bluetooth bulbs

[![Documentation Status](https://readthedocs.org/projects/magicblue/badge/?version=latest)](http://magicblue.readthedocs.io/en/latest/?badge=latest)

The Magic Bulb is, as far as I know, the cheapest bluetooth RGB light bulb
on the market : you can get it for as low as ~8€/9$ on sites like
Expand Down Expand Up @@ -56,7 +58,9 @@ installed on your machine.

> sudo pip3 install magicblue
Library needs elevated permissions to use Bluetooth features. You can either run as root (required for magicblueshell), or give `hcitool` special capabilities (see [this link](https://github.com/Betree/magicblue/wiki/Giving-hcitool-capabilities))
Library needs elevated permissions to use Bluetooth features. You can either
run as root (required for magicblueshell), or give `hcitool` special capabilities
(see [this link](https://github.com/Betree/magicblue/wiki/Giving-hcitool-capabilities))

### Known errors

Expand All @@ -74,23 +78,15 @@ installed on your machine.

* Other errors

If you run into problems during devices listing or connect, try to follow this procedure to ensure your Bluetooth interface works correctly : [How to use manually with Gatttool page](https://github.com/Betree/pyMagicBlue/wiki/How-to-use-manually-with-Gatttool)
If you run into problems during devices listing or connect, try to follow
this procedure to ensure your Bluetooth interface works correctly :
[How to use manually with Gatttool page](https://github.com/Betree/pyMagicBlue/wiki/How-to-use-manually-with-Gatttool)

## Usage

### Python API

```python
from magicblue import MagicBlue

bulb_mac_address = 'XX:XX:XX:XX:XX:XX'
bulb = MagicBlue(bulb_mac_address, 9) # Replace 9 by whatever your version is (default: 7)
bulb.connect()
bulb.set_color([255, 0, 0]) # Set red
bulb.set_random_color() # Set random
bulb.turn_off() # Turn off the light
bulb.turn_on() # Set white light
```
Check the [API documentation](http://magicblue.readthedocs.io/en/latest/)

### From shell
Script must be run as root.
Expand Down Expand Up @@ -176,4 +172,5 @@ The protocol isn't fully retro-engineered but
[How to use manually with Gatttool page](https://github.com/Betree/pyMagicBlue/wiki/How-to-use-manually-with-Gatttool)
should give you enough details to start working on your own implementation if you need to port this for another
language / platform.
On the [research/bluetooth branch](https://github.com/Betree/pyMagicBlue/tree/research/bluetooth) you'll also find capture of bluetooth packets exchanged between Android and the bulb (open hci_capture.log with Wireshark).
On the [research/bluetooth branch](https://github.com/Betree/pyMagicBlue/tree/research/bluetooth)
you'll also find capture of bluetooth packets exchanged between Android and the bulb (open hci_capture.log with Wireshark).
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = python3 -msphinx
SPHINXPROJ = MagicBlue
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
170 changes: 170 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# -*- coding: utf-8 -*-

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys
import re


sys.path.insert(0, os.path.abspath('../magicblue'))


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.coverage',
'sphinx.ext.githubpages'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'MagicBlue'
copyright = u'2018, Benjamin Piouffle'
author = u'Benjamin Piouffle'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
release = re.search(
r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
open(os.path.abspath('../magicblue/__init__.py')).read()
).group(1)

# The full X.Y.Z version
version = '.'.join(release.split('.')[:-1])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'navigation_depth': 4
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'MagicBluedoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'MagicBlue.tex', u'MagicBlue Documentation',
u'Benjamin Piouffle', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'magicblue', u'MagicBlue Documentation',
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'MagicBlue', u'MagicBlue Documentation',
author, 'MagicBlue', 'One line description of project.',
'Miscellaneous'),
]



59 changes: 59 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.. MagicBlue documentation master file, created by
sphinx-quickstart on Sun Jan 21 11:34:32 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
MagicBlue
=========

This is the reference for MagicBlue's API. To get information about
how to install it or to use magicblueshell, please refer to this link:
https://github.com/Betree/magicblue/blob/master/README.md

License
-------

The project is licensed under the MIT license.

Contribute
----------

- Issue Tracker: https://github.com/Betree/magicblue/issues
- Source Code: https://github.com/Betree/magicblue

Basic usage
-----------

.. code-block:: python
from magicblue import MagicBlue
bulb_mac_address = 'XX:XX:XX:XX:XX:XX'
bulb = MagicBlue(bulb_mac_address, 9) # Replace 9 by whatever your version is (default: 7)
bulb.connect()
bulb.set_color([255, 0, 0]) # Set red
bulb.set_random_color() # Set random
bulb.turn_off() # Turn off the light
bulb.turn_on() # Set white light
----------------------------------------------------------------------

MagicBlue API reference
=======================

.. automodule:: magicbluelib

MagicBlue
---------

.. autoclass:: MagicBlue
:members:

Effect
------

.. autoclass:: Effect
:members:



2 changes: 1 addition & 1 deletion magicblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Unofficial Python API to control Magic Blue bulbs over Bluetooth
"""

__version__ = "0.5.0"
__version__ = "0.6.0"

try:
from magicblue.magicbluelib import MagicBlue, Effect
Expand Down
Loading

0 comments on commit 649bdda

Please sign in to comment.