Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 296903c

Browse files
committed
Out with setup, in with poetry
Migrated the package from setuptools to using pypackage and poetry. Also moved all (most) of the scripts from the contrib directory into blynclight/scripts package and gave them all click interfaces. Added the magic to pypackage to enable installing the scripts as commands. Which is nice.
1 parent 9290822 commit 296903c

File tree

19 files changed

+434
-246
lines changed

19 files changed

+434
-246
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v2.2.1
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://github.com/ambv/black
12+
rev: stable
13+
hooks:
14+
- id: black

VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@
3535

3636
from .constants import FlashSpeed, MusicSelections, MusicVolume
3737

38-
from .exceptions import (
39-
BlyncLightNotFound,
40-
BlyncLightUnknownDevice,
41-
BlyncLightInUse,
42-
)
38+
from .exceptions import BlyncLightNotFound, BlyncLightUnknownDevice, BlyncLightInUse
4339

4440
from .proxy import Proxy as BlyncLightProxy
4541

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33
from ctypes import Structure, c_uint64
44
from contextlib import contextmanager
55
from .hid import HidDevice
6-
from .constants import (
7-
EMBRAVA_VENDOR_IDS,
8-
END_OF_COMMAND,
9-
COMMAND_LENGTH,
10-
PAD_VALUE,
11-
)
12-
from .exceptions import (
13-
BlyncLightNotFound,
14-
BlyncLightUnknownDevice,
15-
BlyncLightInUse,
16-
)
6+
from .constants import EMBRAVA_VENDOR_IDS, END_OF_COMMAND, COMMAND_LENGTH, PAD_VALUE
7+
from .exceptions import BlyncLightNotFound, BlyncLightUnknownDevice, BlyncLightInUse
178

189

1910
class BlyncLight(Structure):
@@ -52,10 +43,10 @@ class method get_light().
5243
5344
Additionally, any updates to the bit fields in the ByncLight class
5445
will be immediately written to the hardware device by default.
55-
46+
5647
Finally, when a BlyncLight object is deallocated it will attempt
5748
to return the light to a known quiescent state before releasing
58-
the device.
49+
the device.
5950
6051
Callers can defer hardware updates by setting the 'immediate'
6152
attribute to False. Any changes to command fields will not be
@@ -103,10 +94,10 @@ class method get_light().
10394
green : 8 Green component varies between 0-255
10495
off : 1 0==on 1==off
10596
dim : 1 0==bright 1==dim
106-
flash : 1 0==steady 1==flash
97+
flash : 1 0==steady 1==flash
10798
speed : 3 0==off 1==low 2==medium 4==fast
10899
pad : 2
109-
mute : 1 0==unmute 1==mute
100+
mute : 1 0==unmute 1==mute
110101
music : 4 select a built-in musical tune
111102
play : 1 0==stop 1==play
112103
repeat : 1 0==no repeat 1==repeat
@@ -235,23 +226,21 @@ def __init__(self, vendor_id, product_id, immediate=True):
235226
236227
If immediate is False, the caller will need to set immediate
237228
to True before updates to the device will occur.
238-
229+
239230
The following exceptions are raised:
240231
241232
- BlyncLightUnknownDevice is raised if vendor_id does not
242233
match known Embrava vendor indentifiers.
243-
234+
244235
- BlyncLightInUse is raised if the light specified by
245236
vendor_id:product_id has already been opened.
246-
237+
247238
- BlyncLightNotFound is raised if the light specified by
248239
vendor_id:product_id does not exist.
249240
250241
"""
251242
if vendor_id not in EMBRAVA_VENDOR_IDS:
252-
raise BlyncLightUnknownDevice(
253-
f"unknown vendor id 0x{vendor_id:04}"
254-
)
243+
raise BlyncLightUnknownDevice(f"unknown vendor id 0x{vendor_id:04}")
255244
self.vendor_id = vendor_id
256245
self.product_id = product_id
257246
self.reset(flush=False)
@@ -325,9 +314,7 @@ def __setattr__(self, name, value):
325314
if name in self.commands and self.immediate:
326315
n = self.device.write(self.bytes)
327316
if n != len(self.bytes):
328-
raise IOError(
329-
f"wrote {n} bytes, expected {len(self.bytes)} bytes"
330-
)
317+
raise IOError(f"wrote {n} bytes, expected {len(self.bytes)} bytes")
331318

332319
@property
333320
def device(self):
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ class _DeviceHandle(ctypes.Structure):
8888
pass
8989

9090

91-
_hidapi_libraries = [
92-
"hidapi",
93-
"hidapi-hidraw",
94-
"hidapi-libusb",
95-
"hidapi-iohidmanager",
96-
]
91+
_hidapi_libraries = ["hidapi", "hidapi-hidraw", "hidapi-libusb", "hidapi-iohidmanager"]
9792

9893
for stem in _hidapi_libraries:
9994
fullname = ctypes.util.find_library(stem)
@@ -104,11 +99,7 @@ class _DeviceHandle(ctypes.Structure):
10499
raise ImportError("failed to locate hidapi shared object")
105100

106101
_function_signatures = [
107-
(
108-
"hid_enumerate",
109-
[ctypes.c_ushort, ctypes.c_ushort],
110-
ctypes.POINTER(_DeviceInfo),
111-
),
102+
("hid_enumerate", [ctypes.c_ushort, ctypes.c_ushort], ctypes.POINTER(_DeviceInfo)),
112103
("hid_free_enumeration", [ctypes.POINTER(_DeviceInfo)], None),
113104
(
114105
"hid_open",
@@ -119,20 +110,12 @@ class _DeviceHandle(ctypes.Structure):
119110
("hid_close", [ctypes.POINTER(_DeviceHandle)], None),
120111
(
121112
"hid_write",
122-
[
123-
ctypes.POINTER(_DeviceHandle),
124-
ctypes.POINTER(ctypes.c_byte),
125-
ctypes.c_size_t,
126-
],
113+
[ctypes.POINTER(_DeviceHandle), ctypes.POINTER(ctypes.c_byte), ctypes.c_size_t],
127114
ctypes.c_int,
128115
),
129116
(
130117
"hid_read",
131-
[
132-
ctypes.POINTER(_DeviceHandle),
133-
ctypes.POINTER(ctypes.c_byte),
134-
ctypes.c_size_t,
135-
],
118+
[ctypes.POINTER(_DeviceHandle), ctypes.POINTER(ctypes.c_byte), ctypes.c_size_t],
136119
ctypes.c_int,
137120
),
138121
(
@@ -158,7 +141,7 @@ class _DeviceHandle(ctypes.Structure):
158141

159142
class HidDevice:
160143
"""A USB Human Input Device (HID) Device
161-
144+
162145
Provides read and write access to devices that adhere to the USB
163146
HID protocol. The HidDevice.enumerate class method can be used to
164147
discover currently attached devices.
@@ -256,9 +239,7 @@ def handle(self):
256239
return self._handle
257240
except AttributeError:
258241
pass
259-
self._handle = hidapi.hid_open(
260-
self.vendor_id, self.product_id, self.path
261-
)
242+
self._handle = hidapi.hid_open(self.vendor_id, self.product_id, self.path)
262243
if not self._handle:
263244
raise LookupError(f"no such device: {self.identifier}")
264245
self._opened.add(self.identifier)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def color(self, light_id, value):
6262
:param value: color specifier ( tuple of ints or int )
6363
6464
Changes the color of the light associated with light_id.
65-
65+
6666
"""
6767
if isinstance(value, tuple):
6868
# convert tuple to string

blynclight/scripts/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,17 @@
1616
@click.option("--flash/--no-flash", default=False)
1717
@click.option("-s", "--speed", default=0, help="0, 1, 2, 4")
1818
@click.option(
19-
"-v",
20-
"--verbose",
21-
is_flag=True,
22-
default=False,
23-
help="Prints the light status.",
19+
"-v", "--verbose", is_flag=True, default=False, help="Prints the light status."
2420
)
2521
@click.option("-d", "--duration", default=-1)
2622
@click.option(
27-
"-a",
28-
"--available",
29-
is_flag=True,
30-
default=False,
31-
help="Show available lights.",
23+
"-a", "--available", is_flag=True, default=False, help="Show available lights."
3224
)
3325
def cli(
34-
light_id,
35-
red,
36-
blue,
37-
green,
38-
off,
39-
bright,
40-
flash,
41-
speed,
42-
verbose,
43-
duration,
44-
available,
26+
light_id, red, blue, green, off, bright, flash, speed, verbose, duration, available
4527
):
4628
"""Initialize the state of a connected BlyncLight and
47-
activate the light for 'duration' seconds.
29+
activate the light for 'duration' seconds.
4830
"""
4931

5032
if available:

0 commit comments

Comments
 (0)