blob: 4189b29239b4ca64d369eb940589c7598ecfa87c [file] [log] [blame]
Matt Hart76fb2542014-06-01 14:24:56 +01001#! /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
21import logging
Matt Hart132d43c2015-02-25 18:19:53 +000022from lavapdu.drivers.apc7952 import APC7952
Matt Hartd4a09982015-07-17 16:13:11 +010023log = logging.getLogger(__name__)
Matt Hart132d43c2015-02-25 18:19:53 +000024
Matt Hart76fb2542014-06-01 14:24:56 +010025
Matt Hart2af71142014-07-22 10:40:41 +010026class APC9218(APC7952):
Matt Hart76fb2542014-06-01 14:24:56 +010027
Matt Hart132d43c2015-02-25 18:19:53 +000028 @classmethod
29 def accepts(cls, drivername):
Matt Hartfe042212015-07-09 14:13:29 +010030 models = ["ap9606", "apc9606", "ap9218", "apc9218"]
Matt Harte7bddc02015-07-08 18:05:08 +010031 if drivername.lower() in models:
Matt Hart132d43c2015-02-25 18:19:53 +000032 return True
33 return False
34
Matt Hart76fb2542014-06-01 14:24:56 +010035 def _port_interaction(self, command, port_number):
Matt Hartfe042212015-07-09 14:13:29 +010036 # make sure in main menu here
Matt Hart76fb2542014-06-01 14:24:56 +010037 self._back_to_main()
38 self.connection.send("\r")
39 self.connection.expect("1- Device Manager")
40 self.connection.expect("> ")
Matt Hartd4a09982015-07-17 16:13:11 +010041 log.debug("Entering Device Manager")
Matt Hart76fb2542014-06-01 14:24:56 +010042 self.connection.send("1\r")
43 self.connection.expect("------- Device Manager")
Matt Hartd4a09982015-07-17 16:13:11 +010044 log.debug("Got to Device Manager")
Matt Hart76fb2542014-06-01 14:24:56 +010045 self._enter_outlet(port_number, False)
Matt Hartfe042212015-07-09 14:13:29 +010046 self.connection.expect(["1- Control Outlet",
47 "1- Outlet Control/Configuration"])
Matt Hart76fb2542014-06-01 14:24:56 +010048 self.connection.expect("> ")
49 self.connection.send("1\r")
50 res = self.connection.expect(["> ", "Press <ENTER> to continue..."])
51 if res == 1:
Matt Hartd4a09982015-07-17 16:13:11 +010052 log.debug("Stupid paging thingmy detected, pressing enter")
Matt Hart76fb2542014-06-01 14:24:56 +010053 self.connection.send("\r")
54 self.connection.send("\r")
Matt Hartfe042212015-07-09 14:13:29 +010055 self.connection.expect(["Control Outlet %s" % port_number,
56 "Control Outlet"])
Matt Hart76fb2542014-06-01 14:24:56 +010057 self.connection.expect("3- Immediate Reboot")
58 self.connection.expect("> ")
59 if command == "on":
60 self.connection.send("1\r")
61 self.connection.expect("Immediate On")
62 self._do_it()
63 elif command == "off":
64 self.connection.send("2\r")
65 self.connection.expect("Immediate Off")
66 self._do_it()
67 else:
Matt Hartd4a09982015-07-17 16:13:11 +010068 log.debug("Unknown command!")