Skip to content

Commit 1c386a9

Browse files
committed
Switch to DigestAuth. This is incompatible with firmware <2.0.4
1 parent e15a7da commit 1c386a9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

spx/smartplug.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from xml.dom.minidom import parseString
77

88
import requests
9+
from requests.auth import HTTPDigestAuth
910

1011
log = logging.getLogger(__name__)
1112

@@ -74,7 +75,8 @@ def _convert_to_boolean(self, value):
7475

7576
def _send_command(self, command):
7677
log.debug(command)
77-
response = requests.post(self.url, data=command, auth=HTTPDigestAut h(),timeout=5)
78+
auth = HTTPDigestAuth(username=self.username, password=self.password)
79+
response = requests.post(self.url, data=command,timeout=5, auth=auth)
7880

7981
if response.status_code != 200:
8082
raise SmartplugCommandFailed(response.status_code,

spx/tool.py

100644100755
File mode changed.

tests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import datetime
22
import unittest
3+
4+
from requests.auth import HTTPBasicAuth
5+
36
try:
47
from mock import MagicMock, patch
58
except ImportError:
@@ -30,9 +33,10 @@ def test_get_usage(self, p, d):
3033
}
3134
)
3235
p.assert_called_once_with(
33-
'http://admin:1234@240.0.0.1:10000/smartplug.cgi',
36+
'http://240.0.0.1:10000/smartplug.cgi',
3437
data='\n<?xml version="1.0" encoding="UTF8"?>\n<SMARTPLUG id="edimax">\n<CMD id="get">\n <NOW_POWER>\n </NOW_POWER>\n</CMD>\n</SMARTPLUG>',
35-
timeout=5
38+
timeout=5,
39+
auth=HTTPBasicAuth('admin', '1234')
3640
)
3741

3842

0 commit comments

Comments
 (0)