Ejemplo n.º 1
0
    def decora(self, switch_name, command, brightness):
        logging.debug('switch:' + switch_name + ' command:' + str(command) +
                      ' brightness: ' + brightness)
        username = Home.private.get('Decora', 'username')
        password = Home.private.get('Decora', 'password')

        session = DecoraWiFiSession()
        session.login(username, password)

        perms = session.user.get_residential_permissions()
        all_residences = []
        for permission in perms:
            if permission.residentialAccountId is not None:
                acct = ResidentialAccount(session,
                                          permission.residentialAccountId)
                for res in acct.get_residences():
                    all_residences.append(res)
            elif permission.residenceId is not None:
                res = Residence(session, permission.residenceId)
                all_residences.append(res)
        for residence in all_residences:
            for switch in residence.get_iot_switches():
                attribs = {}
                if switch.name == switch_name:
                    if brightness is not "None":
                        attribs['brightness'] = brightness
                    if command == 'ON':
                        attribs['power'] = 'ON'
                    else:
                        attribs['power'] = 'OFF'
                    logging.debug(switch.name + ':' + str(attribs))
                switch.update_attributes(attribs)

        Person.logout(session)
Ejemplo n.º 2
0
 def logout(event):
     """Log out..."""
     try:
         if session is not None:
             Person.logout(session)
     except ValueError:
         _LOGGER.error('Failed to log out of myLeviton Service.')
Ejemplo n.º 3
0
 def logout(event):
     """Log out..."""
     try:
         if session is not None:
             Person.logout(session)
     except ValueError:
         _LOGGER.error("Failed to log out of myLeviton Service.")
else:
    decora_bright = None

session = DecoraWiFiSession()
session.login(decora_email, decora_pass)

# Gather all the available devices...

perms = session.user.get_residential_permissions()
all_residences = []
for permission in perms:
    if permission.residentialAccountId is not None:
        acct = ResidentialAccount(session, permission.residentialAccountId)
        for res in acct.get_residences():
            all_residences.append(res)
    elif permission.residenceId is not None:
        res = Residence(session, permission.residenceId)
        all_residences.append(res)
all_switches = []
for residence in all_residences:
    attribs = {}
    if decora_bright is not None:
        attribs['brightness'] = decora_bright
    if decora_cmd == 'ON':
        attribs['power'] = 'ON'
    else:
        attribs['power'] = 'OFF'
    residence.update_by_id_iot_switches(decora_switch_id, attribs)

Person.logout(session)