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 apc7952 import APC7952 |
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 | class APC9218(APC7952): |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 25 | |
| 26 | def _port_interaction(self, command, port_number): |
| 27 | print("Attempting command: %s port: %i" % (command, port_number)) |
| 28 | ### make sure in main menu here |
| 29 | self._back_to_main() |
| 30 | self.connection.send("\r") |
| 31 | self.connection.expect("1- Device Manager") |
| 32 | self.connection.expect("> ") |
| 33 | logging.debug("Entering Device Manager") |
| 34 | self.connection.send("1\r") |
| 35 | self.connection.expect("------- Device Manager") |
| 36 | logging.debug("Got to Device Manager") |
| 37 | self._enter_outlet(port_number, False) |
| 38 | res = self.connection.expect(["1- Control Outlet", "1- Outlet Control/Configuration"]) |
| 39 | self.connection.expect("> ") |
| 40 | self.connection.send("1\r") |
| 41 | res = self.connection.expect(["> ", "Press <ENTER> to continue..."]) |
| 42 | if res == 1: |
| 43 | logging.debug("Stupid paging thingmy detected, pressing enter") |
| 44 | self.connection.send("\r") |
| 45 | self.connection.send("\r") |
| 46 | res = self.connection.expect(["Control Outlet %s" % port_number, "Control Outlet"]) |
| 47 | self.connection.expect("3- Immediate Reboot") |
| 48 | self.connection.expect("> ") |
| 49 | if command == "on": |
| 50 | self.connection.send("1\r") |
| 51 | self.connection.expect("Immediate On") |
| 52 | self._do_it() |
| 53 | elif command == "off": |
| 54 | self.connection.send("2\r") |
| 55 | self.connection.expect("Immediate Off") |
| 56 | self._do_it() |
| 57 | else: |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 58 | logging.debug("Unknown command!") |