Skip to content

started typing for three requested functions: init, getitem, setitem #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions adafruit_ble_magic_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

"""

try:
from typing import Optional
except ImportError:
pass

from adafruit_ble.services import Service
from adafruit_ble.uuid import VendorUUID
from adafruit_ble.characteristics import Characteristic
Expand All @@ -28,20 +33,20 @@ class MagicLightService(Service):
uuid=VendorUUID("0000ffe9-0000-1000-8000-00805f9b34fb"), max_length=7
)

def __init__(self, service=None):
def __init__(self, service: Optional["MagicLightService"] = None) -> None:
super().__init__(service=service)
self._color = 0xFFFFFF
self._buf = bytearray(7)
self._buf[0] = 0x56
self._buf[6] = 0xAA
self._brightness = 1.0

def __getitem__(self, index):
def __getitem__(self, index: int) -> int:
if index > 0:
raise IndexError()
return self._color

def __setitem__(self, index, value):
def __setitem__(self, index: int, value: int) -> None:
if index > 0:
raise IndexError()
if isinstance(value, int):
Expand Down