Skip to content
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

fix led state is not boolean #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions pylutron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,19 +926,27 @@ class Led(KeypadComponent):
handle events for (led toggled by scenes)."""
_ACTION_LED_STATE = 9

class State(Enum):
"""Possible states of an OccupancyGroup."""
OFF = 0
ON = 1
NORMAL_FLASH = 2
RAPID_FLASH = 3

class Event(LutronEvent):
"""Led events that can be generated.

STATE_CHANGED: The button has been pressed.
Params:
state: The boolean value of the new LED state.
state: The value of the new LED state.
0= off, 1= on, 2= 1 flash/sec, 3= 10 flash/sec
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add class enums for OFF, ON, FLASH_SLOW, FLASH_FAST

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

"""
STATE_CHANGED = 1

def __init__(self, lutron, keypad, name, led_num, component_num, uuid):
"""Initializes the Keypad LED class."""
super(Led, self).__init__(lutron, keypad, name, led_num, component_num, uuid)
self._state = False
self._state = None
self._query_waiters = _RequestHelper()

def __str__(self):
Expand Down Expand Up @@ -969,10 +977,10 @@ def state(self):
return self._state

@state.setter
def state(self, new_state: bool):
def state(self, new_state: int):
"""Sets the new led state.

new_state: bool
new_state
"""
self._lutron.send(Lutron.OP_EXECUTE, Keypad._CMD_TYPE, self._keypad.id,
self.component_number, Led._ACTION_LED_STATE,
Expand All @@ -991,7 +999,7 @@ def handle_update(self, action, params):
_LOGGER.debug("Unknown params %s (action %d on led %d in keypad %s)" % (
params, action, self.number, self._keypad.name))
return False
self._state = bool(params[0])
self._state = Led.State(int(params[0]))
self._query_waiters.notify()
self._dispatch_event(Led.Event.STATE_CHANGED, {'state': self._state})
return True
Expand Down