Skip to content

Commit 5ab7ef9

Browse files
committed
Update to support 1.0.1
1 parent 6c3f7a1 commit 5ab7ef9

19 files changed

+43
-1043
lines changed

README.md

Lines changed: 12 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,33 @@
1-
# AnimatedLEDStrip Client Library for Python
2-
31
[![Build Status](https://travis-ci.com/AnimatedLEDStrip/client-python.svg?branch=master)](https://travis-ci.com/AnimatedLEDStrip/client-python)
42
[![PyPI](https://img.shields.io/pypi/v/animatedledstrip-client.svg)](https://pypi.python.org/pypi/animatedledstrip-client)
53
[![codecov](https://codecov.io/gh/AnimatedLEDStrip/client-python/branch/master/graph/badge.svg)](https://codecov.io/gh/AnimatedLEDStrip/client-python)
64

7-
This library allows a Python 3 client to connect to an AnimatedLEDStrip server, allowing the client to send animations to the server and receive currently running animations from the server, among other information.
5+
# AnimatedLEDStrip Client Library for Python
6+
7+
This library allows a Python 3 client to communicate with an AnimatedLEDStrip server.
88

99
## Adding the Library to a Project
10+
1011
The library is available via pip:
1112

1213
```bash
1314
pip3 install animatedledstrip-client
1415
```
1516

1617
## Creating an `AnimationSender`
17-
An `AnimationSender` is constructed with two arguments:
18-
- `ip_address`: The IP address of the server (as a string)
19-
- `port_num`: The port that the client should connect to (as an integer)
2018

21-
```python
22-
from animatedledstrip import AnimationSender
23-
24-
sender = AnimationSender("10.0.0.254", 5)
25-
```
26-
27-
## Starting an `AnimationSender`
28-
An `AnimationSender` is started by calling the `start()` method on the instance.
19+
An `ALSHttpClient` is created with `ALSHttpClient(ip_address)`.
2920

3021
```python
31-
sender.start()
32-
```
22+
from animatedledstrip import ALSHttpClient
3323

34-
## Stopping the `AnimationSender`
35-
An `AnimationSender` is stopped by calling the `end()` method on the instance.
36-
37-
```python
38-
sender.end()
24+
sender = ALSHttpClient('10.0.0.254')
3925
```
4026

41-
## Sending Data
42-
An animation can be sent to the server by creating an instance of the `AnimationData` class, then calling `send_animation()` with the instance as the argument.
27+
## Communicating with the Server
4328

44-
```python
45-
from animatedledstrip import AnimationData, ColorContainer
46-
47-
color = ColorContainer()
48-
color.add_color(0xFF)
49-
color.add_color(0xFF00)
50-
51-
data = AnimationData()
52-
data.add_color(color)
53-
54-
sender.send_data(data)
55-
```
56-
57-
#### `AnimationData` type notes
58-
The Python library uses the following values for `continuous` and `direction`:
59-
- `continuous`: `None`, `True`, `False`
60-
- `direction`: `Direction.FORWARD`, `Direction.BACKWARD`
61-
62-
## Receiving Data
63-
Received animations are saved to the `running_animations` dict and removed when an `EndAnimation` is received for that animation.
64-
65-
In addition, the Python library uses callbacks that run functions to allow you to specify what to do with data that is received.
66-
67-
### ReceiveCallback
68-
The `receiveCallback` is called whenever the sender receives `bytes` from the server.
69-
The `bytes` are passed to your callback.
70-
Use the `newAnimationDataCallback`, `newAnimationInfoCallback`, `newEndAnimationCallback`, `newSectionCallback` *(Coming soon)* and `newStripInfoCallback` *(Coming soon)* callbacks to handle each type of data.
71-
Runs before `newAnimationDataCallback`, `newAnimationInfoCallback`, `newEndAnimationCallback`, `newSectionCallback` and `newStripInfoCallback`.
72-
73-
```python
74-
def receiveData(data: bytes):
75-
# Your code here
76-
77-
sender.on_receive_callback = receiveData
78-
```
29+
This library follows the conventions laid out for [AnimatedLEDStrip client libraries](https://animatedledstrip.github.io/client-libraries), with the following modifications:
7930

80-
### NewAnimationDataCallback
81-
The `newAnimationDataCallback` is called whenever the sender receives an `AnimationData` instance from the server.
82-
The `AnimationData` instance is passed to your callback.
83-
Runs after the `receiveCallback`.
84-
85-
```python
86-
def processAnimationData(data: 'AnimationData'):
87-
# Your code here
88-
89-
sender.on_new_animation_data_callback = processAnimationData
90-
```
91-
92-
### NewAnimationInfoCallback
93-
The `newAnimationInfoCallback` is called whenever the sender receives an `AnimationInfo` instance from the server.
94-
The `AnimationInfo` instance is passed to your callback.
95-
Runs after the `receiveCallback`.
96-
97-
```python
98-
def handleNewAnimationInfo(info: 'AnimationInfo'):
99-
# Your code here
100-
101-
sender.on_new_animation_info_callback = handleNewAnimationInfo
102-
```
103-
104-
### NewEndAnimationCallback
105-
The `newEndAnimationCallback` is called whenever the sender receives an `EndAnimation` instance from the server.
106-
The `EndAnimation` instance is passed to your callback.
107-
Runs after the `receiveCallback`.
108-
109-
```python
110-
def handleEndAnimation(anim: 'EndAnimation'):
111-
# Your code here
112-
113-
sender.on_new_end_animation_callback = handleEndAnimation
114-
```
115-
116-
### NewSectionCallback *(Coming soon)*
117-
The `newSectionCallback` is called whenever the sender receives a `Section` instance from the server.
118-
The `Section` instance is passed to your callback.
119-
Runs after the `receiveCallback`.
120-
121-
```python
122-
def newSectionHandler(sect: 'Section'):
123-
# Your code here
124-
125-
sender.on_new_section_callback = newSectionHandler
126-
```
127-
128-
### NewStripInfoCallback *(Coming soon)*
129-
The `newStripInfoCallback` is called whenever the sender receives a `StripInfo` instance from the server.
130-
The `StripInfo` instance is passed to your callback.
131-
Runs after the `receiveCallback`.
132-
133-
```python
134-
def processStripInfo(info: 'StripInfo'):
135-
# Your code here
136-
137-
sender.on_new_strip_info_callback = processStripInfo
138-
```
31+
- Function names and class variables are in snake case to follow Python style conventions
32+
- `get_supported_animations_dict` is provided as an alias for `get_supported_animations_map`
33+
- `get_sections_dict` is provided as an alias for `get_sections_map`

animatedledstrip/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
from .als_http_client import ALSHttpClient
12
from .animation_info import AnimationInfo
2-
from .animation_sender import AnimationSender
3-
from .client_params import ClientParams
3+
from .animation_to_run_params import AnimationToRunParams
44
from .color_container import ColorContainer, PreparedColorContainer
5-
from .command import Command
6-
from .current_strip_color import CurrentStripColor
75
from .distance import AbsoluteDistance, PercentDistance
8-
from .end_animation import EndAnimation
96
from .equation import Equation
107
from .location import Location
11-
from .message import Message
8+
from .rotation import DegreesRotation, RadiansRotation
129
from .running_animation_params import RunningAnimationParams
1310
from .section import Section
1411
from .strip_info import StripInfo

animatedledstrip/als_http_client.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@
1717
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
# THE SOFTWARE.
20+
2021
import json
2122
from urllib.request import Request, urlopen
22-
from typing import TYPE_CHECKING, List, Dict, Any
23+
from typing import Any, Dict, List, TYPE_CHECKING
2324

24-
from animatedledstrip import RunningAnimationParams, Section, StripInfo
25-
from animatedledstrip.animation_to_run_params import AnimationToRunParams
2625
from animatedledstrip.json_decoder import ALSJsonDecoder
2726
from animatedledstrip.json_encoder import ALSJsonEncoder
2827

2928
if TYPE_CHECKING:
3029
from animatedledstrip.animation_info import AnimationInfo
31-
from animatedledstrip.current_strip_color import CurrentStripColor
30+
from animatedledstrip.animation_to_run_params import AnimationToRunParams
31+
from animatedledstrip.running_animation_params import RunningAnimationParams
32+
from animatedledstrip.section import Section
33+
from animatedledstrip.strip_info import StripInfo
3234

3335

3436
class ALSHttpClient:
@@ -54,9 +56,9 @@ def _delete_data(self, url: str) -> Any:
5456
return urlopen(Request(self._resolve_url(url), method='DELETE')).read()
5557

5658
def get_animation_info(self, anim_name: str) -> 'AnimationInfo':
57-
return self.decoder.decode_with_type(self._get_data('/animation/' + anim_name), 'AnimationInfo')
59+
return self.decoder.decode_object_with_type(self._get_data('/animation/' + anim_name), 'AnimationInfo')
5860

59-
def get_supported_animation_names(self) -> List[str]:
61+
def get_supported_animations_names(self) -> List[str]:
6062
return json.loads(self._get_data('/animations/names'))
6163

6264
def get_supported_animations(self) -> List['AnimationInfo']:
@@ -75,10 +77,10 @@ def get_running_animations_ids(self) -> List[str]:
7577
return json.loads(self._get_data('/running/ids'))
7678

7779
def get_running_animation_params(self, anim_id: str) -> 'RunningAnimationParams':
78-
return self.decoder.decode_with_type(self._get_data('/running/' + anim_id), 'RunningAnimationParams')
80+
return self.decoder.decode_object_with_type(self._get_data('/running/' + anim_id), 'RunningAnimationParams')
7981

8082
def end_animation(self, anim_id: str) -> 'RunningAnimationParams':
81-
return self.decoder.decode_with_type(self._delete_data('/running/' + anim_id), 'RunningAnimationParams')
83+
return self.decoder.decode_object_with_type(self._delete_data('/running/' + anim_id), 'RunningAnimationParams')
8284

8385
def end_animation_from_params(self, anim_params: 'RunningAnimationParams') -> 'RunningAnimationParams':
8486
return self.end_animation(anim_params.anim_id)
@@ -92,23 +94,23 @@ def get_sections_map(self) -> Dict[str, 'Section']:
9294
def get_sections_dict(self) -> Dict[str, 'Section']:
9395
return self.get_sections_map()
9496

95-
def get_section(self, section_id: str) -> 'Section':
96-
return self.decoder.decode_with_type(self._get_data('/sections/' + section_id), 'Section')
97+
def get_section(self, section_name: str) -> 'Section':
98+
return self.decoder.decode_object_with_type(self._get_data('/sections/' + section_name), 'Section')
9799

98100
def get_full_strip_section(self) -> 'Section':
99101
return self.get_section('fullStrip')
100102

101103
def create_new_section(self, new_section: 'Section') -> 'Section':
102-
return self.decoder.decode_with_type(self._post_data('/sections', new_section), 'Section')
104+
return self.decoder.decode_object_with_type(self._post_data('/sections', new_section), 'Section')
103105

104106
def start_animation(self, anim_params: 'AnimationToRunParams') -> 'RunningAnimationParams':
105-
return self.decoder.decode_with_type(self._post_data('/start', anim_params), 'RunningAnimationParams')
107+
return self.decoder.decode_object_with_type(self._post_data('/start', anim_params), 'RunningAnimationParams')
106108

107109
def get_strip_info(self) -> 'StripInfo':
108-
return self.decoder.decode_with_type(self._get_data('/strip/info'), 'StripInfo')
110+
return self.decoder.decode_object_with_type(self._get_data('/strip/info'), 'StripInfo')
109111

110-
def get_current_strip_color(self) -> 'CurrentStripColor':
111-
return self.decoder.decode_with_type(self._get_data('/strip/color'), 'CurrentStripColor')
112+
def get_current_strip_color(self) -> List[int]:
113+
return json.loads(self._get_data('/strip/color'))
112114

113115
def clear_strip(self):
114116
# TODO: Fix 404

0 commit comments

Comments
 (0)