Giter Site home page Giter Site logo

pyharmony's Introduction

pyharmony

Python library for connecting to and controlling the Logitech Harmony Link

Protocol

As the harmony protocol is being worked out, notes are in PROTOCOL.md.

Status

  • Authentication to Logitech's web service working.
  • Authentication to harmony device working.
  • Querying for entire device information
  • Sending a simple command to harmony device working.

Usage

To query your device's configuration state:

PYTHONPATH="." python harmony --email [email protected] --password pass \
    --harmony_ip 192.168.0.1 show_config

For full argument information on the command-line tool:

PYTHONPATH="." python harmony

TODO

  • Figure out how to detect when the session token expires so we can get a new one.
  • Figure out a good way of sending commands based on sync state.
  • Is it possible to update device configuration?

pyharmony's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyharmony's Issues

Brief Explanations Please

Hi,

I have scoured all of the various forks of this module, and all of them seem to talk about requiring authenticated tokens. In my experience with my Hub, I can send commands and get the config from it without doing anythign at all. Is this expected nowadays? I mean, it is quite slow which I assume is due to it not having a proper token, yet it still works.

Also, I am simply putting it in a for loop and using send_command to send digits to change the channel numerically without having to program 1000 favorites so each channel has it's own identifier. Is there a way to send a sting of commands @ once? I have yet to try it in python, just using the provided harmony built-ins ::

for i in 1 0 0 5 Enter ; do harmony --harmony_ip 192.168.100.191 send_command --device_id=54904916 --command=$i ; done

But this does not change the channel fast enough for my receiver, so it changes the channel 4x - obviously not what I need. I am not apython expert, but can probably find my way around if I need to write it in python to accomplish what I need.

Thanks!

-Greg

Need some help

Sorry, but I need some help as I don't know how to use python modules.

What do I need to do to run this in Python for Windows? I have downloaded the files and have them in a folder called harmony. Do I have to do something to install the module to get it to run from a command line? And why do the examples include a PTHONPATH?

From the command line I type c:\python27\python\harmony and I get
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 162, in run_module_as_main
"main", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in run_code
exec code in run_globals
File "C:\pyharmony-master\harmony__main
.py", line 10, in
from harmony import auth
ImportError: No module named harmony

How did you sniff the protocol?

I have implemented that config example in the code (using the gatorade fork) and the config query works great. But I am unable to get the VolumeDown keypress example to work. I have tried to sniff my wifi with wireshark to see the packets but my laptop's adapter and/or driver can't capture anything but it's own traffic. How did you two, @jterrace and @petele, capture the packets? Is there any trick other than the normal airmon-ng and wireshark stuff?

If I can get this to work I promise I'll release a new generation of code with some of the to-do list filled out.

My failed communication is below. Any idea what could be wrong? I added the timestamp=0 based on another issue here but it didn't make a difference. I can tell the command is parsed properly because if I misspell anything I get worse errors.

Request:
     <iq type="get" id="#{identity}">
       <oa xmlns="connect.logitech.com"                  
           mime="vnd.logitech.harmony/vnd.logitech.harmony.engine?holdAction">
          action={"command"::"VolumeDown","type"::"IRCommand", "deviceId"::"19685842"}:status=press:timestamp=0
       </oa>
     </iq>
Response:
    <iq id="278a394f-4d9e-43cf-bc26-5dd204b837bd" to="278a394f-4d9e-43cf-bc26-5dd204b837bd" type="get">
      <oa xmlns='connect.logitech.com' mime='vnd.logitech.harmony/vnd.logitech.harmony.engine?holdAction' 
          errorcode='504' errorstring='Insufficient Arguments'>
      </oa>
    </iq>

connect() got an unexpected keyword argument 'use_ssl'

Having issues getting past this error... to install the libraries I just used

sudo apt-get install python-argh

sudo apt-get install python-sleekxmpp

sudo apt-get install python-requests

Linux 3.8.0-19-generic #30-Ubuntu

PYTHONPATH="." python harmony --email XXXXX --password XXXXX --harmony_ip 192.168.0.236 show_config

INFO urllib3.connectionpool Starting new HTTPS connection (1): svcs.myharmony.com
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/pyharmony/harmony/main.py", line 83, in
main()
File "/tmp/pyharmony/harmony/main.py", line 79, in main
sys.exit(args.func(args))
File "/tmp/pyharmony/harmony/main.py", line 37, in show_config
token = login_to_logitech(args)
File "/tmp/pyharmony/harmony/main.py", line 28, in login_to_logitech
args.harmony_ip, args.harmony_port, token)
File "/tmp/pyharmony/harmony/auth.py", line 111, in swap_auth_token
use_tls=False, use_ssl=False)
TypeError: connect() got an unexpected keyword argument 'use_ssl'

TypeError: 'dict' object is not callable

Any thoughts on this? I

Command:

PYTHONPATH="." python harmony --email --password --harmony_ip 192.168.1.23 show_config

output:

INFO requests.packages.urllib3.connectionpool Starting new HTTPS connection (1): svcs.myharmony.com
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/pi/pyharmony-master/harmony/main.py", line 83, in
main()
File "/home/pi/pyharmony-master/harmony/main.py", line 79, in main
sys.exit(args.func(args))
File "/home/pi/pyharmony-master/harmony/main.py", line 37, in show_config
token = login_to_logitech(args)
File "/home/pi/pyharmony-master/harmony/main.py", line 23, in login_to_logitech
token = auth.login(args.email, args.password)
File "/home/pi/pyharmony-master/harmony/auth.py", line 41, in login
result = resp.json().get('GetUserAuthTokenResult', None)
TypeError: 'dict' object is not callable

How to send commands

I have tried to follow the protocol docs for sending a command, but am having difficulty figuring out where to add the "{"type":"IRCommand","deviceId":"13154865","command":"PowerOff"}:status=press".
Any help would be appreciated.
Right now I have:

iq_cmd = self.Iq()
        iq_cmd['type'] = 'get'
        action_cmd = ET.Element('oa')
        action_cmd.attrib['xmlns'] = 'connect.logitech.com'
        action_cmd.attrib['mime'] = (
            'vnd.logitech.harmony/vnd.logitech.harmony.engine?holdAction')
        action_cmd.attrib['action'] = '{"type":"IRCommand","deviceId":"13154865","command":"PowerOff"}:status=press'
        iq_cmd.set_payload(action_cmd)
        result = iq_cmd.send(block=True)
        payload = result.get_payload()
        assert len(payload) == 1
        action_cmd = payload[0]
        assert action_cmd.attrib['errorcode'] == '200'
        response = action_cmd.text
        return json.loads(response)

Fails with OSError: [Errno 57] Socket is not connected

I've been using this for a long time on Raspberry Pi with Python 3.5 but now on a machine with FreeBSD and Python 3.7 it's failing with:

Traceback (most recent call last):
  File "/var/polyglot/nodeservers/HarmonyHub/harmony_hub_nodes/HarmonyController.py", line 221, in _discover
    discover_result = harmony_discovery.discover(scan_attempts=10,scan_interval=1)
  File "/var/polyglot/.local/lib/python3.7/site-packages/pyharmony/discovery.py", line 107, in discover
    return Discovery().discover(scan_attempts, scan_interval)
  File "/var/polyglot/.local/lib/python3.7/site-packages/pyharmony/discovery.py", line 90, in discover
    listen_socket.shutdown(socket.SHUT_RDWR)
OSError: [Errno 57] Socket is not connected

Not sure if this is caused by FreeBSD differences or Python.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.