Files
home-assistant-core/tests/components/bond/test_cover.py
T
Eugene PrystupaandChris Talkington 9b77e16ffc Add new integration for Bond hub (#37477)
* create foundation for Bond integration

* add Bond hub integration (fix lint)

* Update homeassistant/components/bond/__init__.py

adding async_unload_entry per PR review suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* add Bond hub integration (fix missing import after applying PR suggestion)

* Update tests/components/bond/test_init.py

add a unit for unloading per PR review suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update tests/components/bond/test_init.py

add unit test for unload per PR review suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update tests/components/bond/test_init.py

PR review suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update tests/components/bond/test_init.py

PR review suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update tests/components/bond/test_init.py

PR review suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* add Bond hub integration (fix formatting)

* Update homeassistant/components/bond/manifest.json

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update homeassistant/components/bond/manifest.json

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update homeassistant/components/bond/manifest.json

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update homeassistant/components/bond/strings.json

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update homeassistant/components/bond/manifest.json

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update requirements_all.txt

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update homeassistant/components/bond/manifest.json

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update requirements_test_all.txt

PR suggestion

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* add Bond hub integration (remove friendly name from config per PR suggestion)

* Update homeassistant/components/bond/__init__.py

add per PR review feedback

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update homeassistant/components/bond/__init__.py

remove per PR review feedback

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Update tests/components/bond/test_init.py

fix unit test

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-05 20:17:53 -05:00

114 lines
3.2 KiB
Python

"""Tests for the Bond cover device."""
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,
SERVICE_CLOSE_COVER,
SERVICE_OPEN_COVER,
SERVICE_STOP_COVER,
)
from homeassistant.helpers.entity_registry import EntityRegistry
from .common import setup_platform
from tests.async_mock import patch
_LOGGER = logging.getLogger(__name__)
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},
)
],
):
await setup_platform(hass, COVER_DOMAIN)
registry: EntityRegistry = await hass.helpers.entity_registry.async_get_registry()
assert [key for key in registry.entities.keys()] == ["cover.name_1"]
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},
)
],
):
await setup_platform(hass, COVER_DOMAIN)
with patch("bond.Bond.open") as mock_open:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: "cover.name_1"},
blocking=True,
)
await hass.async_block_till_done()
mock_open.assert_called_once()
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},
)
],
):
await setup_platform(hass, COVER_DOMAIN)
with patch("bond.Bond.close") as mock_close:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: "cover.name_1"},
blocking=True,
)
await hass.async_block_till_done()
mock_close.assert_called_once()
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},
)
],
):
await setup_platform(hass, COVER_DOMAIN)
with patch("bond.Bond.hold") as mock_hold:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: "cover.name_1"},
blocking=True,
)
await hass.async_block_till_done()
mock_hold.assert_called_once()