Add binary sensor for myq gateway connectivity (#33423)
This commit is contained in:
1 parent
12b408219e
commit
b783aab41b
8 files changed
+397
-3
No files matched your search
@@ -0,0 +1,20 @@
|
||||
"""The scene tests for the myq platform."""
|
||||
|
||||
from homeassistant.const import STATE_ON
|
||||
|
||||
from .util import async_init_integration
|
||||
|
||||
|
||||
async def test_create_binary_sensors(hass):
|
||||
"""Test creation of binary_sensors."""
|
||||
|
||||
await async_init_integration(hass)
|
||||
|
||||
state = hass.states.get("binary_sensor.happy_place_myq_gateway")
|
||||
assert state.state == STATE_ON
|
||||
expected_attributes = {"device_class": "connectivity"}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
"""The scene tests for the myq platform."""
|
||||
|
||||
from homeassistant.const import STATE_CLOSED
|
||||
|
||||
from .util import async_init_integration
|
||||
|
||||
|
||||
async def test_create_covers(hass):
|
||||
"""Test creation of covers."""
|
||||
|
||||
await async_init_integration(hass)
|
||||
|
||||
state = hass.states.get("cover.large_garage_door")
|
||||
assert state.state == STATE_CLOSED
|
||||
expected_attributes = {
|
||||
"device_class": "garage",
|
||||
"friendly_name": "Large Garage Door",
|
||||
"supported_features": 3,
|
||||
}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
)
|
||||
|
||||
state = hass.states.get("cover.small_garage_door")
|
||||
assert state.state == STATE_CLOSED
|
||||
expected_attributes = {
|
||||
"device_class": "garage",
|
||||
"friendly_name": "Small Garage Door",
|
||||
"supported_features": 3,
|
||||
}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
)
|
||||
|
||||
state = hass.states.get("cover.gate")
|
||||
assert state.state == STATE_CLOSED
|
||||
expected_attributes = {
|
||||
"device_class": "gate",
|
||||
"friendly_name": "Gate",
|
||||
"supported_features": 3,
|
||||
}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Tests for the myq integration."""
|
||||
|
||||
import json
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.myq.const import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
|
||||
async def async_init_integration(
|
||||
hass: HomeAssistant, skip_setup: bool = False,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the myq integration in Home Assistant."""
|
||||
|
||||
devices_fixture = "myq/devices.json"
|
||||
devices_json = load_fixture(devices_fixture)
|
||||
devices_dict = json.loads(devices_json)
|
||||
|
||||
def _handle_mock_api_request(method, endpoint, **kwargs):
|
||||
if endpoint == "Login":
|
||||
return {"SecurityToken": 1234}
|
||||
elif endpoint == "My":
|
||||
return {"Account": {"Id": 1}}
|
||||
elif endpoint == "Accounts/1/Devices":
|
||||
return devices_dict
|
||||
return {}
|
||||
|
||||
with patch("pymyq.api.API.request", side_effect=_handle_mock_api_request):
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"}
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
if not skip_setup:
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return entry
|
||||
Reference in new issue
Block a user