Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors out on restore volume if previous volume is null. #2777

Open
richard-collier opened this issue Dec 28, 2024 · 2 comments
Open

Errors out on restore volume if previous volume is null. #2777

richard-collier opened this issue Dec 28, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@richard-collier
Copy link

Works as advertised unless the previous_volume attribute is null (which is it's value after a reboot). At that point, it returns an error.

Copy link

@richard-collier this issue was automatically closed because it did not follow the issue template and this warning: IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

@danielbrunt57 danielbrunt57 reopened this Dec 28, 2024
@danielbrunt57 danielbrunt57 self-assigned this Dec 28, 2024
@danielbrunt57 danielbrunt57 added the bug Something isn't working label Dec 28, 2024
@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 28, 2024

I can change the service call to issue a warning instead of an error:
custom_components/alexa_media/services.py lines 166-185:

        # Retrieve the state and attributes
        state = self.hass.states.get(entity_id)
        if not state:
            _LOGGER.warning("Entity %s has no state; cannot restore volume", entity_id)
            return False
    
        previous_volume = state.attributes.get('previous_volume')
        current_volume = state.attributes.get('volume_level')
    
        if previous_volume is None:
            _LOGGER.warning(
                "Previous volume not found for %s; attempting to use current volume level: %s",
                entity_id,
                current_volume,
            )
            previous_volume = current_volume
    
        if previous_volume is None:
            _LOGGER.warning("No valid volume levels found for entity %s; cannot restore volume", entity_id)
            return False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants