s-celles / APC

APC power switch automation
MIT License
30 stars 9 forks source link

--status returns "parse error" if outlets are named. #9

Closed pjtait closed 5 years ago

pjtait commented 6 years ago
% apc --user XXXX --password XXXX --host XXXXX --status
Acquiring lock /tmp/apc.lock
Connecting to APC @ XXXXX
Logged in as user XXXXX, version 3.9.2
DISCONNECTED from XXXXXX
Traceback (most recent call last):
  File "/usr/bin/apc", line 9, in <module>
    load_entry_point('apc==0.1.0', 'console_scripts', 'apc')()
  File "/usr/lib/python2.7/site-packages/apc/cli_apc.py", line 69, in main
    print(apc.status())
  File "/usr/lib/python2.7/site-packages/apc/utility.py", line 342, in status
    ol = Outlet.parse(row)
  File "/usr/lib/python2.7/site-packages/apc/outlet.py", line 68, in parse
    raise OutletParseException('Could not parse APC outlet status')
apc.outlet.OutletParseException: Could not parse APC outlet status

I see that the regex pattern assumes the name/number field is numeric.

s-celles commented 6 years ago

That's odd because I thought I was supporting id, name and status parsing

See https://github.com/scls19fr/APC/blob/master/tests/test_outlet.py

Anyway contributions are welcome (with unit test and respecting PEP8)

s-celles commented 6 years ago

Please use triple backquote for code in Github issues

s-celles commented 6 years ago

Please use triple backticks for code in Github issues https://help.github.com/articles/creating-and-highlighting-code-blocks/

pjtait commented 6 years ago

(Thanks for the guidance on code snippets.)

Looking at line 68 of outlet.py, it seems that a line returned from the PDU is failing to match:

APC_OUTLET_ROW_PATTERN = re.compile('Outlet (\d) (.*) (OFF\*?|ON\*?)')

Looking at the output from an interactive telnet session, I see lines like:

5- Outlet 5                 OFF
6- Focus Drive PS           ON

so I think the pattern does not handle the case where a custom name has been applied to the outlet, it always expects to see "Outlet N" in the line.

I'll see if I can contribute a fix.