Skip to content

Add default value to timeout on SamsungTV Device#17221

Closed
anapaulagomes wants to merge 1 commit intohome-assistant:devfrom
anapaulagomes:timeout-fix
Closed

Add default value to timeout on SamsungTV Device#17221
anapaulagomes wants to merge 1 commit intohome-assistant:devfrom
anapaulagomes:timeout-fix

Conversation

@anapaulagomes
Copy link
Copy Markdown
Contributor

Description:

Add default value to timeout. cc @arsaboo

Related issue (if applicable): fixes #17203

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@ghost ghost added the in progress label Oct 7, 2018
@amelchio amelchio added this to the 0.80 milestone Oct 7, 2018
@arsaboo
Copy link
Copy Markdown
Contributor

arsaboo commented Oct 7, 2018

This fixes the issue...thanks for the quick fix 👍

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the argument order when instantiating the entity too.

"""Representation of a Samsung TV."""

def __init__(self, host, port, name, timeout, mac):
def __init__(self, host, port, name, mac, timeout=0):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already is a default timeout defined. Why is this change needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a default but when the config entry doesn't exist this value is None.
https://github.com/home-assistant/home-assistant/blob/400658f23649d22c7214c8e4a88127119d653612/homeassistant/components/media_player/samsungtv.py#L63

This is causing the issue presented in the description. I added the default timeout in the line above (timeout = config.get(CONF_TIMEOUT, DEFAULT_TIMEOUT)) and a test for it but the problem remains when testing in a real device. Any thoughts?

This test reproduces the problem:

    @MockDependency('samsungctl')
    @MockDependency('wakeonlan')
    def test_setup_without_timeout(self, samsung_mock, wol_mock):
        """Testing setup of platform to unset timeout."""
        with mock.patch(
                'homeassistant.components.media_player.samsungtv.socket'):
            add_entities = mock.Mock()

            WORKING_CONFIG_WITHOUT_TIMEOUT = WORKING_CONFIG.copy()
            WORKING_CONFIG_WITHOUT_TIMEOUT.pop(CONF_TIMEOUT)

            setup_platform(
                self.hass, WORKING_CONFIG_WITHOUT_TIMEOUT, add_entities)

            assert add_entities.called
            device = add_entities.call_args[0][0][0]
            assert device._config['timeout'] == DEFAULT_TIMEOUT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a default defined in the config schema. When setting up via config the platform schema will populate default values in the config.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your test example is incomplete. We need to set up the platform via the core with setup_component to have config validation be done.

@balloob balloob removed this from the 0.80 milestone Oct 8, 2018
@anapaulagomes
Copy link
Copy Markdown
Contributor Author

Turns out we found out that changing DEFAULT_TIMEOUT to 1 would do the trick. @arsaboo is gonna open a PR. I'm closing this one. Thanks you all.

@ghost ghost removed the in progress label Oct 9, 2018
@anapaulagomes anapaulagomes deleted the timeout-fix branch October 9, 2018 15:43
@arsaboo arsaboo mentioned this pull request Oct 9, 2018
2 tasks
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Samsungtv not working in 0.80.0b0

7 participants