Skip to content

Commit

Permalink
Fixes for the API change of construct v2.9.30 (#220)
Browse files Browse the repository at this point in the history
* Fixes for the API change of construct v2.9.30.

construct==2.9.30 pinned.

* Backward compatible solution used.

* Range of compatible construct versions added.
  • Loading branch information
syssi authored and rytilahti committed Feb 13, 2018
1 parent bc9fdcf commit a675ef0
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):
def _decode(self, obj, context, *args, **kwargs):
return int(obj * context._.modulation_period)

def _encode(self, obj, context):
def _encode(self, obj, context, *args, **kwargs):
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):
def _encode(self, obj, context, *args, **kwargs):
return calendar.timegm(obj.timetuple())

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


class EncryptionAdapter(Adapter):
"""Adapter to handle communication encryption."""
def _encode(self, obj, context):
def _encode(self, obj, context, *args, **kwargs):
"""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):
def _decode(self, obj, context, *args, **kwargs):
"""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
construct>=2.9.23,<=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',
install_requires=['construct>=2.9.23,<=2.9.30',
'click',
'cryptography',
'pretty_cron',
Expand Down

1 comment on commit a675ef0

@arekbulski
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add "path" to encode and decode, not entire * and **, thats not safe.

Please sign in to comment.