async def connect(self) -> bool: """Connect to Lightpack.""" _LOGGER.debug("%s: connect()", self._name) import lightpack try: self._update = lightpack.Lightpack(host=self._host, port=self._port, api_key=self._api_key) self._update.connect() self._control = lightpack.Lightpack(host=self._host, port=self._port, api_key=self._api_key) self._control.connect() self._available = True except self.lightpack.CannotConnectError as e: _LOGGER.error("%s:connect(); result: %s", self._name, repr(e)) _LOGGER.error("Unexpected error: %s", traceback.format_exception(*sys.exc_info())) self._available = False else: api_version = self._update.getApiVersion() if api_version is not None: self._api_version = str(api_version) self._attributes[ATTR_API_VERSION] = self.api_version if StrictVersion(self.api_version) >= StrictVersion('2.2'): self._attributes[ATTR_PERSIST] = False return self.available
def __init__(self): # Configuration host = 'localhost' # (default) port = 3636 # (default) api_key = '{YOUR-API-KEY-IF-USED}' # not used by default led_map = [ # Optional aliases for the LEDs in order 'bottom-right', 'right-bottom', 'right-top', 'top-far-right', 'top-right', 'top-left', 'top-far-left', 'left-top', 'left-bottom', 'bottom-left', ] self.lp = lightpack.Lightpack(host, port, led_map=led_map, api_key=api_key) self.retry_counter = 0 self.retry_limit = 120 self.retry_interval = 5
def __init__(self): self.loadConfig() self.lp = lightpack.Lightpack() self.status = False try: self.lp.connect() except lightpack.CannotConnectError as e: print(repr(e)) sys.exit(1)
exitFlag = 0 lightpack_enabled = False # Configuration # host = '192.168.0.4' # (default) # port = 3636 # (default) # api_key = '{secret-code}' # Default is None # If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time) b.connect() # Connect to the Lightpack API if lightpack_enabled: lp = lightpack.Lightpack() try: lp.connect() except lightpack.CannotConnectError as e: print(repr(e)) sys.exit(1) # Lock the Lightpack so we can make changes lp.lock() else: lp = None ################################ pygame.init() pygame.fastevent.init()
'bottom-right', 'right-bottom', 'right-top', 'top-far-right', 'top-right', 'top-left', 'top-far-left', 'left-top', 'left-bottom', 'bottom-left', ] # api_key = '{secret-code}' # Default is None api_key = '{3b4d4219-5753-460f-a852-54221b44a0d2}' # Connect to the Lightpack API lp = lightpack.Lightpack(led_map=led_map) try: lp.connect() except lightpack.CannotConnectError as e: print repr(e) sys.exit(1) print "connected" # Lock the Lightpack so we can make changes lp.lock() lp.turnOn() sleep(0.1) lp.setSmoothness(100) sleep(0.1)
# port = 3636 # (default) led_map = [ # Optional aliases for the LEDs in order 'bottom-right', 'right-bottom', 'right-top', 'top-far-right', 'top-right', 'top-left', 'top-far-left', 'left-top', 'left-bottom', 'bottom-left', ] api_key = '{e5ecc13c-45f3-4652-a0fb-b03eb07b894e}' lp = lightpack.Lightpack(led_map=led_map, api_key=api_key) try: lp.connect() except lightpack.CannotConnectError as e: print repr(e) sys.exit(1) # Lock the Lightpack so we can make changes lp.lock() for i in range(3): lp.setColourToAll((0, 255, 0)) sleep(0.2) lp.setColourToAll((0, 0, 0)) sleep(0.2)