mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
Update pyHS100.py
This commit is contained in:
parent
89481ad06e
commit
ef85f939fd
@ -1,10 +1,14 @@
|
|||||||
import logging, socket, codecs, json
|
import logging
|
||||||
|
import socket
|
||||||
|
import codecs
|
||||||
|
import json
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SmartPlug(object):
|
class SmartPlug(object):
|
||||||
"""Class to access TPLink Switch.
|
"""Class to access TPLink Switch.
|
||||||
|
|
||||||
Usage example when used as library:
|
Usage example when used as library:
|
||||||
p = SmartPlug("192.168.1.105")
|
p = SmartPlug("192.168.1.105")
|
||||||
# change state of plug
|
# change state of plug
|
||||||
@ -48,9 +52,9 @@ class SmartPlug(object):
|
|||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((self.ip, self.port))
|
s.connect((self.ip, self.port))
|
||||||
on_str = ('0000002ad0f281f88bff9af7d5'
|
on_str = ('0000002ad0f281f88bff9af7d5'
|
||||||
'ef94b6c5a0d48bf99cf091e8b7'
|
'ef94b6c5a0d48bf99cf091e8b7'
|
||||||
'c4b0d1a5c0e2d8a381f286e793'
|
'c4b0d1a5c0e2d8a381f286e793'
|
||||||
'f6d4eedfa2dfa2')
|
'f6d4eedfa2dfa2')
|
||||||
data = codecs.decode(on_str, 'hex_codec')
|
data = codecs.decode(on_str, 'hex_codec')
|
||||||
s.send(data)
|
s.send(data)
|
||||||
s.close()
|
s.close()
|
||||||
@ -59,9 +63,9 @@ class SmartPlug(object):
|
|||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((self.ip, self.port))
|
s.connect((self.ip, self.port))
|
||||||
off_str = ('0000002ad0f281f88bff9af7d5'
|
off_str = ('0000002ad0f281f88bff9af7d5'
|
||||||
'ef94b6c5a0d48bf99cf091e8b7'
|
'ef94b6c5a0d48bf99cf091e8b7'
|
||||||
'c4b0d1a5c0e2d8a381f286e793'
|
'c4b0d1a5c0e2d8a381f286e793'
|
||||||
'f6d4eedea3dea3')
|
'f6d4eedea3dea3')
|
||||||
data = codecs.decode(off_str, 'hex_codec')
|
data = codecs.decode(off_str, 'hex_codec')
|
||||||
s.send(data)
|
s.send(data)
|
||||||
s.close()
|
s.close()
|
||||||
@ -77,8 +81,8 @@ class SmartPlug(object):
|
|||||||
code = 171
|
code = 171
|
||||||
response = ""
|
response = ""
|
||||||
query_str = ('00000023d0f0d2a1d8abdfbad7'
|
query_str = ('00000023d0f0d2a1d8abdfbad7'
|
||||||
'f5cfb494b6d1b4c09fec95e68f'
|
'f5cfb494b6d1b4c09fec95e68f'
|
||||||
'e187e8caf09eeb87ebcbb696eb')
|
'e187e8caf09eeb87ebcbb696eb')
|
||||||
data = codecs.decode(query_str, 'hex_codec')
|
data = codecs.decode(query_str, 'hex_codec')
|
||||||
s.send(data)
|
s.send(data)
|
||||||
reply = s.recv(4096)
|
reply = s.recv(4096)
|
||||||
@ -95,7 +99,6 @@ class SmartPlug(object):
|
|||||||
|
|
||||||
info = json.loads(response)
|
info = json.loads(response)
|
||||||
# info is reserved for future expansion.
|
# info is reserved for future expansion.
|
||||||
# The JSON response from the smartplug provide smartplug system information
|
|
||||||
sys_info = info["system"]["get_sysinfo"]
|
sys_info = info["system"]["get_sysinfo"]
|
||||||
relay_state = sys_info["relay_state"]
|
relay_state = sys_info["relay_state"]
|
||||||
return relay_state
|
return relay_state
|
||||||
|
Loading…
Reference in New Issue
Block a user