On my UPS the regular ups.status response would be "OL CHRG"
When I add ups.status to nut_vars JSON, I get the following error:
VAR ups ups.status "OL CHRG"
Traceback (most recent call last):
File "/etc/nut/influx_nut/influx_nut.py", line 337, in
cli()
File "/etc/nut/influx_nut/influx_nut.py", line 332, in cli
influx_creds=config['influx_creds'])
File "/etc/nut/influx_nut/influx_nut.py", line 274, in update
var_value = info['type'](nut_conn.request_var(nut_ups, var))
File "/etc/nut/influx_nut/influx_nut.py", line 159, in request_var
resp = VarResponse(*(raw_resp.split(' ')))
TypeError: new() takes 5 positional arguments but 6 were given
This suggests that raw_resp is split by space char and this results in splitting "OL CHRG" into two separate elements.
My apologies beforehand, because my Python programming skills are beyond horrible, but the way I fixed it for myself is by rewriting request_var function (lines mentioning / working with list "tmp_resp" are the new ones):
def request_var(self, ups, var) -> str:
VarResponse = collections.namedtuple('VarResponse',('type', 'ups', 'var', 'value'))
req = 'GET VAR {} {}'.format(ups, var)
raw_resp = self.request(req)
tmp_resp = raw_resp.split(' ')
if len(tmp_resp)>4:
value = tmp_resp[3]
while len(tmp_resp)>4:
value +='-' + tmp_resp[len(tmp_resp)-1]
tmp_resp.pop(len(tmp_resp)-1)
tmp_resp[3] = value
resp = VarResponse(*(tmp_resp))
return resp.value.strip('"')
On my UPS the regular ups.status response would be "OL CHRG"
When I add ups.status to nut_vars JSON, I get the following error:
VAR ups ups.status "OL CHRG"
Traceback (most recent call last):
File "/etc/nut/influx_nut/influx_nut.py", line 337, in
cli()
File "/etc/nut/influx_nut/influx_nut.py", line 332, in cli
influx_creds=config['influx_creds'])
File "/etc/nut/influx_nut/influx_nut.py", line 274, in update
var_value = info['type'](nut_conn.request_var(nut_ups, var))
File "/etc/nut/influx_nut/influx_nut.py", line 159, in request_var
resp = VarResponse(*(raw_resp.split(' ')))
TypeError: new() takes 5 positional arguments but 6 were given
This suggests that raw_resp is split by space char and this results in splitting "OL CHRG" into two separate elements.
My apologies beforehand, because my Python programming skills are beyond horrible, but the way I fixed it for myself is by rewriting request_var function (lines mentioning / working with list "tmp_resp" are the new ones):