本文整理汇总了Python中soco.discover函数的典型用法代码示例。如果您正苦于以下问题:Python discover函数的具体用法?Python discover怎么用?Python discover使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了discover函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play_spoken_notifications
def play_spoken_notifications(self, notifications=None):
notification_mp3s = []
for notification in notifications:
tts = gTTS(text=notification, lang=self.tts_lang)
now = datetime.datetime.now()
filename = now.strftime('%Y-%m-%d_%H-%M-%S-%f') + ".mp3"
notification_mp3s.append(filename)
tts.save(self.webserver_path + filename)
if notification_mp3s:
group_coordinator = None
for zone in list(soco.discover()):
if zone.group.coordinator.player_name == zone.player_name:
group_coordinator = zone
zone_snapshot = Snapshot(zone)
zone_snapshot.snapshot()
time.sleep(1)
zone.volume = int(self.volume)
for mp3 in notification_mp3s:
self.log.info('Playing notification ' + mp3 + ' on ' + zone.player_name)
zone.play_uri(uri='http://' + Nic().get_current_address() + ':' + self.webserver_port + '/' + mp3)
time.sleep(self.max_notification_seconds)
zone_snapshot.restore()
if group_coordinator is not None:
for zone in list(soco.discover()):
if zone.group.coordinator.player_name != zone.player_name:
print zone.player_name + ' joining ' + zone.group.coordinator.player_name
zone.join(group_coordinator)
return notifications
示例2: discoverAll
def discoverAll():
if len(my_globals["Speakers"]) == 0:
my_globals["Speakers"] = list(soco.discover())
elif my_globals["somethingChange"] == True:
my_globals["somethingChange"] = False
newList = list(soco.discover())
print "Rediscover"
oldList = my_globals["Speakers"]
newNewList = []
for oldItem in oldList:
for newItem in newList:
if newItem == oldItem:
newNewList.append(newItem)
my_globals["Speakers"] = newNewList
else:
pass
示例3: find_controller
def find_controller(name):
for s in list(soco.discover()):
if s.player_name != name:
continue
ip = s.group.coordinator.ip_address
return soco.SoCo(ip)
return None
示例4: _scan_once
def _scan_once(self):
devices = soco.discover()
if devices is None:
return
devices = list(devices)
logging.info('Found %d sonos devices.', len(devices))
for device in devices:
uid = device.uid
self._devices[uid] = device
speaker_info = device.get_speaker_info()
currently_playing = device.get_current_track_info()
current_transport_info = device.get_current_transport_info()
details = {
'uid': uid,
'device_name': speaker_info['zone_name'],
'currently_playing': {k: currently_playing.get(k, None)
for k in CURRENTLY_PLAYING_KEYS},
'state': current_transport_info['current_transport_state'],
}
if self._previous_details.get(uid, None) != details:
self._callback('sonos', 'sonos-%s' % uid, details)
self._previous_details[uid] = details
示例5: __init__
def __init__(self):
self.devs = list(soco.discover())
self.dev = self.devs[0]
self.groups = list(self.dev.all_groups)
self.event_state = State()
self.startEventThreads()
示例6: add_random_file_from_present_folder
def add_random_file_from_present_folder(machine_ip, port, zone_name):
"""Add a random non-py file from this folder and subfolders to soco"""
# Make a list of music files, right now it is done by collection all files
# below the current folder whose extension does not start with .py
# This will probably need to be modded for other pusposes.
music_files = []
print('Looking for music files')
for path, dirs, files in os.walk('.'):
for file_ in files:
if not os.path.splitext(file_)[1].startswith('.py'):
music_files.append(os.path.relpath(os.path.join(path, file_)))
print('Found:', music_files[-1])
random_file = choice(music_files)
# urlencode all the path parts (but not the /'s)
random_file = os.path.join(
*[quote(part) for part in os.path.split(random_file)]
)
print('\nPlaying random file:', random_file)
netpath = 'http://{}:{}/{}'.format(machine_ip, port, random_file)
for zone in soco.discover():
if zone.player_name == zone_name:
break
number_in_queue = zone.add_uri_to_queue(netpath)
zone.play_from_queue(number_in_queue)
示例7: get_options
def get_options(self):
self.display.displayLoadingAnimation()
self.players = {}
for i in soco.discover():
self.players[i.player_name] = i
self.display.stopLoadingAnimation()
return self.players
示例8: scan
def scan():
zones = soco.discover()
print "SONOS" + "\n" + "-----"
for zone in zones:
transport_info = zone.get_current_transport_info()
# zone.get_speaker_info().get('hardware_version')
if True is True:
print "{}: {}, {}, {}, {}, IP={}".format(
zone.uid,
zone.player_name,
transport_info['current_transport_status'],
transport_info['current_transport_state'],
transport_info['current_transport_speed'],
zone.ip_address
)
print "\n" + "YAMAHA" + "\n" + "------"
receivers = rxv.find()
for rx in receivers:
uri = urlparse(rx.ctrl_url)
print "{}: {} ({})\n\t\t{}\n\t\t{}".format(
uri.hostname,
rx.friendly_name,
rx.model_name,
rx.ctrl_url,
rx.basic_status)
示例9: setup_platform
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Sonos platform."""
import soco
import socket
if discovery_info:
add_devices([SonosDevice(hass, soco.SoCo(discovery_info))])
return True
players = None
hosts = config.get('hosts', None)
if hosts:
# Support retro compatibility with comma separated list of hosts
# from config
hosts = hosts.split(',') if isinstance(hosts, str) else hosts
players = []
for host in hosts:
players.append(soco.SoCo(socket.gethostbyname(host)))
if not players:
players = soco.discover(interface_addr=config.get('interface_addr',
None))
if not players:
_LOGGER.warning('No Sonos speakers found.')
return False
add_devices(SonosDevice(hass, p) for p in players)
_LOGGER.info('Added %s Sonos speakers', len(players))
return True
示例10: main
def main():
zones = list(soco.discover())
zones.sort(key = lambda zone: zone.ip_address)
zone = zones[0]
print "Sonos zone: %s" % zone.player_name
monitor = PeakMonitor(SINK_NAME, METER_RATE)
sounding = False
blank_time = 0
for sample in monitor:
if sample > 1:
blank_time = 0
if not sounding:
sounding = True
print "Now sounding"
track = zone.get_current_track_info()
transport = zone.get_current_transport_info()
if transport["current_transport_state"] == "STOPPED" or track["uri"] != RADIO_URI:
print "Tuning in"
zone.play_uri(RADIO_URI)
else:
blank_time += 1
if sounding and blank_time > 5*METER_RATE:
print "Not sounding anymore"
sounding = False
示例11: setup_platform
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Sonos platform. """
import soco
import socket
if discovery_info:
add_devices([SonosDevice(hass, soco.SoCo(discovery_info))])
return True
players = None
hosts = config.get('hosts', None)
if hosts:
players = []
for host in hosts.split(","):
host = socket.gethostbyname(host)
players.append(soco.SoCo(host))
if not players:
players = soco.discover(interface_addr=config.get('interface_addr',
None))
if not players:
_LOGGER.warning('No Sonos speakers found.')
return False
add_devices(SonosDevice(hass, p) for p in players)
_LOGGER.info('Added %s Sonos speakers', len(players))
return True
示例12: get_addr
def get_addr(self,hks):
players = list(soco.discover())
p_name = self.Devices_neu[hks]
for player in players:
if player._player_name == p_name:
ip = player.ip_address
uid = player.uid
return ip, uid, p_name
示例13: user_select_zone
def user_select_zone(self):
# get user input if no zone name defined
zone_names = [zone.player_name for zone in soco.discover()]
print zone_names
self.cfg['desired_zone'] = raw_input('Which zone would you like to troll?\n')
if not self.cfg['desired_zone'] in list(zone_names):
print self.cfg['desired_zone'], 'is not an option'
self.cfg['desired_zone'] = None
示例14: zones
def zones(self):
if not self.__zone_ip:
if not self._zones:
self._zones = soco.discover(timeout=5)
else:
logging.info("Discovering with custom IP")
self._zones = [soco.SoCo(self.__zone_ip)]
return self._zones
示例15: configure_sonos
def configure_sonos(config):
import soco
sonos = soco.discover()
config.registry['sonos'] = sonos
config.add_request_method(
lambda r: r.registry['sonos'],
'sonos',
property=True
)