mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Refactors state() to use turn_on() and turn_off()
This commit is contained in:
parent
0eabf264e4
commit
77d524ecf2
@ -54,28 +54,10 @@ class SmartPlug(object):
|
|||||||
:param value: Future state (either ON or OFF)
|
:param value: Future state (either ON or OFF)
|
||||||
"""
|
"""
|
||||||
if value.upper() == 'ON':
|
if value.upper() == 'ON':
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.turn_on()
|
||||||
s.connect((self.ip, self.port))
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.connect((self.ip, self.port))
|
|
||||||
on_str = ('0000002ad0f281f88bff9af7d5'
|
|
||||||
'ef94b6c5a0d48bf99cf091e8b7'
|
|
||||||
'c4b0d1a5c0e2d8a381f286e793'
|
|
||||||
'f6d4eedfa2dfa2')
|
|
||||||
data = codecs.decode(on_str, 'hex_codec')
|
|
||||||
s.send(data)
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
elif value.upper() == 'OFF':
|
elif value.upper() == 'OFF':
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.turn_off()
|
||||||
s.connect((self.ip, self.port))
|
|
||||||
off_str = ('0000002ad0f281f88bff9af7d5'
|
|
||||||
'ef94b6c5a0d48bf99cf091e8b7'
|
|
||||||
'c4b0d1a5c0e2d8a381f286e793'
|
|
||||||
'f6d4eedea3dea3')
|
|
||||||
data = codecs.decode(off_str, 'hex_codec')
|
|
||||||
s.send(data)
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise TypeError("State %s is not valid." % str(value))
|
raise TypeError("State %s is not valid." % str(value))
|
||||||
|
Loading…
Reference in New Issue
Block a user