-
-
Notifications
You must be signed in to change notification settings - Fork 37.9k
Add timeout / debounce (for brightness and others) #13534
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| """Test different accessory types: Lights.""" | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.components.homekit.type_lights import Light | ||
| from homeassistant.components.light import ( | ||
| DOMAIN, ATTR_BRIGHTNESS, ATTR_BRIGHTNESS_PCT, ATTR_COLOR_TEMP, | ||
| ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_COLOR) | ||
|
|
@@ -13,6 +13,10 @@ | |
|
|
||
| from tests.common import get_test_home_assistant | ||
|
|
||
| patch('homeassistant.components.homekit.accessories.debounce', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is bad as now loading this file impacts all other tests that use homekit. Instead, you should use a pytest fixture. But to be able to leverage pytest fixtures, you will need to rewrite your tests to be just methods. Something like this: (written from top of my head, didn't test) import pytest
@pytest.fixture(autouse=True)
def mock_debounce():
with patch('…'):
yield
@pytest.fixture
def mock_call_service(hass):
events = []
@callback
def record_event(event):
…
hass.bus.listen(…)
return events
def test_light_basic(hass, mock_call_service):
# hass is a new test instance, will be automatically stopped for you
# mock_call_service is equivalent to self.events
# Instead of self.assertEqual, just use assert
assert acc.aid == 2 |
||
| lambda f: lambda *args, **kwargs: f(*args, **kwargs)).start() | ||
| from homeassistant.components.homekit.type_lights import Light # noqa: E402 | ||
|
|
||
|
|
||
| class TestHomekitLights(unittest.TestCase): | ||
| """Test class for all accessory types regarding lights.""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,23 @@ | ||
| """Test different accessory types: Thermostats.""" | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.components.climate import ( | ||
| ATTR_CURRENT_TEMPERATURE, ATTR_TEMPERATURE, | ||
| ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH, ATTR_OPERATION_MODE, | ||
| ATTR_OPERATION_LIST, STATE_COOL, STATE_HEAT, STATE_AUTO) | ||
| from homeassistant.components.homekit.type_thermostats import Thermostat | ||
| from homeassistant.const import ( | ||
| ATTR_SERVICE, EVENT_CALL_SERVICE, ATTR_SERVICE_DATA, | ||
| ATTR_UNIT_OF_MEASUREMENT, STATE_OFF, TEMP_CELSIUS, TEMP_FAHRENHEIT) | ||
|
|
||
| from tests.common import get_test_home_assistant | ||
|
|
||
| patch('homeassistant.components.homekit.accessories.debounce', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed too. |
||
| lambda f: lambda *args, **kwargs: f(*args, **kwargs)).start() | ||
| from homeassistant.components.homekit.type_thermostats import ( # noqa: E402 | ||
| Thermostat) | ||
|
|
||
|
|
||
| class TestHomekitThermostats(unittest.TestCase): | ||
| """Test class for all accessory types regarding thermostats.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this weird. it used to take hass but now we don't pass that on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see now how you're storing this. Can we store it in a dictionary? That makes things a lot more readable.