Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/amcrest/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@

_LOGGER = logging.getLogger(__name__)

_KEEPALIVE_OPTS = HTTPConnection.default_socket_options + [
_KEEPALIVE_OPTS = HTTPConnection.default_socket_options + list(filter(lambda option: option[1], [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.
line too long (97 > 79 characters)

(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, KEEPALIVE_IDLE),
(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE if hasattr(socket, "TCP_KEEPIDLE") else None, KEEPALIVE_IDLE), # TCP_KEEPIDLE doesn't exist for Mac

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment
line too long (144 > 79 characters)

(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, KEEPALIVE_INTERVAL),
(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, KEEPALIVE_COUNT),
]
]))


class SOHTTPAdapter(HTTPAdapter):
Expand Down
22 changes: 22 additions & 0 deletions src/amcrest/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
# vim:sw=4:ts=4:et

import datetime

class System(object):
"""Amcrest system class."""
Expand Down Expand Up @@ -50,6 +51,14 @@ def __get_config(self, config_name):
)
return ret.content.decode('utf-8')

def __set_config(self, *argv):
config_strs = "&".join(map(lambda pair: str(pair[0]) + "=" + str(pair[1]), argv))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

print('configManager.cgi?action=setConfig&{0}'.format(config_strs))
ret = self.command(
'configManager.cgi?action=setConfig&{0}'.format(config_strs)
)
return ret.content.decode('utf-8')

@property
def general_config(self):
return self.__get_config('General')
Expand Down Expand Up @@ -165,3 +174,16 @@ def reboot(self, delay=None):

ret = self.command(cmd)
return ret.content.decode('utf-8')

def setAutoReboot(self, date, everyday=False):
# No reboot
if date is None:
return self.__set_config(("AutoMaintain.AutoRebootDay", -1))
assert isinstance(date, datetime.datetime)
date_info = date.timetuple()
config = {
"AutoMaintain.AutoRebootDay": 7 if everyday else date.isoweekday(),
"AutoMaintain.AutoRebootHour": date_info.tm_hour,
"AutoMaintain.AutoRebootMinute": date_info.tm_min
}
return self.__set_config(*config.items())