本文整理汇总了Python中soco.discover函数的典型用法代码示例。如果您正苦于以下问题:Python discover函数的具体用法?Python discover怎么用?Python discover使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了discover函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:jalieven,项目名称:homification,代码行数:31,代码来源:sonos.py
示例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
开发者ID:tpulatha,项目名称:SonosWallController,代码行数:16,代码来源:soco_wrapper.py
示例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
开发者ID:RJ,项目名称:sonos-shipping-forecast,代码行数:7,代码来源:sonosforecast.py
示例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
开发者ID:tomwilkie,项目名称:awesomation,代码行数:28,代码来源:sonos.py
示例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()
开发者ID:bosim,项目名称:socompd,代码行数:7,代码来源:__init__.py
示例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)
开发者ID:DPH,项目名称:SoCo,代码行数:27,代码来源:play_local_files.py
示例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
开发者ID:baryon5,项目名称:homectrl,代码行数:7,代码来源:sonos.py
示例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)
开发者ID:axontrust,项目名称:sonos-yamaha-monitor,代码行数:28,代码来源:sonos-yamaha-monitor.py
示例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
开发者ID:Cinntax,项目名称:home-assistant,代码行数:31,代码来源:sonos.py
示例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
开发者ID:arun3528,项目名称:sonoscast,代码行数:28,代码来源:monitor.py
示例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
开发者ID:FanaHOVA,项目名称:home-assistant,代码行数:29,代码来源:sonos.py
示例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
开发者ID:chrihuc,项目名称:steuerzentrale,代码行数:8,代码来源:cmd_sonos.py
示例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
开发者ID:dylancaponi,项目名称:sonos-trollbot,代码行数:8,代码来源:main.py
示例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
开发者ID:YoSmudge,项目名称:sonosalarm,代码行数:8,代码来源:discovery.py
示例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
)
开发者ID:yoshrote,项目名称:smart_home,代码行数:9,代码来源:__init__.py
示例16: discoverer
def discoverer(self):
def addOrReplaceZone(zone):
if zone.player_name in self.zones:
if zone.ip_address != self.zones[zone.player_name].ip_address:
with self.zlock:
self.zones.pop(zone.player_name)
self.logger.debug("Replacing: %s"%zone.player_name)
else:
self.logger.debug("Unchanged: %s"%zone.player_name)
return
else:
self.logger.info("Adding: %s"%zone.player_name)
with self.zlock:
self.zones[zone.player_name] = zone
def removeZone(zone_name):
if zone_name in self.zones:
with self.zlock:
self.zones.pop(zone_name)
self.logger.info("Expiring: %s"%zone_name)
while not self.quit:
zones_needed = list(self.needed_zones)
self.logger.debug("Need to find these zones: %s" %zones_needed)
zones_discovered = discover(10)
for z in list(zones_discovered):
addOrReplaceZone(z)
try:
zones_needed.remove(z.player_name)
except ValueError:
self.logger.debug("Did not want: %s" %z.player_name)
for z in zones_needed:
removeZone(z)
if len(zones_needed) > 0:
self.logger.warning("Missing zones: %s" % zones_needed)
self.logger.warning("New attempt in 5 sec...")
for x in range(0,5):
if self.quit:
break
sleep(1)
else:
self.logger.debug("Found all needed zones: %s" %self.zones.keys())
self.logger.debug("New check in 60 sec...")
for x in range(0,60):
if self.quit:
break
sleep(1)
开发者ID:TrondKjeldas,项目名称:knxsonos,代码行数:57,代码来源:sonos.py
示例17: _sonos_refresh
def _sonos_refresh():
global coordinator
groups.clear()
speakers = soco.discover()
if speakers:
for speaker in speakers:
groups[speaker.group.coordinator].append(speaker)
coordinator = None if len(groups) != 1 else groups.keys()[0]
return bool(speakers)
开发者ID:mc706,项目名称:SlackBot,代码行数:9,代码来源:sonos.py
示例18: discover_target_sonos_player
def discover_target_sonos_player(target_name):
zones = soco.discover()
if zones == None:
print "No Sonos players discovered on this network."
else:
for zone in zones:
if zone.player_name == target_name:
return zone
raise UndiscoverablePlayerError(target_name)
开发者ID:KeanWong,项目名称:dash-sonos-stream,代码行数:10,代码来源:print_current_uri.py
示例19: get_device_list
def get_device_list(cls, retries_remaining=3):
try:
devices = list(soco.discover())
assert len(devices) > 0
return devices
except (AssertionError, TypeError):
if retries_remaining > 0:
return cls.get_device_list(retries_remaining - 1)
else:
raise
开发者ID:TySkby,项目名称:sonos-suite,代码行数:10,代码来源:device_manager.py
示例20: startSonos
def startSonos(self, speaker):
# Sonos setup
MusicLogging.Instance().info("Connecting to Sonos...")
self.speakers = soco.discover()
try:
self.sonosDevice = soco.discovery.by_name(speaker)
except:
self.sonosDevice = self.speakers.pop()
return True
开发者ID:clemenstyp,项目名称:music-on-blocks,代码行数:10,代码来源:sonosController.py
注:本文中的soco.discover函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论