Пример #1
0
 def handle_nano_leaf_on_intent(self, message):
     silent_kw = message.data.get("SilentKeyword")
     MyPanels = Aurora(self.IPstring, self.tokenString)
     MyPanels.on = True
     MyPanels.brightness = 100
     if not silent_kw:
         self.speak_dialog("light.on")
def HyperLeaf(my_panels):
    PanelIDs = my_panels[1:-1]
    lower_panel = my_panels[0]
    upper_panel = my_panels[len(my_panels) - 1]
    first_panel = PanelIDs[0]
    last_panel = PanelIDs[len(PanelIDs) - 1]
    print(my_panels)
    print(lower_panel)
    print(first_panel)
    print(upper_panel)
    print(last_panel)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
    sock.bind((UDP_IP, UDP_PORT))
    my_aurora = Aurora(IPstring,
                       tokenString)  # IP address and key for nanoleaf Aurora
    my_aurora.on = True  #Turn nanoleaf on
    my_aurora.brightness = 50  #set brightness
    sleep(1)
    strm = my_aurora.effect_stream(
    )  #set nanoleaf to streaming mode, this only works with bharat's fork of nanoleaf
    LOG.info(strm.addr)
    while True:
        data = sock.recvfrom(
            21
        )  # hyperion sends 3 bytes (R,G,B) for each configured light (3*7=21)
        now = datetime.datetime.now()  # retrieve time for debuging
        new = bytearray(data[0])  # retrieve hyperion byte array
        RGBList = list(new)  # great R-G-B list
        # print(RGBList)  # for debuging only
        PanelCount = 0  # initial condition
        for Panel in PanelIDs:  # itterate through the configured PanleID's above
            firstByteIndex = PanelCount * 3  # Red Index
            secondByteIndex = firstByteIndex + 1  # Green Index
            thirdByteIndex = secondByteIndex + 1  # Blue Index
            intPanelID = PanelIDs[
                PanelCount]  # This Panel ID ***could this not just be "Panel"
            intRedValue = RGBList[firstByteIndex]
            intGreenValue = RGBList[secondByteIndex]
            intBlueValue = RGBList[thirdByteIndex]
            # print(str(intPanelID) + " " + str(intRedValue) + " " + str(intGreenValue) + " " + str(intBlueValue))

            if intPanelID == lower_panel or intPanelID == first_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                strm.panel_set(lower_panel, intRedValue, intGreenValue,
                               intBlueValue)
                strm.panel_set(first_panel, intRedValue, intGreenValue,
                               intBlueValue)
            else:
                if intPanelID == upper_panel or intPanelID == last_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                    strm.panel_set(upper_panel, intRedValue, intGreenValue,
                                   intBlueValue)
                    strm.panel_set(last_panel, intRedValue, intGreenValue,
                                   intBlueValue)
                else:
                    strm.panel_set(intPanelID, intRedValue, intGreenValue,
                                   intBlueValue)  # set the current panel color
            PanelCount += 1  # next panel
 def show_temperature(self, temp):
     my_aurora = Aurora(self.IP, self.AUTH_TOKEN)
     red = Color("blue")
     colors = list(red.range_to(Color("red"), 50))
     color = colors[int(temp) + 10]
     hex = color.get_hex_l()[1:]
     my_aurora.rgb = hex
     my_aurora.brightness = 40
     sleep(2)
     my_aurora.on = False
Пример #4
0
 def handle_nano_leaf_set_intent(self, message):
     silent_kw = message.data.get("SilentKeyword")
     str_remainder = str(message.utterance_remainder()).lower()
     message_words = []
     scene_words = []
     scene_match = False
     message_words = str_remainder.split()
     for each_scene in self.retrieve_scenes():
         scene_words = re.findall(r"\w+", str(each_scene).lower())
         LOGGER.info('List Compare: ' + str(message_words) + ' : ' +
                     str(each_scene))
         scene_match = bool(set(message_words).intersection(scene_words))
         if scene_match:
             self.set_scene(each_scene)
             LOG.info('Scene Found!')
             if not silent_kw:
                 self.speak_dialog(
                     "light.set",
                     data={"result": str(each_scene) + ", scene"})
             break
     if not scene_match:
         LOG.info('Scene not Found!')
         for findcolor in Valid_Color:
             mypos = str_remainder.find(findcolor)
             if mypos > 0:
                 if findcolor == 'read':
                     findcolor = 'red'
                 if findcolor == 'toronto':
                     myRed = 0
                     myGreen = 62
                     myBlue = 126
                 else:
                     myRed = math.trunc(Color(findcolor).get_red() * 255)
                     myGreen = math.trunc(
                         Color(findcolor).get_green() * 255)
                     myBlue = math.trunc(Color(findcolor).get_blue() * 255)
                 myHex = Color(findcolor).hex_l
                 if not silent_kw:
                     self.speak_dialog("light.set",
                                       data={"result": findcolor})
                 MyPanels = Aurora(self.IPstring, self.tokenString)
                 MyPanels.rgb = myHex[1:]
                 break
     dim_level = re.findall('\d+', str_remainder)
     if dim_level:
         MyPanels = Aurora(self.IPstring, self.tokenString)
         MyPanels.brightness = int(dim_level[0])
         if not silent_kw:
             self.speak_dialog(
                 "light.set",
                 data={"result": str(dim_level[0]) + ", percent"})
Пример #5
0
 def handle_nano_leaf_dim_intent(self, message):
     silent_kw = message.data.get("SilentKeyword")
     MyPanels = Aurora(self.IPstring, self.tokenString)
     MyPanels.brightness = 5
     self.speak_dialog("light.dim")
Пример #6
0
 def do_cinema_mode(self, my_id, terminate):
     addr = self.get_ifaces()
     if len(addr) == 0:
         LOG.info("no UDP network connection detected")
     elif len(addr) == 1:
         iface, my_ip = addr.popitem()
         LOG.info("UDP network connection found")
         self.UDP_IP = my_ip
     LOG.info("Starting Nanoleaf Cinema Mode: " + str(my_id))
     all_panels = self.get_panels()
     panel_ids = all_panels[1:-1]
     lower_panel = all_panels[0]
     upper_panel = all_panels[len(all_panels) - 1]
     first_panel = panel_ids[0]
     last_panel = panel_ids[len(panel_ids) - 1]
     try:
         LOG.info('Attempting to open the socket connection')
         sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
         sock.bind((self.UDP_IP, self.UDP_PORT))
         sock.settimeout(5)
         socket_open = True
     except Exception as e:
         LOG.error(e)
         LOG.info('Socket Connection Failed')
         socket_open = False
     LOG.info('Connecting to Aurora at: ' + self.IPstring + " : " +
              self.tokenString)
     my_aurora = Aurora(
         self.IPstring,
         self.tokenString)  # IP address and key for nanoleaf Aurora
     my_aurora.on = True  # Turn nanoleaf on
     my_aurora.brightness = 50  # set brightness
     sleep(1)
     LOG.info('Attempting to switch to cinema mode')
     try:
         strm = my_aurora.effect_stream()  # set nanoleaf to streaming mode
         LOG.info('Aurora Successfully switched to cinema mode')
         LOG.info('waiting for udp data')
         while True:
             if not socket_open:
                 break
             try:
                 raw_data = sock.recvfrom(
                     21
                 )  # hyperion sends 3 bytes (R,G,B) for each configured light (3*7=21)
                 byte_data = bytearray(
                     raw_data[0])  # retrieve hyperion byte array
                 rgb_list = list(byte_data)  # great R-G-B list
                 # LOG.info(rgb_list)  # for debuging only
                 panel_count = 0  # initial condition
                 for each_panel in panel_ids:  # itterate through the configured PanleID's above
                     # Todo - Determine if I can use Panel instead of PanelID's
                     # Todo - If we can use Panel then the PanelCount should not be required
                     # LOG.info('Panel: ' + str(each_panel) + " - Panel ID:" + str(panel_ids[panel_count]))
                     first_byte_index = panel_count * 3  # Red Index
                     second_byte_index = first_byte_index + 1  # Green Index
                     third_byte_index = second_byte_index + 1  # Blue Index
                     int_panel_id = panel_ids[
                         panel_count]  # This Panel ID ***could this not just be "Panel"
                     # int_panel_id = each_panel
                     int_red_value = rgb_list[first_byte_index]
                     int_green_value = rgb_list[second_byte_index]
                     int_blue_value = rgb_list[third_byte_index]
                     if int_panel_id == lower_panel or int_panel_id == first_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                         strm.panel_set(lower_panel, int_red_value,
                                        int_green_value, int_blue_value)
                         strm.panel_set(first_panel, int_red_value,
                                        int_green_value, int_blue_value)
                     else:
                         if int_panel_id == upper_panel or int_panel_id == last_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                             strm.panel_set(upper_panel, int_red_value,
                                            int_green_value, int_blue_value)
                             strm.panel_set(last_panel, int_red_value,
                                            int_green_value, int_blue_value)
                         else:
                             strm.panel_set(int_panel_id, int_red_value,
                                            int_green_value, int_blue_value
                                            )  # set the current panel color
                     panel_count += 1  # next panel
             except Exception as e:
                 LOG.error(e)
                 LOG.info('Socket Timeout Error - No Data Received')
                 break
             if terminate():
                 LOG.info('Stop Signal Received')
                 break
     except Exception as e:
         LOG.error(e)
         LOG.info('Aurora Failed to launch cinema mode')
     my_aurora.on = False  # Turn nanoleaf off
     try:
         sock.close()
         LOG.info('Socket Closed')
     except Exception as e:
         LOG.error(e)
         LOG.info('Socket Closure Failed!')
     LOG.info("Nanoleaf Cinema Mode Ended: " + str(my_id))
Пример #7
0
import json

try:
    # Argument parsing
    parser = argparse.ArgumentParser("Aurora Controller")
    parser.add_argument("--effect")
    parser.add_argument("--brightness", type=int)
    parser.add_argument("--identify", action="store_true")
    parser.add_argument("--info", action="store_true")
    args = parser.parse_args()
    logger.info(args)

    # Connect to Aurora
    aurora = Aurora(IP_ADDRESS, AUTH_TOKEN)

    if args.brightness is not None:
        aurora.brightness = args.brightness
    if args.effect:
        if args.effect == "random":
            aurora.effect_random()
        else:
            aurora.effect = args.effect
    if args.identify:
        aurora.identify()
    if args.info:
        print(json.dumps(aurora.info, sort_keys=True, indent=4))

# Error handling
except Exception as e:
    logger.exception(e)