Code Monkey home page Code Monkey logo

pyamaha's Introduction

PYAMAHA

PyPI Join the chat at https://gitter.im/rsc-dev/pyamaha Unit Tests

About

Pyamaha is Python implementation of Yamaha Extended Control API Specification. Please see Status for list of implemented functions. Undocumented functions will be added in future.

Instalation

pip install pyamaha

or

python setup.py install

Usage

API (with requests)

from pyamaha import Device, System

dev = Device('192.168.1.1')
res = dev.request(System.get_device_info())

print(res.json()) # JSON response

Async API (with aiohttp)

import asyncio
import sys

import aiohttp

from pyamaha import AsyncDevice, System


async def main():
    async with aiohttp.ClientSession() as session:
        dev = AsyncDevice(session, "192.168.1.1")
        res = await dev.request(System.get_device_info())

        v = await res.json()
        print(v)


# To avoid 'Event loop is closed' RuntimeError due to compatibility issue with aiohttp
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
    try:
        from asyncio import WindowsSelectorEventLoopPolicy
    except ImportError:
        pass
    else:
        if not isinstance(
            asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy
        ):
            asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
asyncio.run(main())

UDP Callbacks (see Chaper 10 in YXC documentation)

import time

from pyamaha import Device, System


def handle(message):
    print(message) # UDP event data (python dict)

dev = Device('192.168.1.1')
res = dev.request(System.get_device_info(), handle)

print(res.json()) # JSON response

time.sleep(60)

CLI

> python -m pyamaha
yxc>device 192.168.1.106
yxc>system
yxc\system>getDeviceInfo
{u'api_version': 1.17,
 u'destination': u'BG',
 u'device_id': u'XXX',
 u'model_name': u'CD-NT670D',
 u'netmodule_checksum': u'XXX',
 u'netmodule_version': u'1130    ',
 u'operation_mode': u'normal',
 u'response_code': 0,
 u'system_id': u'XXX',
 u'system_version': 1.7,
 u'update_error_code': u'FFFFFFFF'}
yxc\system>

Status

Function API CLI Info
SYSTEM
/YamahaExtendedControl/v1/system/getDeviceInfo x x Documented
/YamahaExtendedControl/v1/system/getFeatures x x Documented
/YamahaExtendedControl/v1/system/getNetworkStatus x x Documented
/YamahaExtendedControl/v1/system/getFuncStatus x x Documented
/YamahaExtendedControl/v1/system/setAutoPowerStandby x x Documented
/YamahaExtendedControl/v1/system/getLocationInfo x x Documented
/YamahaExtendedControl/v1/system/sendIrCode x x Documented
/YamahaExtendedControl/v1/system/setWiredLan x x Documented
/YamahaExtendedControl/v1/system/setWirelessLan x - Documented
/YamahaExtendedControl/v1/system/setWirelessDirect x - Documented
/YamahaExtendedControl/v1/system/setIpSettings x - Documented
/YamahaExtendedControl/v1/system/setNetworkName x - Documented
/YamahaExtendedControl/v1/system/setAirPlayPin x - Documented
/YamahaExtendedControl/v1/system/getMacAddressFilter x - Documented
/YamahaExtendedControl/v1/system/setMacAddressFilter x - Documented
/YamahaExtendedControl/v1/system/getNetworkStandby x - Documented
/YamahaExtendedControl/v1/system/setNetworkStandby x - Documented
/YamahaExtendedControl/v1/system/getBluetoothInfo x - Documented
/YamahaExtendedControl/v1/system/setBluetoothStandby x - Documented
/YamahaExtendedControl/v1/system/setBluetoothTxSetting x - Documented
/YamahaExtendedControl/v1/system/getBluetoothDeviceList x - Documented
/YamahaExtendedControl/v1/system/updateBluetoothDeviceList x - Documented
/YamahaExtendedControl/v1/system/connectBluetoothDevice x - Documented
/YamahaExtendedControl/v1/system/disconnectBluetoothDevice x - Documented
/YamahaExtendedControl/v1/system/setSpeakerA x - Documented
/YamahaExtendedControl/v1/system/setSpeakerB x - Documented
/YamahaExtendedControl/v1/system/setDimmer x - Documented
/YamahaExtendedControl/v1/system/setZoneBVolumeSync x - Documented
/YamahaExtendedControl/v1/system/setHdmiOut1 x - Documented
/YamahaExtendedControl/v1/system/setHdmiOut2 x - Documented
/YamahaExtendedControl/v1/system/getNameText x - Documented
/YamahaExtendedControl/v1/system/setNameText x - Documented
/YamahaExtendedControl/v1/system/setSpeakerPattern x - Documented
/YamahaExtendedControl/v1/system/setPartyMode x - Documented
ZONE
/YamahaExtendedControl/v1/{zone}/getStatus x - Documented
/YamahaExtendedControl/v1/{zone}/getSoundProgramList x - Documented
/YamahaExtendedControl/v1/{zone}/setPower x - Documented
/YamahaExtendedControl/v1/{zone}/setSleep x - Documented
/YamahaExtendedControl/v1/{zone}/setVolume x - Documented
/YamahaExtendedControl/v1/{zone}/setMute x - Documented
/YamahaExtendedControl/v1/{zone}/setInput x - Documented
/YamahaExtendedControl/v1/{zone}/setSoundProgram x - Documented
/YamahaExtendedControl/v1/{zone}/prepareInputChange x - Documented
/YamahaExtendedControl/v1/{zone}/set3dSurround x - Documented
/YamahaExtendedControl/v1/{zone}/setDirect x - Documented
/YamahaExtendedControl/v1/{zone}/setPureDirect x - Documented
/YamahaExtendedControl/v1/{zone}/setEnhancer x - Documented
/YamahaExtendedControl/v1/{zone}/setToneControl x - Documented
/YamahaExtendedControl/v1/{zone}/setEqualizer x - Documented
/YamahaExtendedControl/v1/{zone}/setBalance x - Documented
/YamahaExtendedControl/v1/{zone}/setDialogueLevel x - Documented
/YamahaExtendedControl/v1/{zone}/setDialogueLift x - Documented
/YamahaExtendedControl/v1/{zone}/setClearVoice x - Documented
/YamahaExtendedControl/v1/{zone}/setSubwooferVolume x - Documented
/YamahaExtendedControl/v1/{zone}/setBassExtension x - Documented
/YamahaExtendedControl/v1/{zone}/getSignalInfo x - Documented
/YamahaExtendedControl/v1/{zone}/setLinkControl x - Documented
/YamahaExtendedControl/v1/{zone}/setLinkAudioDelay x - Documented
TUNER
/YamahaExtendedControl/v1/tuner/getPresetInfo x - Documented
/YamahaExtendedControl/v1/tuner/getPlayInfo x - Documented
/YamahaExtendedControl/v1/tuner/setFreq x - Documented
/YamahaExtendedControl/v1/tuner/recallPreset x - Documented
/YamahaExtendedControl/v1/tuner/switchPreset x - Documented
/YamahaExtendedControl/v1/tuner/storePreset x - Documented
/YamahaExtendedControl/v1/tuner/setDabService x - Documented
NETWORK/USB
/YamahaExtendedControl/v1/netusb/getPresetInfo x - Documented
/YamahaExtendedControl/v1/netusb/getPlayInfo x - Documented
/YamahaExtendedControl/v1/netusb/setPlayback x - Documented
/YamahaExtendedControl/v1/netusb/toggleRepeat x - Documented
/YamahaExtendedControl/v1/netusb/toggleShuffle x - Documented
/YamahaExtendedControl/v1/netusb/getListInfo x - Documented
/YamahaExtendedControl/v1/netusb/setListControl x - Documented
/YamahaExtendedControl/v1/netusb/setSearchString x - Documented
/YamahaExtendedControl/v1/netusb/recallPreset x - Documented
/YamahaExtendedControl/v1/netusb/storePreset x - Documented
/YamahaExtendedControl/v1/netusb/getAccountStatus x - Documented
/YamahaExtendedControl/v1/netusb/switchAccount x - Documented
/YamahaExtendedControl/v1/netusb/getServiceInfo x - Documented
CD
/YamahaExtendedControl/v1/cd/getPlayInfo x - Documented
/YamahaExtendedControl/v1/cd/setPlayback x - Documented
/YamahaExtendedControl/v1/cd/toggleTray x - Documented
/YamahaExtendedControl/v1/cd/toggleRepeat x - Documented
/YamahaExtendedControl/v1/cd/toggleShuffle x - Documented
DIST
/YamahaExtendedControl/v1/dist/getDistributionInfo x - Documented
/YamahaExtendedControl/v1/dist/setServerInfo x - Documented
/YamahaExtendedControl/v1/dist/setClientInfo x - Documented
/YamahaExtendedControl/v1/dist/startDistribution x - Documented
/YamahaExtendedControl/v1/dist/stopDistribution x - Documented
/YamahaExtendedControl/v1/dist/setGroupName x - Documented
CLOCK
/YamahaExtendedControl/v1/clock/getSettings x - Documented
/YamahaExtendedControl/v1/clock/setAutoSync x - Documented
/YamahaExtendedControl/v1/clock/setDateAndTime x - Documented
/YamahaExtendedControl/v1/clock/setClockFormat x - Documented
/YamahaExtendedControl/v1/clock/setAlarmSettings x - Documented

License

Code is released under MIT license © Radoslaw '[rsc]' Matusiak.

pyamaha's People

Contributors

aaronrobson avatar cinkrupa avatar gitter-badger avatar hurricane31337 avatar micha91 avatar nduhamel avatar rsc-dev avatar thatdonfc avatar thezoker avatar vigonotion avatar wengloon avatar

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyamaha's Issues

Errors

Installed from the repository and I get this when I run it.

pip install -e git+https://github.com/rsc-dev/pyamaha.git#egg=pyamaha

C:\Users\HSM>python -m pyamaha
yxc>device 192.168.11.115
yxc>system
yxc\system>getDeviceInfo
Traceback (most recent call last):
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\users\HSM\src\pyamaha\pyamaha\__main__.py", line 301, in <module>
    r.cmdloop()
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\cmd.py", line 138, in cmdloop
    stop = self.onecmd(line)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\cmd.py", line 217, in onecmd
    return func(arg)
           ^^^^^^^^^
  File "c:\users\HSM\src\pyamaha\pyamaha\__main__.py", line 274, in do_system
    system.cmdloop()
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\cmd.py", line 138, in cmdloop
    stop = self.onecmd(line)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\cmd.py", line 217, in onecmd
    return func(arg)
           ^^^^^^^^^
  File "c:\users\HSM\src\pyamaha\pyamaha\__main__.py", line 21, in func_wrapper
    func(*args, **kwargs)
  File "c:\users\HSM\src\pyamaha\pyamaha\__main__.py", line 78, in do_getDeviceInfo
    pprint.pprint(resp.json())
                  ^^^^^^^^^^^
  File "C:\Users\HSM\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

C:\Users\HSM>

assert zone in ZONE, 'Invalid ZONE value!'

init.py defines ZONES in line 18 as...
ZONES = ['main', 'zone2', 'zone3', 'zone4']

There are some instances of...
assert zone in ZONE, 'Invalid ZONE value!'
where it should be...
assert zone in ZONES, 'Invalid ZONE value!'
See lines 521 and 540.

Great package though! :-)

String format spelled 'fromat' in several places in __init__.py file

Hi,
String format spelled 'fromat' in several places in init.py file

line 1085:
return Tuner.URI['SET_FREQ'].fromat(host='{host}', band=band, tuning=tuning, num=num)

line 1103:
return Tuner.URI['RECALL_PRESET'].fromat(host='{host}', zone=zone, band=band, num=num)

line 1130:
return Tuner.URI['STORE_PRESET'].fromat(host='{host}', num=num)

Thanks

General exception handling

Right now I have to check each response for the response status. It would be cool if your class would optionally throw Exceptions bases on RESPONSE_CODE. This would result in a much clearer code at my side. Otherwise I have to implement some kind of wrapper or proxy for your class.

New functions for ISX-18D / ISX-80

Hi,

can you incorporate functions for reading/setting the alarm clock on the ISX series?

What I found out:

/YamahaExtendedControl/v1/clock/getSettings
/YamahaExtendedControl/v1/clock/setAlarmSettings

getSettings returns (e.g.)
{
"alarm":
{
"alarm_on": true, // boolean, on/off
"fade_interval": 180, // seconds between start of {source} and beep, valid 0-180
"fade_type": 1, // don't know
"mode": "oneday", // don't know, can't set via app
"oneday":
{
"beep": true, // switch to beep after {fade_interval}
"enable": true, // alarm is on
"playback_type": "preset",
// this seems a bit complex. playback_type can be either
// - "preset" (choose a preset from netusb source),
// - "resume" (then specify any source),
// - "none" (only beep) or
// - "tuner" (choose a preset from tuner/dab source)
// as yet, I have not seen all source details,
// might need to test this a bit more
"preset": // specifies necessary info for selecting playback mode
{
"netusb_info":
{
"input": "server", // "server" or "net_radio"
"text": "(selected track name)"
// not sure, this seems to be only informational
},
"num": 4, // select preset #
"type": "netusb" // select source for preset (netusb, tuner, ...)
},
"time": "0629" // alarm time as plain string. this is the BEEP time,
// specified playback starts {fade_interval} secs before!
},
"repeat": false, // repeat alarm or one-shot
"volume": 25 // final playback volume, usually 0-60 (depending on zone)
},
"auto_sync": true, // auto-sync device time via musiccast control app
"format": "24h" // time format for display on device, "24h", "12h"
"response_code": 0 // well-known
}

setAlarmSettings (not been able to set via http GET, only POST):
// this can set only alarm_on or set any number of alarm settings (or both)
{
"alarm_on": bool // enable/disable alarm
"detail": // set alarm details
{
"beep": true // finish with beeping on time
"day": "oneday" // don't know, no option in control app
"enable": true // alarm enabled
"fade_interval": 180 // seconds to fade in playback till beep, valid 0-180
"playback_type": "preset"/"resume"
// see explanation above on getSettings
"preset": // if playback_type "preset" selected:
{
"num": 4 // use preset #
"type": "netusb" // source for preset (netusb, tuner, ...?)
}
"resume": // if playback_type "resume" selected:
{
"input": "net_radio" // source for playback resume acc. to device capabilities
}
"snooze": false // enable snooze
"time": "2325" // alarm time (beep!) as plain string
}
"mode": "oneday" // only mode supported?
"repeat": "false" // repeat alarm next day?
"volume": 25 // final playback volume, device/zone dependent (usually 0-60)
}

New version release

Hi

Is it possible to release new version ? Looks like there are some new fixes, after latest version release, and python3 support.

Link musiccast devices

Please support these methods in order to allow linking of devices:

sendHttpGetRequest("http://192.168.1.YYY/YamahaExtendedControl/v1/main/setPower?power=on")
sendHttpPostRequest("http://192.168.1.XXX/YamahaExtendedControl/v1/dist/setServerInfo", "application/json", '{"group_id":"a89b0f9f2d334b63bab6bcc48a0587f0","type":"add","client_list":["192.168.1.YYY"]}')
sendHttpPostRequest("http://192.168.1.YYY/YamahaExtendedControl/v1/dist/setClientInfo", "application/json", '{"group_id":"a89b0f9f2d334b63bab6bcc48a0587f0","zone":["main"],"server_ip_address":"192.168.1.XXX"}')
sendHttpGetRequest("http://192.168.1.XXX/YamahaExtendedControl/v1/dist/startDistribution?num=0")
sendHttpPostRequest("http://192.168.1.XXX/YamahaExtendedControl/v1/dist/setGroupName", "application/json", '{"name": "Salon+Chambre"}')
end

https://community.openhab.org/t/yamaha-musiccast-binding/15060/40

Typo in set_freq tunning argument causes assertion

Hi,
set_freq tunning argument is written with double n (at line 1073)
def set_freq(band, tunning, num):

the argument assertion is written with a single n (at line 1084):
assert tuning in TUNING, 'Invalid TUNING value!'

Which cusses an assertion

Thanks

Play mp3

How can I play some mp3 file from a http server or something like that with this library?

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.