Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aiopioneer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aiopioneer

Asyncio Python library for controlling a Pioneer AVR via its API

  • 0.7.1
  • PyPI
  • Socket score

Maintainers
1

aiopioneer

Python library for controlling a Pioneer AVR via its built-in API.

Used by the pioneer_async integration for Home Assistant, which was inspired by the original Pioneer Home Assistant integration. Originally developed and tested on a VSX-930 (Main Zone and HDZone outputs) but has since been tested on a larger set of models by the community.

Features

  • Implemented in asyncio.
  • Maintains single continuous telnet session to AVR, with automatic reconnect.
  • Eliminates status polling where AVR sends keepalive responses (on port 8102).
  • Auto-detects Zones 1, 2, 3 and HDZONE.
  • Ignore specific zones, for AVRs that report phantom zones.
  • Automatically polls AVR for source names - no longer need to manually code them in your config any more if your AVR supports their retrieval. Can also set source names manually.
  • Queries device parameters: MAC address, software version, model.
  • Ability to set internal parameters to change the API functionality, eg. maximum volume, volume step change delta.
  • Defaults for internal parameters can be changed based on custom profiles based on AVR model.
  • Includes workaround for AVRs with an initial volume set on the Main Zone (eg. VSX-930).
  • Supports AVRs that do not support setting the volume level by emulating using up/down commands (eg. VSX-S510).
  • Command line client for sending commands and testing
  • Supports all listening mode functions
  • Supports all video related functions
  • Supports panel and remote locking
  • Supports most AMP related functions
  • Supports all tone functions
  • Supports most zone power functions
  • Supports all zone input functions
  • Supports all zone volumne and mute functions
  • Supports setting of tuner band and preset
  • Supports setting frequency directly for capable AVRs, and also by stepping the frequency up/down

Params

There are several types of parameters that modify the library's functionality. These are listed below in order of increasing priority:

  • Default parameters: these are the defaults for all of the parameters
  • Model parameters: these parameters are determined by the AVR model as detected by the library. Custom profiles for specific AVR models are defined in `aiopioneer/param.py
  • User parameters: these parameters are provided by the user at instantiation, and can also be updated via the set_user_params method
  • System parameters: these parameters are set by the library at run time

Where a parameter is specified at more than one level, the higher priority parameter takes precedence. So a user specified parameter will override any value that is determined by the AVR model.

NOTE: YAML syntax is used in the table below. Use Python equivalents (false -> False, true -> True, null -> None etc.) when calling the Python API directly, and JSON syntax if manually specifying via the Home Assistant integration.

NameTypeDefaultDescription
ignored_zoneslist[]List of zones to ignore even if they are auto-discovered. Specify Zone IDs as strings: "1", "2", "3" and "Z".
command_delayfloat0.1Insert a delay between sequential commands that are sent to the AVR. This appears to make the AVR behave more reliably during status polls. Increase this value if debug logging shows that your AVR times out between commands.
max_source_idint60Maximum source ID that the source discovery queries. Reduce this if your AVR returns errors.
max_volumeint185Maximum volume for the Main Zone.
max_volume_zonexint185Maximum volume for zones other than the Main Zone.
power_on_volume_bounceboolfalseOn some AVRs (eg. VSX-930) where a power-on is set, the initial volume is not reported by the AVR correctly until a volume change is made. This option enables a workaround that sends a volume up and down command to the AVR on power-on to correct the reported volume without affecting the power-on volume.
volume_step_onlyboolfalseOn some AVRs (eg. VSX-S510), setting the volume level is not supported natively by the API. This option emulates setting the volume level using volume up and down commands.
ignore_volume_checkboolfalseDon't check volume when determining whether a zone exists on the AVR. Useful for AVRs with an HDZone that passes through audio.
zone_1_sourceslist[](>0.4) Customises the available sources for use with Zone 1. Defaults to all available sources.
zone_2_sourceslistsee sourceCustomises the available sources for use with Zone 2 (some AVRs do not support all sources).
zone_3_sourceslistsee sourceCustomises the available sources for use with Zone 3 (some AVRs do not support all sources).
hdzone_sourceslistsee sourceCustomises the available sources for use with HDZone (some AVRs do not support all sources).
hdzone_volume_requirementslist["13", "15", "05", "25"]A list of sources that HDZone must be set to for volume control, some AVRs do not support HDZone volume at all (see ignore_volume_check above) and some only allow control of certain sources.
amp_speaker_system_modesdict....Customises the names of speaker system modes. Different generations of AVR will name zones slighty differently. For example, the SC-LX57 names speaker system mode 15 as 5.1ch Bi-Amp + ZONE2 however this can also be called 5.2ch Bi-Amp + HDZONE on newer AVRs.
extra_amp_listening_modesdictsee source(>0.5) Additional listening modes that are added to the list of all possible listening modes for the AVR. This list is used to decode the listening mode ID returned by the AVR. See the source for the format for listening mode definition.
enabled_amp_listening_modeslist[](>0.5) A list of listening mode IDs to be made available for selection. If specified, then no listening mode IDs will be included by default. All enabled source names must be unique, and duplicated names are ignored. The additional listening modes must be actually supported by the AVR, and will return an error (usually E02) when an unsupported listening mode is selected. This list is predefined for some AVRs, and specifying this parameter manually will override the model specific default disable list.
disabled_amp_listening_modeslist[]A list of listening mode IDs to be disabled. Listening mode IDs that are also specified in enabled_amp_listening_modes will be disabled. This list is predefined for some AVRs, and specifying this parameter manually will override the model specific default disable list.
video_resolution_modeslist['0', '1', '3', '4', '5', '6', '7', '8', '9']Sets the available video resolutions. Not all AVRs support the same resolution settings. This defaults to all of the latest resolutions from FY16.
mhl_sourcestringnullSets the MHL source ID. This is used for media controls. This information cannot be queried automatically
enabled_functionslist["amp", "dsp", "tuner", "tone", "channels", "video", "system", "audio"]Change the functions that are enabled by the API, adding more functions will increase the amount of time it takes to complete a full init and update.
disable_auto_queryboolfalseSetting to true will disable auto queries on init for all functions apart from basic functionality (power, source, volume and mute). If you only need those functions, you can set this to true
am_frequency_stepintnullOptional setting to configure the AM frequency step. If this is set to null, a function is queued to detect this information by stepping up and down the frequency when the tuner is first used while set to AM.
debug_listenerboolfalseEnables additional debug logging for the listener task.
debug_responderboolfalseEnables additional debug logging for the responder task.
debug_updaterboolfalseEnables additional debug logging for the updater task.
debug_commandboolfalseEnables additional debug logging for commands sent and responses received.

If your model of AVR always needs specific parameters to be set for the library to function properly, then please create a PR to add a custom profile for the AVR model.

Python API

The library exposes a Python API through the PioneerAVR class. The class methods are listed below:

Connection methods

PioneerAVR.__init__(host, port = DEFAULT_PORT, timeout: float = DEFAULT_TIMEOUT, scan_interval: int = DEFAULT_SCAN_INTERVAL, params: dict[str, str] = None )

Constructor for the PioneerAVR class. The connection parameters are used when PioneerAVR.connect is called. After connection is established, the AVR will be polled every scan_interval seconds. Optional user parameters are provided via params.

awaitable PioneerAVR.connect(reconnect: bool = True)

Establish a connection to the AVR. Set reconnect to True to attempt to re-establish the connection on disconnect.

awaitable PioneerAVR.disconnect()

Disconnect from the AVR. Attempt to re-establish the connection if enabled.

awaitable PioneerAVR.shutdown()

Permanently disconnect from the AVR. Does not attempt reconnection.

awaitable PioneerAVR.set_timeout(timeout: float)

Set command timeout. Used also to set the socket keepalive timeout.

Update methods

awaitable PioneerAVR.update(full: bool = False, wait: bool = True)

Request an update of the AVR, and wait for the update to complete if wait is True.
If full is True, then a full update is performed irrespective of when the previous update was performed. Otherwise, an update is performed if the scan interval has elapsed.
If a scan interval is set, then an update is scheduled in the updater task. Otherwise the update is performed synchronously (wait cannot be set to False in this case).

awaitable PioneerAVR.set_scan_interval(scan_interval: int)

Set the scan interval to scan_interval and restart the updater task.

awaitable PioneerAVR.update_zones()

Update zones from ignored_zones parameter and re-query zones from the AVR.

AVR system methods

awaitable PioneerAVR.turn_on(zone: Zones = Zones.Z1):

Turn on the Pioneer AVR zone.

awaitable PioneerAVR.turn_off(zone: Zones = Zones.Z1):

Turn off the Pioneer AVR zone.

awaitable PioneerAVR.query_device_info()

Query the AVR for device information. Updates the model parameters if device model is changed.

awaitable PioneerAVR.query_zones(force_update: bool = True)

Query the AVR for available zones by querying the power status for each zone and checking if the AVR responds. Ignores zones listed in the ignored_zones parameter.
If the ignore_volume_check parameter is not set, then additionally query the zone volume as well.

awaitable PioneerAVR.set_panel_lock(panel_lock: str):

Set the panel lock.

awaitable PioneerAVR.set_remote_lock(remote_lock: bool):

Set the remote lock.

awaitable PioneerAVR.set_dimmer(dimmer: str, zone: Zones = Zones.Z1):

Set the display dimmer.

AVR source methods

awaitable PioneerAVR.select_source(source: str = None, source_id: str = None, zone: Zones = Zones.Z1):

Set the input source for zone to name source_name or ID source_id (requires one argument.)

awaitable PioneerAVR.build_source_dict()

Query the available sources names from the AVR.
Parameter max_source_id determines the highest source ID that is queried.

PioneerAVR.set_source_dict(sources: dict[str, str])

Manually set the available sources to the dict sources, where the keys are source IDs (padded to 2 chars) and the values are the corresponding source names.

PioneerAVR.get_source_list(zone: Zones = Zones.Z1) -> list[str]

Return the set of currently available source names for zone. The source names can be used with the select_source method.

PioneerAVR.get_source_dict(zone: Zones = None) -> dict[str, str]

Return a dict of currently available source names to source ID mappings for zone.
If zone is None, then return the dict of all available source names to source ID mappings.

PioneerAVR.get_source_name(source_id: str) -> str

Return the source name for source_id.

awaitable PioneerAVR.set_source_name(source_id: str, source_name: str = "", default: bool = False) -> bool

Renames source_id to source_name on the AVR.
If default is True, reset source_id to the default source name.

PioneerAVR.clear_source_id(source_id: str)

Clear the name mapping for source_id.

AVR command methods

awaitable PioneerAVR.send_command(command: str, zone: Zones = Zones.Z1, prefix: str = "", suffix: str = "", _ignore_erro* = None, rate_limit: bool = True) -> bool | None

Send command command for zone zone to the AVR, prefixed with prefix and/or suffixed with suffix if specified.
If command does not generate a response, then returns True if the command was successfully sent. Otherwise, returns the response received from the AVR, None if timed out, or False if an error response was received.
If ignore_error is None (default), then raise an exception on error. If ignore_error is True, then log the error as level debug, otherwise log the error as level error.
Raises AVRResponseTimeoutError on timeout, and AVRCommandError if the request returned an error.
If rate_limit is True, then rate limit the commands sent to the AVR in accordance with the command_delay parameter.

PioneerAVR.queue_command(command: str, skip_if_queued: bool = True, insert_at: int = -1) -> None

Add command to the command queue, to to be sent in the background to the AVR when method command_queue_schedule is invoked. Insert the command at queue position insert_at if specified (inserts at end of the queue by default).

awaitable PioneerAVR.send_raw_command(command: str, rate_limit: bool = True)

Send a raw command command to the AVR. If rate_limit is True, then rate limit the commands sent to the AVR in accordance with the command_delay parameter.

awaitable PioneerAVR.send_raw_request(command: str, response_prefix: str, rate_limit: bool = True) -> str | bool | None

Send a raw command command to the AVR and wait for a response with prefix response_prefix. Returns the response received from the AVR.
Raises AVRResponseTimeoutError on timeout, and AVRCommandError if the request returned an error.
If rate_limit is True, then rate limit the commands sent to the AVR in accordance with the command_delay parameter.

AVR tuner methods

awaitable PioneerAVR.select_tuner_band(band: TunerBand = TunerBand.FM) -> bool

Set the tuner band to band.

awaitable PioneerAVR.set_tuner_frequency(band: TunerBand, frequency: float = None) -> bool

Set the tuner band to band and tuner frequency to frequency. Step the frequency up or down if it cannot be set directly.

awaitable PioneerAVR.select_tuner_preset(tuner_class: str, preset: int) -> bool:

Select the tuner preset preset in class tuner_class.

awaitable PioneerAVR.tuner_previous_preset()

Select the previous tuner preset.

awaitable PioneerAVR.tuner_next_preset()

Select the next tuner preset.

AVR audio/video methods

awaitable PioneerAVR.select_listening_mode(mode_name: str = None, mode_id: str = None) -> bool

Set the listening mode to name mode_name, or ID mode_id (requires one argument.) Must be a listening mode valid for the current sound input as returned by get_listening_modes.

PioneerAVR.get_listening_modes() -> dict[str, str] | None

Return dict of valid listening mode mapping to names for the AVR.

awaitable PioneerAVR.set_volume_level(target_volume: int, zone: Zones = Zones.Z1)

Set the volume level for zone zone to target_volume. target_volume must be between 0 and 185 inclusive for Zone 1, and between 0 and 81 inclusive for all other zones.

awaitable PioneerAVR.mute_on(zone: Zones = Zones.Z1) -> bool

Turn mute on for zone zone.

awaitable PioneerAVR.mute_off(zone: Zones = Zones.Z1) -> bool

Turn mute off for zone zone.

awaitable PioneerAVR.set_tone_settings(tone: str = None, treble: int = None, bass: int = None, zone: Zones = Zones.Z1 )*

Set the tone settings for zone zone to tone. When tone is set to On, treble specifies the treble and bass specifies the bass.

awaitable PioneerAVR.set_amp_settings(speaker_config: str = None, hdmi_out: str = None, hdmi_audio_output: bool = None, pqls: bool = None, amp: str = None, zone: Zones = Zones.Z1) -> bool

Set amplifier function settings for zone zone.

PioneerAVR.get_ipod_control_commands() -> list[str]

Return a list of all valid iPod control modes.

PioneerAVR.get_tuner_control_commands() -> list[str]

Return a list of all valid tuner control commands.

PioneerAVR.get_supported_media_controls(zone: Zones) -> list[str]

Return a list of all valid media control actions for zone zone. Return None if the provided zone source is not currently compatible with media controls.

awaitable PioneerAVR.set_channel_levels(channel: str, level: float, zone: Zones = Zones.Z1) -> bool

Set the level (gain) for amplifier channel in zone zone.

awaitable PioneerAVR.set_video_settings(zone: Zones, **arguments) -> bool

Set video settings for zone zone.

awaitable PioneerAVR.set_dsp_settings(zone: Zones, **arguments) -> bool

Set the DSP settings for the amplifier for zone zone.

awaitable PioneerAVR.media_control(action: str, zone: Zones = Zones.Z1) -> bool

Perform media control activities such as play, pause, stop, fast forward or rewind.

AVR zone callback methods

PioneerAVR.set_zone_callback(zone: Zones, callback: Callable[..., None])

Register callback callback for zone zone.

PioneerAVR.clear_zone_callbacks()

Clear callbacks for all zones.

Param methods

PioneerAVR.set_user_params(params: dict[str, Any] = None) -> None

Set user parameters and update current parameters.

PioneerAVR.get_param(param_name: str) -> Any

Get the value of the specified parameter.

PioneerAVR.get_params() -> dict[str, Any]

Get a copy of all current parameters.

PioneerAVR.get_user_params() -> dict[str, Any]

Get a copy of user parameters.

PioneerAVR.get_default_params() -> dict[str, Any]

Get a copy of current default parameters.

Attributes

Listed below are the public attributes of a PioneerAVR object. Use a Zones enum to access zone specific attributes for those that are indexed by zone.

AttributeTypeDescription
scan_intervalintNumber of seconds between polls for AVR full updates
modelstr | NoneModel number returned by the AVR
software_versionstr | NoneSoftware version returned by the AVR
mac_addrstr | NoneSystem MAC address returned by the AVR
availableboolWhether integration is connected to the AVR
initial_updatebool | NoneSet to False if the initial update has been deferred due to the AVR main zone being powered off when initially connected, and True when the update has been completed
zoneslist[Zones]List of all zones detected on the AVR
powerdict[Zones, bool]Power status for each detected zone
volumedict[Zones, int]Volume status for each detected zone
max_volumedict[Zones, int]Maximum valid volume for each detected zone
mutedict[Zones, bool]Mute status for each detected zone
sourcedict[Zones, str]Active source for each detected zone
listening_modestrName of the currently active listening mode
listening_mode_rawstrID of the currently active listening mode
media_control_modedict[Zones, str]Media control mode for each detected zone
toneTone attributes for each detected zone
ampCurrent AVR amp attributes
tunerCurrent AVR tuner attributes
channel_levelsdict[str, Any]Current AVR channel levels, indexed by channel name
dspCurrent AVR DSP attributes
videoCurrent AVR video parameters
audioCurrent AVR audio parameters
systemAVR system attributes

Command line interface (CLI) (>= 0.1.3, CLI arguments >= 0.3)

A very simple command line interface aiopioneer is available to connect to the AVR, send commands and receive responses. It can be used to test the capabilities of the library against your specific AVR.

On Home Assistant, you can run the CLI when the pioneer_async Home Assistant integration has been installed. On Home Assistant Supervised or Container, start the CLI from within the HA container: docker exec -it homeassistant aiopioneer.

Invoke the CLI with the following arguments:

ArgumentDefaultDescription
hostnamerequiredhostname for AVR connection
-p
--port
8102port for AVR connection
+Q
--no-query-device-info
Noneskip AVR device info query
+Z
--no-query-zones
Noneskip AVR zone query

The CLI accepts all API commands, as well as the following:

CommandArgumentDescription
exit or quitExit the CLI.
zonezoneChange current zone to zone.
log_levellog_levelChange debug level to log_level. Valid log levels are: debug, info, warning, error, critical.
updateRequest update of AVR. An update is scheduled in the updater task if a scan interval is set, if it is not set then the update is performed synchronously.
update_fullRequest a full update of AVR irrespective of when the previous update was performed. An update is scheduled in the updater task if a scan interval is set, if it is not set then the update is performed synchronously.
query_device_infoQuery the AVR for device information.
query_zonesQuery the AVR for available zones. Ignore zones specified in parameter ignored_zones (list).
build_source_dictQuery the sources from the AVR.
set_source_dictsources (JSON)Manually set the sources to sources.
get_source_listReturn the current set of available source names that can be used with the select_source command.
get_zone_listening_modes(>0.5) Return the current set of available listening modes.
get_paramsReturn the currently active set of parameters.
get_user_paramsReturn the currently active set of user parameters.
set_user_paramsparams (JSON)Set the user parameters to params.
get_toneReturns the current AVR tone attributes.
get_ampReturns the current AVR amp attributes.
get_tunerReturns the current AVR tuner attributes.
get_channel_levelsReturns the current AVR channel levels.
get_dspReturns the current AVR DSP attributes.
get_videoReturns the current AVR video parameters.
get_audioReturns the current AVR audio parameters.
get_systemReturns the AVR system attributes.
debug_listenerstate (bool)Enable/disable the debug_listener parameter.
debug_responderstate (bool)Enable/disable the debug_responder parameter.
debug_updaterstate (bool)Enable/disable the debug_updater parameter.
debug_commandstate (bool)Enable/disable the debug_command parameter.
set_scan_intervalscan_interval (float)Set the scan interval to scan_interval.
get_scan_intervalReturn the current scan interval.
set_volume_levelvolume_level (int)Set the volume level for the current zone.
select_sourcesource_nameSet the input source for the current zone.
select_listening_modelistening_mode(>0.5) Set the listening mode to the specified mode.
set_tuner_frequencyband frequencySet the tuner band and (optionally) frequency.
tuner_previous_presetSelect the previous tuner preset
tuner_next_presetSelect the next tuner preset
send_raw_command or >raw_commandSend the raw command raw_command to the AVR.

NOTE: The CLI interface may change in the future, and should not be used in scripts. Use the Python API instead.

Source list

The list below shows the source ID that corresponds to each AVR source:

IDDefault Name
25BD
04DVD
06SAT/CBL
10VIDEO
15DVR/BDR
19HDMI 1
20HDMI 2
21HDMI 3
22HDMI 4
23HDMI 5
24HDMI 6
34HDMI 7
49GAME
26NETWORK (cyclic)
38INTERNET RADIO
53Spotify
41PANDORA
44MEDIA SERVER
45FAVORITES
17iPod/USB
05TV
01CD
13USB-DAC
02TUNER
00PHONO
12MULTI CH IN
33BT AUDIO
31HDMI (cyclic)
46AirPlay (Information only)
47DMR (Information only)

Breaking changes

0.7

  • Most PioneerAVR methods now raise exceptions derived from PioneerError when an error is encountered, rather than returning false, None or similar error value. Some instances that currently raise ValueError or SystemError will also raise PioneerError subclasses in the near future
  • send_raw_request no longer accepts an argument ignore_error and will always raise exceptions on error. Use ignore_error with send_command to have exceptions handled for you
  • asyncio yields have been optimised and minimised, which may cause certain sequences of operations to happen in a different order

0.6

  • Python requirement bumped to 3.11 for StrEnum
  • Zones enum now used on all methods accepting zone arguments (except in params)
  • Zone argument removed from tuner methods as tuner is independent of zone
  • TunerBand enum now used to specify a tuner band
  • update now waits for the update to finish by default
  • set_tuner_preset has been renamed to select_tuner_preset
  • get_zone_listening_modes has been renamed to get_listening_modes
  • set_listening_mode has been renamed to select_listening_mode
  • tuner_*, get_zone_listening_modes, set_panel_lock, set_remote_lock and set_dimmer methods no longer accept a zone argument
  • The suffix argument of the send_command method has been reordered after the prefix argument
  • Response codes marked --- now return None
  • Dimmer mode, tone mode and dB strings have been updated

0.5

  • get_sound_modes was renamed to get_zone_listening_modes to reflect Pioneer AVR terminology
  • disable_autoquery was renamed disable_auto_query to better match the underlying variable name
  • amplifier_speaker_system_modes and disabled_amplifier_listening_modes were shortened to amp_speaker_system_modes and disabled_amp_listening_modes respectively

0.4

  • zone_z_sources was renamed hdzone_sources for even more consistency

0.3

  • zone_h_sources was renamed zone_z_sources for consistency

0.2

  • volume_step_delta has been removed entirely
  • By default, a number of additional queries are sent at module startup to the AVR to gather amp, tuner and channel levels attributes. If your AVR does not handle these additional queries well, they can be disabled by setting parameter disable_autoquery to true

0.1

  • _PioneerAVR.__init__() no longer accepts command_delay, volume_workaround and volume_steps arguments. Configure these parameters using the equivalent PARAM_* keys in the params dict, passed in via the constructure or set via set_user_params()

References

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc