Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [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 |
| 22 | from lavapdu.drivers.apc7952 import APC7952 |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 23 | log = logging.getLogger(__name__) |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 24 | |
| 25 | |
| 26 | class APC9210(APC7952): |
| 27 | |
| 28 | @classmethod |
| 29 | def accepts(cls, drivername): |
| 30 | if drivername == "apc9210": |
| 31 | return True |
| 32 | return False |
| 33 | |
| 34 | def _port_interaction(self, command, port_number): |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 35 | log.debug("Attempting command: %s port: %i", command, port_number) |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 36 | # make sure in main menu here |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 37 | self._back_to_main() |
| 38 | self.connection.send("\r") |
| 39 | self.connection.expect("1- Outlet Manager") |
| 40 | self.connection.expect("> ") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 41 | log.debug("Entering Outlet Manager") |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 42 | self.connection.send("1\r") |
| 43 | self.connection.expect("------- Outlet Manager") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 44 | log.debug("Got to Device Manager") |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 45 | self._enter_outlet(port_number, False) |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 46 | self.connection.expect(["1- Control of Outlet", |
| 47 | "1- Outlet Control/Configuration"]) |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 48 | self.connection.expect("> ") |
| 49 | self.connection.send("1\r") |
| 50 | self.connection.expect("Turn Outlet On") |
| 51 | self.connection.expect("> ") |
| 52 | if command == "on": |
| 53 | self.connection.send("1\r") |
| 54 | self.connection.expect("Turn Outlet On") |
| 55 | self._do_it() |
| 56 | elif command == "off": |
| 57 | self.connection.send("2\r") |
| 58 | self.connection.expect("Turn Outlet Off") |
| 59 | self._do_it() |
| 60 | else: |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 61 | log.debug("Unknown command!") |