w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python Script for Raspberry Pi not running properly

Class TestInput

The function getInput(self): is not returning anything (i.e. the variable authInput is empty).

You probably want to return the created token? return AuthToken("Andrew","1234") that is.

Class BasicAuthenticator

This class checks against self.id and self.secretPassword but they are not set. You are setting id and secretPassword.

Main

Your main functions isn't called either, should be if __name__ == '__main__': with double underlines.

class AuthToken:
    def __init__(self, id, secret):
        self.id=id
        self.secret=secret

class TestDoorController:
    def send_open_pulse(self):
        print "unlock the door"

class BasicAuthenticator:
    def __init__(self):
        self.id = "Andrew"
        self.secretPassword = "1234"

    def check(self,token):
        print "checking input of '" + token.id + "', + password + : " +
token.secret + ", against secret password'" + self.secretPassword +"'"
        result = (token.secret == self.secretPassword) & (token.id ==
self.id)
        print "authentication is: " + str(result)
        return result

class TestInput:
    def getInput(self):
        print "checking for input"
        return AuthToken("Andrew","1234")

class DoorControllerPiFace:
    def send_open_pulse(self):
        piface.digital_write(0,1)
        sleep(5)
        piface.digital_write(0,0)

def main():
    authInput = TestInput()
    authenticator = BasicAuthenticator()
    doorController = DoorControllerPiFace()

    if(authenticator.check(authInput.getInput())):
        doorController.send_open_pulse()

if __name__ == '__main__':
    main()




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.