Skip to content

Commit

Permalink
Use the path parameter of encode/decode again to be future-proof.
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Feb 14, 2018
1 parent 26fc798 commit 74e9bed
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions miio/chuangmi_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def play(self, command: str):


class ProntoPulseAdapter(Adapter):
def _decode(self, obj, context, *args, **kwargs):
def _decode(self, obj, context, path):
return int(obj * context._.modulation_period)

def _encode(self, obj, context, *args, **kwargs):
def _encode(self, obj, context, path):
raise RuntimeError('Not implemented')


Expand Down
8 changes: 4 additions & 4 deletions miio/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,24 @@ def is_hello(x) -> bool:

class TimeAdapter(Adapter):
"""Adapter for timestamp conversion."""
def _encode(self, obj, context, *args, **kwargs):
def _encode(self, obj, context, path):
return calendar.timegm(obj.timetuple())

def _decode(self, obj, context, *args, **kwargs):
def _decode(self, obj, context, path):
return datetime.datetime.utcfromtimestamp(obj)


class EncryptionAdapter(Adapter):
"""Adapter to handle communication encryption."""
def _encode(self, obj, context, *args, **kwargs):
def _encode(self, obj, context, path):
"""Encrypt the given payload with the token stored in the context.
:param obj: JSON object to encrypt"""
# pp(context)
return Utils.encrypt(json.dumps(obj).encode('utf-8') + b'\x00',
context['_']['token'])

def _decode(self, obj, context, *args, **kwargs):
def _decode(self, obj, context, path):
"""Decrypts the given payload with the token stored in the context.
:return str: JSON object"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
click
cryptography
pretty_cron
construct>=2.9.23,<=2.9.30
construct==2.9.30
zeroconf
attrs
typing # for py3.4 support
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def readme():
packages=["miio", "mirobo"],

python_requires='>=3.4',
install_requires=['construct>=2.9.23,<=2.9.30',
install_requires=['construct==2.9.30',
'click',
'cryptography',
'pretty_cron',
Expand Down

0 comments on commit 74e9bed

Please sign in to comment.