Skip to content

Commit eacce0b

Browse files
committed
Restructure the project for PyPi
- Move some files and fix some minor issues - Add setup.py for PyPi - Add README - Add .gitignore - Add unittest test First release - v1.0.0
1 parent 42c5022 commit eacce0b

8 files changed

Lines changed: 184 additions & 28 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
venv
2+
__pycache__
3+
.vscode
4+
dist/
5+
*.py[co]
6+
*.egg-info/
7+
*.egg
8+
build/

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# trionesControl
2+
3+
This module implements the triones protocol reverse engineered by [madhead](https://github.com/madhead) with python, offering a programmatic way to control these kind of lights without needing the app on your phone. To learn more about the protocol, please read the following specification:
4+
5+
* [madhead - saberlight/protocols/Triones/protocol.md](https://github.com/madhead/saberlight/blob/master/protocols/Triones/protocol.md)
6+
7+
## Requirements
8+
9+
This package only works on Linux, it uses pygatt and depends on blueZ.
10+
11+
The package has been tested in python 3 (3.8.5) but it may work on previous versions, even python 2.7, as long as [pygatt requirements](https://github.com/peplin/pygatt#requirements) are met.
12+
13+
## Installation
14+
15+
Install ``trionesControl`` with pip from PyPI:
16+
17+
pip install trionesControl
18+
19+
This will install all the dependencies used by this package and ``pexpect``, an optional ``pygatt`` needed to use it's BlueZ backend.
20+
21+
## Documentation
22+
23+
### Connexion handling
24+
25+
* ``connect(MAC)``: Connect to the device with the mac address specified.
26+
27+
* ``disconnect(device)``: Disconnects from the specified device.
28+
29+
### LED Control
30+
31+
* ``powerOn(device)``: Powers on the device, the LEDs will turn on.
32+
33+
* ``powerOff(device)``: Powers off the device, the LEDs will turn off.
34+
35+
* ``setRGB(r: int, g: int, b: int, device)``: Sets the LED color configuration of the device to the r, g and b colors. (0-255)
36+
37+
* ``setWhite(intensity: int, device)``: Sets the device's LED to white with the specified intensiy. (0-255)
38+
39+
* ``setBuiltIn(mode: int, speed: int, device)``: Activates the selected predefined built-in mode at the selected speed (0-255). The built modes go from 37 to 56.
40+
41+
## Example use
42+
43+
The unittest code available in [tests/test.py](https://github.com/Aritzherrero4/python-trionesControl/blob/master/tests/test.py) can be used as a sample to use the available functions of the package. You can test your bulb / LED strip by using the following code too.
44+
45+
### Connect and power on the device
46+
47+
```python
48+
import time
49+
import trionesControl.trionesControl as tc
50+
51+
#Change the mac address to the one of your bulb or LED strip
52+
device = tc.connect('00:00:00:00:00:00')
53+
tc.powerOn(device)
54+
```
55+
56+
### Change colors
57+
58+
```python
59+
# RGB mode
60+
tc.setRGB(100,100,100, device)
61+
time.sleep(1)
62+
tc.setRGB(255, 255, 255, device)
63+
time.sleep(1)
64+
tc.setRGB(255,0,0, device)
65+
time.sleep(1)
66+
tc.setRGB(0,255,0, device)
67+
68+
#White mode
69+
time.sleep(10)
70+
tc.setWhite(255, device)
71+
```
72+
73+
### Built-in modes
74+
75+
```python
76+
#Change built-in modes (37-56)
77+
time.sleep(10)
78+
tc.setBuiltIn(37, 1)
79+
tc.time(10)
80+
```
81+
82+
### Power off and disconnect
83+
84+
```python
85+
tc.powerOff(device)
86+
tc.disconnect(device)
87+
```
88+
89+
## Licence
90+
91+
MIT Licence - Copyright 2020 Aritz Herrero
92+
93+
For more information, check [LICENCE](https://github.com/Aritzherrero4/python-trionesControl/blob/master/LICENSE) file.

setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name="trionesControl",
8+
version="1.0.0",
9+
author="Aritz Herrero",
10+
description="Simple python package to control smart lights using the Triones porotocol",
11+
long_description=long_description,
12+
long_description_content_type="text/markdown",
13+
url="https://github.com/Aritzherrero4/python-trionesControl",
14+
license="MIT",
15+
packages=setuptools.find_packages(exclude=("tests",)),
16+
classifiers=[
17+
"Intended Audience :: Developers",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: 3.8",
21+
"License :: OSI Approved :: MIT License",
22+
"Operating System :: POSIX :: Linux",
23+
],
24+
install_requires=["pygatt", "pexpect"],
25+
python_requires='>=3.6'
26+
)

test.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
File renamed without changes.

tests/test.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import time
2+
from trionesControl import trionesControl as tc
3+
import logging
4+
import unittest
5+
6+
#Set the MAC address of the lights before executing
7+
device = tc.connect('00:00:00:00:00:00')
8+
chars = device.discover_characteristics()
9+
10+
11+
log = logging.getLogger(__name__)
12+
logging.basicConfig(level=20)
13+
14+
class fullTestCase(unittest.TestCase):
15+
def powerOn(self):
16+
tc.powerOn(device)
17+
18+
def colorChange(self):
19+
tc.setRGB(100,100,100, device)
20+
time.sleep(1)
21+
tc.setRGB(255, 255, 255, device)
22+
time.sleep(1)
23+
tc.setRGB(255,0,0, device)
24+
time.sleep(1)
25+
tc.setRGB(0,255,0, device)
26+
time.sleep(1)
27+
tc.setRGB(0,0,255, device)
28+
time.sleep(1)
29+
tc.setRGB(0,0,255, device)
30+
time.sleep(1)
31+
tc.setRGB(150,0,150, device)
32+
time.sleep(2)
33+
34+
def setWhite(self):
35+
tc.setWhite(255, device)
36+
time.sleep(10)
37+
38+
def builtIn(self):
39+
tc.setBuiltIn(37, 1, device)
40+
time.sleep(10)
41+
42+
def powerOff(self):
43+
time.sleep(10)
44+
tc.powerOff(device)
45+
tc.disconnect(device)
46+
47+
def testLights(self):
48+
self.powerOn()
49+
self.colorChange()
50+
self.setWhite()
51+
self.builtIn()
52+
self.powerOff()
53+
54+
if __name__ == '__main__':
55+
unittest.main()

trionesControl/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def powerOff(device):
3333
log.info("Device powered off")
3434

3535
def setRGB(r: int, g: int, b: int, device):
36-
# Values for color shoud be between 0 and 255
36+
# Values for color should be between 0 and 255
3737
if r > 255: r = 255
3838
if r < 0: r= 0
3939
if g > 255: g = 255
@@ -71,7 +71,7 @@ def setWhite(intensity: int, device):
7171
device.char_write_handle(0x0009, payload)
7272
except pygatt.exceptions.NotConnectedError:
7373
raise pygatt.exceptions.NotConnectedError("Device nor connected!")
74-
log.info("White color set -- Intensiti %d", intensity)
74+
log.info("White color set -- Intensity: %d", intensity)
7575

7676
def setBuiltIn(mode: int, speed: int, device):
7777
if mode<37 | mode > 56:

0 commit comments

Comments
 (0)