Apply more suggestions from bond code review (#37592)

* apply more suggestions from bond code review

* Update cover.py

* Update test_cover.py

* Update test_cover.py

* Update test_cover.py

* Update cover.py

* Update utils.py

* Update test_cover.py

* Update test_utils.py

* Delete test_utils.py

* Update cover.py

* Update test_cover.py

* Update test_cover.py
This commit is contained in:
Chris Talkington authored and GitHub committed 2020-07-08 16:28:53 -05:00
1 parent c1de781a23
commit fb420d5952
4 files changed
+25 -77

No files matched your search

+14 -36
View File
@@ -3,7 +3,6 @@ import logging
from bond import BOND_DEVICE_TYPE_MOTORIZED_SHADES
from homeassistant.components.bond.utils import BondDevice
from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID,
@@ -19,19 +18,16 @@ from tests.async_mock import patch
_LOGGER = logging.getLogger(__name__)
TEST_DEVICE_IDS = ["device-1"]
TEST_DEVICE = {"name": "name-1", "type": BOND_DEVICE_TYPE_MOTORIZED_SHADES}
async def test_entity_registry(hass):
"""Tests that the devices are registered in the entity registry."""
with patch(
"homeassistant.components.bond.utils.get_bond_devices",
return_value=[
BondDevice(
"device-1",
{"name": "name-1", "type": BOND_DEVICE_TYPE_MOTORIZED_SHADES},
)
],
):
"homeassistant.components.bond.Bond.getDeviceIds", return_value=TEST_DEVICE_IDS
), patch("homeassistant.components.bond.Bond.getDevice", return_value=TEST_DEVICE):
await setup_platform(hass, COVER_DOMAIN)
registry: EntityRegistry = await hass.helpers.entity_registry.async_get_registry()
@@ -42,17 +38,11 @@ async def test_open_cover(hass):
"""Tests that open cover command delegates to API."""
with patch(
"homeassistant.components.bond.utils.get_bond_devices",
return_value=[
BondDevice(
"device-1",
{"name": "name-1", "type": BOND_DEVICE_TYPE_MOTORIZED_SHADES},
)
],
):
"homeassistant.components.bond.Bond.getDeviceIds", return_value=TEST_DEVICE_IDS
), patch("homeassistant.components.bond.Bond.getDevice", return_value=TEST_DEVICE):
await setup_platform(hass, COVER_DOMAIN)
with patch("bond.Bond.open") as mock_open:
with patch("homeassistant.components.bond.Bond.open") as mock_open:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_OPEN_COVER,
@@ -67,17 +57,11 @@ async def test_close_cover(hass):
"""Tests that close cover command delegates to API."""
with patch(
"homeassistant.components.bond.utils.get_bond_devices",
return_value=[
BondDevice(
"device-1",
{"name": "name-1", "type": BOND_DEVICE_TYPE_MOTORIZED_SHADES},
)
],
):
"homeassistant.components.bond.Bond.getDeviceIds", return_value=TEST_DEVICE_IDS
), patch("homeassistant.components.bond.Bond.getDevice", return_value=TEST_DEVICE):
await setup_platform(hass, COVER_DOMAIN)
with patch("bond.Bond.close") as mock_close:
with patch("homeassistant.components.bond.Bond.close") as mock_close:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_CLOSE_COVER,
@@ -92,17 +76,11 @@ async def test_stop_cover(hass):
"""Tests that stop cover command delegates to API."""
with patch(
"homeassistant.components.bond.utils.get_bond_devices",
return_value=[
BondDevice(
"device-1",
{"name": "name-1", "type": BOND_DEVICE_TYPE_MOTORIZED_SHADES},
)
],
):
"homeassistant.components.bond.Bond.getDeviceIds", return_value=TEST_DEVICE_IDS
), patch("homeassistant.components.bond.Bond.getDevice", return_value=TEST_DEVICE):
await setup_platform(hass, COVER_DOMAIN)
with patch("bond.Bond.hold") as mock_hold:
with patch("homeassistant.components.bond.Bond.hold") as mock_hold:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_STOP_COVER,
-24
View File
@@ -1,24 +0,0 @@
"""Tests for the Bond cover device."""
import logging
from bond import Bond
from homeassistant.components.bond.utils import get_bond_devices
from homeassistant.core import HomeAssistant
from tests.async_mock import patch
_LOGGER = logging.getLogger(__name__)
async def test_get_bond_devices(hass: HomeAssistant):
"""Tests that the querying for devices delegates to API."""
bond: Bond = Bond("1.1.1.1", "test-token")
with patch(
"bond.Bond.getDeviceIds", return_value=["device-1", "device-2"],
) as mock_get_device_ids, patch("bond.Bond.getDevice") as mock_get_device:
await get_bond_devices(hass, bond)
assert len(mock_get_device_ids.mock_calls) == 1
assert len(mock_get_device.mock_calls) == 2