# Path: pulseaudio/ffmpeg2pa.py
# class AudioPlay(object):
#     """
#     Wraps a binary ffmpeg and pacat executable
#     """
#     def __init__(self, ffmpeg_exe_file, device_option, volume=65536):
#         self._FfmpegProc = self._PacatProc = None
#         self._FfmpegCmd = "%s  -hide_banner -loglevel panic -i %s -acodec pcm_s16le -f s16le -ac 1 -ar 16k -" %(ffmpeg_exe_file, '%s')
#         self._PacatCmd = "pacat --format=s16le --rate=16000 --channels=1 %s %s" %(device_option, '%s')
#         self._volume = volume
# 
#     def play(self, audiofile):
#         volume_option = "--volume=%d" %(self._volume)
#         FfmpegArgv = shlex.split(str(self._FfmpegCmd % (audiofile)))
#         PacatArgv = shlex.split(str(self._PacatCmd) % (volume_option))
# 
#         if self._FfmpegProc is not None and self._FfmpegProc.poll() is None:
#             self._FfmpegProc.terminate()
#         if self._PacatProc is not None and self._PacatProc.poll() is None:
#             self._PacatProc.terminate()
# 
#         self._FfmpegProc = Popen(FfmpegArgv, stdin=PIPE, stdout=PIPE)
#         self._PacatProc = Popen(PacatArgv, stdin=self._FfmpegProc.stdout)
# 
#     def stop(self):
#         if self._FfmpegProc is not None and self._FfmpegProc.poll() is None:
#             self._FfmpegProc.stdin.write(b'q')
#             self._FfmpegProc.stdin.flush()
# 
#     def set_volume(self, volume):
#         self._volume = volume
# 
#     @property
#     def volume(self):
#         return self._volume
# 
#     @property
#     def is_running(self):
#         return self._PacatProc is not None and self._PacatProc.poll() is None
# 
# Path: pulseaudio/const.py
# DOMAIN = "pulseaudio"
# 
# CONF_SINK = 'sink'
# 
# DEFAULT_NAME = 'Pulse Audio Speaker'
# 
# DEFAULT_SINK = 'default'


import voluptuous as vol
import logging
import asyncio
import homeassistant.helpers.config_validation as cv
from homeassistant.components.media_player.const import (
    MEDIA_TYPE_MUSIC,
    SUPPORT_BROWSE_MEDIA,
    SUPPORT_PLAY,
    SUPPORT_PLAY_MEDIA,
    SUPPORT_VOLUME_SET,
)
from homeassistant.components.media_player import (
    BrowseMedia,
    async_process_play_media_url,
    MediaPlayerEntity,
    PLATFORM_SCHEMA)
from homeassistant.const import (
    CONF_NAME, STATE_IDLE, STATE_PLAYING)
from homeassistant.components.ffmpeg import DATA_FFMPEG
from homeassistant.components import media_source
from .ffmpeg2pa import AudioPlay
from .const import (
    DOMAIN,
    CONF_SINK,
    DEFAULT_NAME,
    DEFAULT_SINK,
)
"""
Support for PulseAudio speakers(sinks)

"""
from __future__ import annotations





SUPPORT_PULSEAUDIO = (
    SUPPORT_PLAY
    | SUPPORT_PLAY_MEDIA
    | SUPPORT_VOLUME_SET
    | SUPPORT_BROWSE_MEDIA
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,

# Path: pulseaudio/ffmpeg2pa.py
# class AudioPlay(object):
#     """
#     Wraps a binary ffmpeg and pacat executable
#     """
#     def __init__(self, ffmpeg_exe_file, device_option, volume=65536):
#         self._FfmpegProc = self._PacatProc = None
#         self._FfmpegCmd = "%s  -hide_banner -loglevel panic -i %s -acodec pcm_s16le -f s16le -ac 1 -ar 16k -" %(ffmpeg_exe_file, '%s')
#         self._PacatCmd = "pacat --format=s16le --rate=16000 --channels=1 %s %s" %(device_option, '%s')
#         self._volume = volume
# 
#     def play(self, audiofile):
#         volume_option = "--volume=%d" %(self._volume)
#         FfmpegArgv = shlex.split(str(self._FfmpegCmd % (audiofile)))
#         PacatArgv = shlex.split(str(self._PacatCmd) % (volume_option))
# 
#         if self._FfmpegProc is not None and self._FfmpegProc.poll() is None:
#             self._FfmpegProc.terminate()
#         if self._PacatProc is not None and self._PacatProc.poll() is None:
#             self._PacatProc.terminate()
# 
#         self._FfmpegProc = Popen(FfmpegArgv, stdin=PIPE, stdout=PIPE)
#         self._PacatProc = Popen(PacatArgv, stdin=self._FfmpegProc.stdout)
# 
#     def stop(self):
#         if self._FfmpegProc is not None and self._FfmpegProc.poll() is None:
#             self._FfmpegProc.stdin.write(b'q')
#             self._FfmpegProc.stdin.flush()
# 
#     def set_volume(self, volume):
#         self._volume = volume
# 
#     @property
#     def volume(self):
#         return self._volume
# 
#     @property
#     def is_running(self):
#         return self._PacatProc is not None and self._PacatProc.poll() is None
# 
# Path: pulseaudio/const.py
# DOMAIN = "pulseaudio"
# 
# CONF_SINK = 'sink'
# 
# DEFAULT_NAME = 'Pulse Audio Speaker'
# 
# DEFAULT_SINK = 'default'


# Path: pulseaudio/media_player.py
import voluptuous as vol
import logging
import asyncio
import homeassistant.helpers.config_validation as cv
from homeassistant.components.media_player.const import (
    MEDIA_TYPE_MUSIC,
    SUPPORT_BROWSE_MEDIA,
    SUPPORT_PLAY,
    SUPPORT_PLAY_MEDIA,
    SUPPORT_VOLUME_SET,
)
from homeassistant.components.media_player import (
    BrowseMedia,
    async_process_play_media_url,
    MediaPlayerEntity,
    PLATFORM_SCHEMA)
from homeassistant.const import (
    CONF_NAME, STATE_IDLE, STATE_PLAYING)
from homeassistant.components.ffmpeg import DATA_FFMPEG
from homeassistant.components import media_source
from .ffmpeg2pa import AudioPlay
from .const import (
    DOMAIN,
    CONF_SINK,
    DEFAULT_NAME,
    DEFAULT_SINK,
)

"""
Support for PulseAudio speakers(sinks)

"""
from __future__ import annotations





SUPPORT_PULSEAUDIO = (
    SUPPORT_PLAY
    | SUPPORT_PLAY_MEDIA
    | SUPPORT_VOLUME_SET
    | SUPPORT_BROWSE_MEDIA
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,

    vol.Optional(CONF_SINK, default=DEFAULT_SINK): cv.string,