def main(): # Discover Nuimo Controllers nuimo = NuimoController('CE:D8:42:A7:9A:78') #adapter = 'hci0' # Typical bluetooth adapter name #nuimo_manager = NuimoDiscoveryManager(bluetooth_adapter=adapter, delegate=DiscoveryLogger()) #nuimo_manager.start_discovery() # Were any Nuimos found? #if len(nuimo_manager.nuimos) == 0: # print('No Nuimos detected') # sys.exit(0) # Take the first Nuimo found. #nuimo = nuimo_manager.nuimos[0] # Set up handling of Nuimo events. # In this case just log each incoming event. # NuimoLogger is defined below. nuimo_event_delegate = NuimoLightController() nuimo.set_delegate(nuimo_event_delegate) # Attach to the Nuimo. nuimo.connect() # Display an icon for 2 seconds interval = 2.0 MATRIX_LIGHTBULB = ( " " + " ... " + " . . " + " . . " + " . . " + " ... " + " ... " + " ... " + " . ") nuimo.write_matrix(MATRIX_LIGHTBULB, interval) # Nuimo events are dispatched in the background while (True): time.sleep(1) nuimo.disconnect()
def _attach(self): """Create a nuimo object from mac address or discovery.""" # pylint: disable=import-error from nuimo import NuimoController, NuimoDiscoveryManager if self._nuimo: self._nuimo.disconnect() self._nuimo = None if self._mac: self._nuimo = NuimoController(self._mac) else: nuimo_manager = NuimoDiscoveryManager( bluetooth_adapter=DEFAULT_ADAPTER, delegate=DiscoveryLogger()) nuimo_manager.start_discovery() # Were any Nuimos found? if not nuimo_manager.nuimos: _LOGGER.debug('No Nuimos detected') return # Take the first Nuimo found. self._nuimo = nuimo_manager.nuimos[0] self._mac = self._nuimo.addr