Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | |
| 3 | # Copyright 2013 Linaro Limited |
| 4 | # Author Matt Hart <matthew.hart@linaro.org> |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 2 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | # MA 02110-1301, USA. |
| 20 | |
| 21 | import logging |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 22 | from apcbase import APCBase |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 23 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 24 | |
| 25 | class APC7952(APCBase): |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 26 | |
| 27 | def _pdu_logout(self): |
| 28 | self._back_to_main() |
| 29 | logging.debug("Logging out") |
| 30 | self.connection.send("4\r") |
| 31 | |
| 32 | def _back_to_main(self): |
| 33 | logging.debug("Returning to main menu") |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 34 | self.connection.send("\r") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 35 | self.connection.expect('>') |
| 36 | for i in range(1, 20): |
| 37 | self.connection.send("\x1B") |
| 38 | self.connection.send("\r") |
| 39 | res = self.connection.expect(["4- Logout", "> "]) |
| 40 | if res == 0: |
| 41 | logging.debug("Back at main menu") |
| 42 | break |
| 43 | |
| 44 | def _enter_outlet(self, outlet, enter_needed=True): |
| 45 | outlet = "%s" % outlet |
| 46 | logging.debug("Attempting to enter outlet %s", outlet) |
| 47 | if (enter_needed): |
| 48 | self.connection.expect("Press <ENTER> to continue...") |
| 49 | logging.debug("Sending enter") |
| 50 | self.connection.send("\r") |
| 51 | self.connection.expect("> ") |
| 52 | logging.debug("Sending outlet number") |
| 53 | self.connection.send(outlet) |
| 54 | self.connection.send("\r") |
| 55 | logging.debug("Finished entering outlet") |
| 56 | |
| 57 | def _port_interaction(self, command, port_number): |
| 58 | print("Attempting command: %s port: %i" % (command, port_number)) |
| 59 | ### make sure in main menu here |
| 60 | self._back_to_main() |
| 61 | self.connection.send("\r") |
| 62 | self.connection.expect("1- Device Manager") |
| 63 | self.connection.expect("> ") |
| 64 | logging.debug("Entering Device Manager") |
| 65 | self.connection.send("1\r") |
| 66 | self.connection.expect("------- Device Manager") |
| 67 | self.connection.send("2\r") |
| 68 | res = self.connection.expect("1- Outlet Control/Configuration") |
| 69 | self.connection.expect("> ") |
| 70 | self.connection.send("1\r") |
| 71 | self._enter_outlet(port_number, False) |
| 72 | self.connection.expect("> ") |
| 73 | self.connection.send("1\r") |
| 74 | res = self.connection.expect(["> ", "Press <ENTER> to continue..."]) |
| 75 | if res == 1: |
| 76 | logging.debug("Stupid paging thingmy detected, pressing enter") |
| 77 | self.connection.send("\r") |
| 78 | self.connection.send("\r") |
| 79 | if command == "on": |
| 80 | self.connection.send("1\r") |
| 81 | self.connection.expect("Immediate On") |
| 82 | self._do_it() |
| 83 | elif command == "off": |
| 84 | self.connection.send("2\r") |
| 85 | self.connection.expect("Immediate Off") |
| 86 | self._do_it() |
| 87 | else: |
| 88 | logging.debug("Unknown command!") |
| 89 | |
| 90 | def _do_it(self): |
| 91 | self.connection.expect("Enter 'YES' to continue or <ENTER> to cancel :") |
| 92 | self.connection.send("YES\r") |
| 93 | self.connection.expect("Press <ENTER> to continue...") |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 94 | self.connection.send("\r") |