Exemple #1
0
def get_play_state(heosobj, command, data):
    """CLI 4.2.3"""

    parts = get_message_parts(data, ['pid', 'state'])

    if 'pid' in parts.keys():
        pid = parts['pid']
    else:
        raise HEOSException(message='Response does not contain PID, aborting')

    if 'state' in parts.keys():
        state = parts['state']
    else:
        raise HEOSException(
            message='Response does not contain state, aborting')

    if state not in ['play', 'pause', 'stop']:
        raise HEOSException(
            message='Invalid play state received: {}'.format(state))

    try:
        attrname = "_play_states['" + pid + "']"
        setattr(heosobj, attrname, state)
    except:
        e = sys.exc_info()
        raise HEOSException(message=e[1] + ": " + e[2])
Exemple #2
0
def get_play_mode(heosobj, command, data):
    """CLI 4.2.13"""

    parts = get_message_parts(data, ['pid', 'repeat', 'shuffle'])

    if 'pid' in parts.keys():
        pid = parts['pid']
    else:
        raise HEOSException(message='Response does not contain PID, aborting')

    if 'repeat' in parts.keys():
        repeat_status = parts['repeat']
    else:
        raise HEOSException(
            message='Response does not contain repeat, aborting')

    if 'shuffle' in parts.keys():
        shuffle_status = parts['shuffle']
    else:
        raise HEOSException(
            message='Response does not contain shuffle, aborting')

    if repeat_status not in ['on', 'off']:
        raise HEOSException(
            message='Illegal repeat state received: {}'.format(repeat_status))

    if shuffle_status not in ['']:
        raise HEOSException(message='Illegal shuffle state received: {}'.
                            format(shuffle_status))
Exemple #3
0
def volume_up(heosobj, command, data):
    """CLI 4.2.8"""

    parts = get_message_parts(data, ['pid', 'step'])

    if 'pid' in parts.keys():
        pid = parts['pid']
    else:
        raise HEOSException(message='Response does not contain PID, aborting')

    if 'step' in parts.keys():
        step_level = parts['step']
    else:
        raise HEOSException(
            message='Response does not contain volume level, aborting')
Exemple #4
0
def heart_beat(heosobj, command, data):
    """CLI 4.1.5"""
    from datetime import datetime
    try:
        setattr(heosobj, '_last_heartbeat', datetime.now())
    except:
        e = sys.exc_info()
        raise HEOSException(message=e[1] + ": " + e[2])
Exemple #5
0
def sources_changed(heosobj, command, data):
    """CLI 5.1"""

    if command == 'event/sources_changed':
        heosobj.send_command(command='browse/get_music_sources')
    else:
        raise HEOSException(message='{} is an unknown command'.format(command),
                            errid=501)
Exemple #6
0
def group_changed(heosobj, command, data):
    """CLI 5.3"""

    if command == 'event/groups_changed':
        heosobj.send_command(command='group/get_groups')
    else:
        raise HEOSException(message='{} is an unknown command'.format(command),
                            errid=503)
Exemple #7
0
def players_changed(heosobj, command, data):
    """CLI 5.2"""

    if command == 'event/players_changed':
        heosobj.send_command(command='player/get_players')
    else:
        raise HEOSException(message='{} is an unknown command'.format(command),
                            errid=502)
Exemple #8
0
def register_for_change_events(heosobj, command, data):
    """CLI 4.1.1"""
    value = data.split('=')[1]
    try:
        attrname = '_' + command
        setattr(heosobj, attrname, value)
    except:
        e = sys.exc_info()
        raise HEOSException(message=e[1] + ": " + e[2])
Exemple #9
0
def get_players(heosobj, command, data):
    """CLI 4.2.1"""

    from datetime import datetime

    try:
        setattr(heosobj, '_players', data)
        setattr(heosobj, '_refresh_players', datetime.now())
    except:
        e = sys.exc_info()
        raise HEOSException(message=e[1] + ": " + e[2])
Exemple #10
0
def player_now_playing_changed(heosobj, command, data):
    """CLI 5.5"""

    if command == 'event/player_now_playing_changed':
        pid = get_message_parts(data, ['pid'])[0]

        heosobj.send_command(
            command='player/get_player_info?pid={}'.format(pid))
    else:
        raise HEOSException(message='{} is an unknown command'.format(command),
                            error=505)
Exemple #11
0
def get_volume(heosobj, command, data):
    """CLI 4.2.6"""

    parts = get_message_parts(data, ['pid', 'level'])

    if 'pid' in parts.keys():
        pid = parts['pid']
    else:
        raise HEOSException(message='Response does not contain PID, aborting')

    if 'level' in parts.keys():
        vol_level = parts['level']
    else:
        raise HEOSException(
            message='Response does not contain volume level, aborting')

    try:
        attrname = "_player_volumes['" + pid + "']"
        setattr(heosobj, attrname, vol_level)
    except:
        e = sys.exc_info()
        raise HEOSException(message=e[1] + ": " + e[2])
Exemple #12
0
def get_music_sources(heosobj, command, data):
    """CLI 4.4.1"""

    sources = data
    filtered_sources = []

    for source in sources:
        if source.type in VALID_SOURCE_TYPES:
            filtered_sources.append(source)
        else:
            raise HEOSException(
                message='{} is not a valid source type ({})'.format(
                    source.type, source.name),
                errid=441)

    heosobj._sources = list(filtered_sources)

    return filtered_sources
Exemple #13
0
def check_account(heosobj, command, data):
    """CLI 4.1.2"""
    status = data.split('&')

    account_status = status[0]
    account_details = ""
    username = ""

    if len(status) > 1:
        account_details = status[1]

    if account_details and account_status == "signed_in":
        username = account_details.split('=')[1]

    try:
        setattr(heosobj, '_account_status', account_status)
        setattr(heosobj, '_heos_username', username)

    except:
        e = sys.exc_info()
        raise HEOSException(message=e[1] + ": " + e[2])
Exemple #14
0
def get_source_info(heosobj, command, data):
    """CLI 4.4.2"""

    newsource = data
    oldsources = heosobj._sources
    processed_sources = []

    if newsource.type in VALID_SOURCE_TYPES:
        for src in oldsources:
            if src.sid == newsource.sid:
                processed_sources.append(newsource)
            else:
                processed_sources.append(src)
    else:
        raise HEOSException(
            message='{} is not a valid source type ({})'.format(
                newsource.type, newsource.name),
            errid=442)

    heosobj._sources = list(processed_sources)

    return newsource
Exemple #15
0
def player_now_playing_progress(heosobj, command, data):
    """CLI 5.6"""

    if command == 'event/player_now_playing_progress':

        all_player_info = heosobj.players
        new_pid = data['pid']

        new_player_info = {}
        for player in all_player_info:
            if player['pid'] == new_pid:
                new_player_info.update(data)
            else:
                new_player_info.update(player)

        from datetime import datetime

        try:
            setattr(heosobj, '_players', new_player_info)
            setattr(heosobj, '_refresh_players', datetime.now())
        except:
            e = sys.exc_info()
            raise HEOSException(message=e[1] + ": " + e[2])