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

TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple' #1

Closed
akeshan opened this issue Jul 18, 2016 · 11 comments
Closed

TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple' #1

akeshan opened this issue Jul 18, 2016 · 11 comments

Comments

@akeshan
Copy link

akeshan commented Jul 18, 2016

I have setup the component to use Mochad.
When i try to toggle any of the switches, I receive the following TypeError. Please let me know how to resolve this. Thanks.


Jul 18 04:58:09 raspberrypi hass[3095]: 16-07-18 04:58:09 ERROR (ThreadPool Worker 16) [homeassistant.core] BusHandler:Exception doing job
Jul 18 04:58:09 raspberrypi hass[3095]: Traceback (most recent call last):
Jul 18 04:58:09 raspberrypi hass[3095]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 835, in job_handler
Jul 18 04:58:09 raspberrypi hass[3095]: func(arg)
Jul 18 04:58:09 raspberrypi hass[3095]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 688, in _execute_service
Jul 18 04:58:09 raspberrypi hass[3095]: service(call)
Jul 18 04:58:09 raspberrypi hass[3095]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 547, in call
Jul 18 04:58:09 raspberrypi hass[3095]: self.func(call)
Jul 18 04:58:09 raspberrypi hass[3095]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/init.py", line 84, in handle_switch_service
Jul 18 04:58:09 raspberrypi hass[3095]: switch.turn_on()
Jul 18 04:58:09 raspberrypi hass[3095]: File "/home/pi/.homeassistant/custom_components/switch/x10.py", line 80, in turn_on
Jul 18 04:58:09 raspberrypi hass[3095]: self._device.x10_command(self._house_code, self._unit_number, 'ON')
Jul 18 04:58:09 raspberrypi hass[3095]: File "/home/pi/.homeassistant/deps/x10_any/init.py", line 154, in x10_command
Jul 18 04:58:09 raspberrypi hass[3095]: return self._x10_command(house_code, unit_number, state)
Jul 18 04:58:09 raspberrypi hass[3095]: File "/home/pi/.homeassistant/deps/x10_any/init.py", line 243, in _x10_command
Jul 18 04:58:09 raspberrypi hass[3095]: mochad_cmd = b"%s %s %s\n" % (self.default_type, house_and_unit, state)
Jul 18 04:58:09 raspberrypi hass[3095]: TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'

@clach04
Copy link
Owner

clach04 commented Jul 18, 2016

@akeshan, thanks for taking time to test this out and report a bug. Can you let me know the exact version of Python this is please? I've been using this with Python 3.5.1 and I'd like to try and reproduce this on my machine. I have an idea for a fix (in https://github.com/clach04/x10_any, looks like default_type needs a to_byte()), but I'd like to see it failing locally first.

@akeshan
Copy link
Author

akeshan commented Jul 18, 2016

No problem, I believe that I have version 3.4.2

@clach04
Copy link
Owner

clach04 commented Jul 19, 2016

@akeshan just the information I needed. Thank you. I've been able to get hold of Python 3.4.4 and reproduced the problem. So there are 2-3 options for you at the moment:

  1. Upgrade Python on your Pi :-p pretty sure this isn't an option for you (yet)
  2. Manually hack in the fix to x10_any (not the HA plugin) clach04/x10_any@0f52f95 which is the fastest option and should get you running immediately. Either edit on your machine /home/pi/.homeassistant/deps/x10_any/__init.py or download https://raw.githubusercontent.com/clach04/x10_any/master/x10_any/__init__.py and replace your file with it
  3. Wait until I push out the new version (0.0.6) of x10_any on PyPi

If you are willing to try #2 that would give me more confidence in testing before I publish the next version.

@akeshan
Copy link
Author

akeshan commented Jul 19, 2016

Thanks for the quick response. I tried #2 and downloaded the new file and the error is gone.

However, I have a new issue now where I interact with the switches but the command isn't executed till I manually run a command through mochad. For example I have toggled three switches to the off state and then see no response so I manually go and try to turn one off and then I see all of them execute at once:

pi@raspberrypi:~ $ telnet 0 1099
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
rf b4 off
07/19 06:36:22 Tx RF HouseUnit: B4 Func: Off
07/19 06:36:22 Tx RF HouseUnit: C1 Func: Off
07/19 06:36:22 Tx RF HouseUnit: A2 Func: Off

@clach04
Copy link
Owner

clach04 commented Jul 19, 2016

@akeshan thanks for being willing to test this! I do not have access to the hardware that Mochad uses so I've only tested this with a fake Mochad server so far. I think I know what the problem is, I've opened a new issue clach04/x10_any#1 which has a proposed fix (search for \n and replace with \r in /home/pi/.homeassistant/deps/x10_any/__init__.py).

@clach04
Copy link
Owner

clach04 commented Jul 20, 2016

@akeshan I believe we've found a bug in Mochad but also in x10_any. I believe I have a fix for clach04/x10_any#1 and it is submitted. Can you give that a shot (same procedure as before)?

One option which may be easier/quicker would be for you to checkout x10_any and then try a modified version of the sample from the readme, e.g.:

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)

@akeshan
Copy link
Author

akeshan commented Jul 20, 2016

I tried replacing the '\n' with '\r' in the mochad_cmd line as suggested in the fix, however the issue still remains.

I also tried it with '\r\n' and got the same result. The command is buffered until I run another one through telnet.

@clach04
Copy link
Owner

clach04 commented Jul 20, 2016

@akeshan does:

echo rf b4 on| nc localhost 1099
sleep 1
echo rf b4 off| nc localhost 1099

work? If so I could remove the code that does a read from Mochad and clone nc behavior which is a write (no read) only operation instead. It may be that setting up a proxy server to record traffic would be a help but lets hold that idea in reserve for a while.

@akeshan
Copy link
Author

akeshan commented Jul 21, 2016

Yes that works!

@clach04
Copy link
Owner

clach04 commented Jul 21, 2016

@akeshan so the nc sample above works? Cool, I've removed the read code and made x10_any use \n as the terminator. Lets switch topic updates over to clach04/x10_any#1. If this still doesn't work we can use nc to help diagnose this further.

@clach04
Copy link
Owner

clach04 commented Jul 21, 2016

https://pypi.python.org/pypi/x10_any/0.0.6 now posted and should be pip installable. Addresses both original problem with Python versions earlier than 3.5 and support real Mochad servers.

@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