|
| 1 | +import growattServer |
| 2 | +import getpass |
| 3 | + |
| 4 | +""" |
| 5 | +This is a simple script that demonstrates the various ways to initialise the library to set a User Agent |
| 6 | +""" |
| 7 | + |
| 8 | +#Prompt user for username |
| 9 | +username=input("Enter username:") |
| 10 | + |
| 11 | +#Prompt user to input password |
| 12 | +user_pass=getpass.getpass("Enter password:") |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +api = growattServer.GrowattApi() |
| 17 | +login_response = api.login(username, user_pass) |
| 18 | +print("Default initialisation") |
| 19 | +print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) |
| 20 | +print("") |
| 21 | + |
| 22 | +api = growattServer.GrowattApi(True) |
| 23 | +login_response = api.login(username, user_pass) |
| 24 | +print("Add random ID to default User-Agent") |
| 25 | +print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) |
| 26 | +print("") |
| 27 | + |
| 28 | +api = growattServer.GrowattApi(False, "my-user-id") |
| 29 | +login_response = api.login(username, user_pass) |
| 30 | +print("Override default User-Agent") |
| 31 | +print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) |
| 32 | +print("") |
| 33 | + |
| 34 | +api = growattServer.GrowattApi(True, "my-user-id") |
| 35 | +login_response = api.login(username, user_pass) |
| 36 | +print("Override default User-Agent and add random ID") |
| 37 | +print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) |
| 38 | +print("") |
| 39 | + |
| 40 | +api = growattServer.GrowattApi(False, growattServer.GrowattApi.agent_identifier + " - my-user-id") |
| 41 | +login_response = api.login(username, user_pass) |
| 42 | +print("Extend default User-Agent") |
| 43 | +print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) |
| 44 | +print("") |
| 45 | + |
| 46 | +api = growattServer.GrowattApi(True, growattServer.GrowattApi.agent_identifier + " - my-user-id") |
| 47 | +login_response = api.login(username, user_pass) |
| 48 | +print("Extend default User-Agent and add random ID") |
| 49 | +print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) |
| 50 | +print("") |
| 51 | + |
0 commit comments