def main():
    """ main function """
    args = parse_args()
    conf = ConfigParser.ConfigParser()
    script_dir = os.path.dirname(os.path.realpath(__file__))
    conf.read(script_dir + '/tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    apiuser = conf.get('tradfri', 'apiuser')
    apikey = conf.get('tradfri', 'apikey')

    if args.action == 'power':
        if args.value == 'on' or args.value == 'off':
            tradfriActions.tradfri_power_group(hubip, apiuser, apikey, args.groupid, args.value)
        else:
            sys.stderr.write('[-] Tradfri: power state can only be on/off\n')
            sys.exit(1)
    elif args.action == 'brightness':
        if 0 <= int(args.value) <= 100:
            tradfriActions.tradfri_dim_group(hubip, apiuser, apikey, args.groupid, args.value)
        else:
            sys.stderr.write('[-] Tradfri: dim value can only be between 1 and 100\n')
            sys.exit(1)
    elif args.action == 'color':
        if args.value in ['warm', 'normal', 'cold']:
            tradfriActions.tradfri_color_group(hubip, apiuser, apikey, args.groupid, args.value)
        else:
            sys.stderr.write('[-] Tradfri: color value can only be warm/normal/cold\n')
            sys.exit(1)
def main():
    """ main function """
    args = parse_args()
    conf = ConfigParser.ConfigParser()
    script_dir = os.path.dirname(os.path.realpath(__file__))
    conf.read(script_dir + '/tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    securityid = conf.get('tradfri', 'securityid')

    if args.action == 'power':
        if args.value == 'on' or args.value == 'off':
            tradfriActions.tradfri_power_group(hubip, securityid, args.groupid,
                                               args.value)
        else:
            sys.stderr.write('[-] Tradfri: power state can only be on/off\n')
            sys.exit(1)
    elif args.action == 'brightness':
        if 0 <= int(args.value) <= 100:
            tradfriActions.tradfri_dim_group(hubip, securityid, args.groupid,
                                             args.value)
        else:
            sys.stderr.write(
                '[-] Tradfri: dim value can only be between 1 and 100\n')
            sys.exit(1)
Beispiel #3
0
def intensity(hubip, apiuser, apikey, bulbid, value):

    if bulbid != 131073:

        tradfriActions.tradfri_dim_light(hubip, apiuser, apikey, bulbid, value)

    else:
        tradfriActions.tradfri_dim_group(hubip, apiuser, apikey, bulbid, value)
def main():
    """ main function """
    args = parse_args()
    conf = ConfigParser.ConfigParser()
    conf.read('tradfri.cfg')

    hubip = conf.get('tradfri', 'hubip')
    securityid = conf.get('tradfri', 'securityid')

    if args.action == 'power':
        if args.value == 'on' or args.value == 'off':
            tradfriActions.tradfri_power_group(hubip, securityid, args.groupid, args.value)
        else:
            sys.stderr.write('[-] tradfri: power state can only be on/off\n')
            sys.exit(1)
    elif args.action == 'brightness':
        if 0 <= int(args.value) <= 100:
            tradfriActions.tradfri_dim_group(hubip, securityid, args.groupid, args.value)
        else:
            sys.stderr.write('[-] tradfri: dim value can only be obetween 1 - 100\n')
            sys.exit(1)
Beispiel #5
0
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    
    topicelem = msg.topic.split("/")
    # Make sure there are at least 4 elements in the topic string
    devaddr = topicelem[2]
    
    print "devaddr is {}".format(devaddr)
    if devaddr == "update_devices":
        read_devices()
        return
    
    cmd = topicelem[3]
    
    group = False
    #print("Devaddr is {}".format(devaddr))
    ep = match_endpoint(groups, devaddr)
    
    # endpoint could be a group or individual device - we treat them differently
    if isinstance(ep, tradfrigroup):
        group = True
    
    if cmd == "brightness":
        print("Set {} - {} brightness to {}".format(ep.name, ep.id, msg.payload))
        #print("Brightness get mutex")
        mutex.acquire()
        if msg.payload.lower() == 'on' or msg.payload.lower() == 'off':
            if group == False:
                tradfriActions.tradfri_power_light(gatewayurl, username, userkey, ep.id, msg.payload.lower())
            else:
                tradfriActions.tradfri_power_group(gatewayurl, username, userkey, ep.id, msg.payload.lower())
        else:
            try:
                if 0 <= int(msg.payload) <= 100:
                    if 0 == int(msg.payload):
                        if group == False:
                            tradfriActions.tradfri_power_light(gatewayurl, username, userkey, ep.id, "off")
                        else:
                            tradfriActions.tradfri_power_group(gatewayurl, username, userkey, ep.id, "off")
                    else:
                        if group == False:
                            tradfriActions.tradfri_dim_light(gatewayurl, username, userkey, ep.id, msg.payload)
                        else:
                            tradfriActions.tradfri_dim_group(gatewayurl, username, userkey, ep.id, msg.payload)
                else:
                    sys.stderr.write('Tradfri: dim value can only be between 0 and 100\n')
            except:
                sys.stderr.write('unable to decode dimmer value {}\n'.format(msg.payload))
                pass
        mutex.release()
        #print("Brightness release mutex")
        #cmdready.set()
    if cmd == "power":
        print("Set {} power {}".format(ep.name, msg.payload))
        #print("Power get mutex")
        mutex.acquire()
        if msg.payload.lower() == 'on' or msg.payload.lower() == 'off':
            if group == False:
                tradfriActions.tradfri_power_light(gatewayurl, username, userkey, ep.id, msg.payload.lower())
            else:
                tradfriActions.tradfri_power_group(gatewayurl, username, userkey, ep.id, msg.payload.lower())
        else:
            sys.stderr.write('Tradfri: power state can only be on/off\n')
        mutex.release()
        #print("Power release mutex")
        #cmdready.set()
    if cmd == "temp":
        # if this is a group id we need to set the temp on individual bulbs as they can't be set as a group
        print("Set {} colour temperature {}% warm".format(ep.name, msg.payload))
        #print("Temp get mutex")
        mutex.acquire()
        try:
            if 0 <= int(msg.payload) <= 100:
                if group == True:
                    for bulb in ep.devices:
                        if bulb.isspectrum == True:
                            tradfriActions.tradfri_color_percent(gatewayurl, username, userkey, bulb.id, msg.payload)
                else:
                    tradfriActions.tradfri_color_percent(gatewayurl, username, userkey, ep.id, msg.payload)
            else:
                sys.stderr.write('Tradfri: colour value can only be between 0 and 100\n')
        except:
            sys.stderr.write('unable to decode colour value {}\n'.format(msg.payload))
        mutex.release()
        #print("Temp release mutex") 
        #cmdready.set()
    if cmd == "poll":
        cmdready.set()