Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for the API change of construct v2.9.30 #220

Merged
merged 3 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, path):
Copy link
Contributor

@yawor yawor Feb 13, 2018

Choose a reason for hiding this comment

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

If the code doesn't use the new path arg, wouldn't it be better to add here (and in other methods) *args, **kwargs to just ignore any extra arguments? It would make it backward compatible with earlier Construct versions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice approach! I updated the PR.

return int(obj * context._.modulation_period)

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

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


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