Skip to content

Commit

Permalink
allow setting USER_AGENT
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Dec 7, 2015
1 parent 4d0cf1d commit 2819a56
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions wattsup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def setNetworkBasic (self, ip_addr, gateway, dns1, dns2, net_mask, dhcp):
self.s.write(commands['write_network'].encode('ascii'))
self.s.readline()

def setNetworkExtended (self, url, port, pfile, interval=1):
def setNetworkExtended (self, url, port, pfile, uagent, interval=1):
if len(url) > 40:
print("POST URL too long. Must be 40 characters or less.")
sys.exit(1)
Expand All @@ -149,7 +149,7 @@ def setNetworkExtended (self, url, port, pfile, interval=1):
sys.exit(1)

cmd = commands['set_network_ext'].format(url, port, pfile,
USER_AGENT, int(interval)).encode('ascii')
uagent, int(interval)).encode('ascii')
self.s.write(cmd)
self.s.readline()
self.s.write(commands['write_network'].encode('ascii'))
Expand Down Expand Up @@ -264,6 +264,10 @@ def reset (self):
nargs=3,
help='Configure POST settings. <POST URL> <POST port> \
<POST file>')
parser.add_argument('-u', '--user-agent',
dest='useragent',
help='Set a custom User Agent. Only has effect if -n \
is also used.')
parser.add_argument('--dhcp',
dest='dhcp',
action='store_true',
Expand Down Expand Up @@ -321,12 +325,15 @@ def reset (self):
url = args.network[0][0]
port = args.network[0][1]
pfile = args.network[0][2]
uagent = USER_AGENT
if args.useragent:
uagent = args.useragent

interval = 1
if args.interval:
interval = int(args.interval)

meter.setNetworkExtended(url, port, pfile, interval)
meter.setNetworkExtended(url, port, pfile, uagent, interval)

elif args.dhcp:
meter.enableDHCP()
Expand Down

0 comments on commit 2819a56

Please sign in to comment.