Skip to content

Commit

Permalink
Expanded names of tp link encryption funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
kbickar committed Aug 21, 2020
1 parent a2cfc0b commit 82fa08d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions sense_energy/SenseLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import logging
import asyncio
import json
import TPLinkEncryption
from PlugInstance import PlugInstance

from .TPLinkEncryption import *
from .PlugInstance import PlugInstance

SENSE_TP_LINK_PORT = 9999

Expand All @@ -23,7 +24,7 @@ def connection_lost(self, exc):
pass

def datagram_received(self, data, addr):
decrypted_data = TPLinkEncryption.decrypt(data)
decrypted_data = tp_link_decrypt(data)

try:
json_data = json.loads(decrypted_data)
Expand All @@ -43,7 +44,7 @@ def datagram_received(self, data, addr):
# Build response
response = plug.generate_response()
json_resp = json.dumps(response, separators=(',', ':'))
encrypted_resp = TPLinkEncryption.encrypt(json_resp)
encrypted_resp = tp_link_encrypt(json_resp)
# Strip leading 4 bytes for...some reason
encrypted_resp = encrypted_resp[4:]

Expand Down
4 changes: 2 additions & 2 deletions sense_energy/TPLinkEncryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from struct import pack


def encrypt(string):
def tp_link_encrypt(string):
key = 171
result = pack('>I', len(string))
for i in string:
Expand All @@ -33,7 +33,7 @@ def encrypt(string):
return result


def decrypt(string):
def tp_link_decrypt(string):
key = 171
result = ""
for i in string:
Expand Down
2 changes: 2 additions & 0 deletions sense_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
import sys
if sys.version_info >= (3, 5):
from .asyncsenseable import ASyncSenseable
from .PlugInstance import PlugInstance
from .SenseLink import SenseLink

__version__ = "0.7.0"

0 comments on commit 82fa08d

Please sign in to comment.