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

commands to a real Mochad server buffer up and do not execute immediately #1

Closed
clach04 opened this issue Jul 19, 2016 · 5 comments
Closed

Comments

@clach04
Copy link
Owner

clach04 commented Jul 19, 2016

Reported in clach04/home-assistant-x10#1

Suspect this is due to \n rather than \r usage, https://github.com/zonyl/pytomation/blob/master/pytomation/interfaces/mochad.py#L151 is using 0x0d as teminator. x10_any has only been tested with a fake server so far.

@clach04
Copy link
Owner Author

clach04 commented Jul 19, 2016

Proposed fix:

diff --git a/x10_any/__init__.py b/x10_any/__init__.py
index 7660c06..fbcc74b 100644
--- a/x10_any/__init__.py
+++ b/x10_any/__init__.py
@@ -240,7 +240,7 @@ class MochadDriver(X10Driver):
         house_and_unit = to_bytes(house_and_unit)
         # TODO normalize/validate state
         state = to_bytes(state)
-        mochad_cmd = self.default_type + b' ' + house_and_unit + b' ' + state + b'\n'  # byte concat works with older Python 3.4
+        mochad_cmd = self.default_type + b' ' + house_and_unit + b' ' + state + b'\r'  # byte concat works with older Python 3.4
         log.debug('mochad send: %r', mochad_cmd)
         mochad_host, mochad_port = self.device_address
         result = netcat(mochad_host, mochad_port, mochad_cmd)

@clach04
Copy link
Owner Author

clach04 commented Jul 20, 2016

The source code for Mochad, in encode.c:837 cm15a_encode() appear to check for either \r or \n (it also checks for end-of-string), the behavior reported in clach04/home-assistant-x10#1 (comment) implies that is not working.

clach04 added a commit that referenced this issue Jul 20, 2016
Fixes issue #1, see issue #1 comments for reasons but the main one
is to more closely follow telnet payload.
@clach04
Copy link
Owner Author

clach04 commented Jul 21, 2016

@akeshan can you try the current version from git please? Example test.

import x10_any

x10_any.default_logger.setLevel(x10_any.logging.DEBUG) # DEBUG

dev = x10_any.MochadDriver()
dev.x10_command('B', 4, x10_any.ON)
dev.x10_command('B', 4, x10_any.OFF)

Thanks.

@akeshan
Copy link

akeshan commented Jul 21, 2016

Tried the latest version and it works great, very responsive.

@clach04
Copy link
Owner Author

clach04 commented Jul 21, 2016

@akeshan many thanks for your assistance with this, https://pypi.python.org/pypi/x10_any/0.0.6 now posted and should be pip installable and working.

@clach04 clach04 closed this as completed Jul 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants