Add binary sensor for myq gateway connectivity (#33423)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-03-31 11:58:44 -07:00
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
)
+50
View File
@@ -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
)
+42
View File
@@ -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
+133
View File
@@ -0,0 +1,133 @@
{
"count" : 4,
"href" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices",
"items" : [
{
"device_type" : "ethernetgateway",
"created_date" : "2020-02-10T22:54:58.423",
"href" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gateway_serial",
"device_family" : "gateway",
"name" : "Happy place",
"device_platform" : "myq",
"state" : {
"homekit_enabled" : false,
"pending_bootload_abandoned" : false,
"online" : true,
"last_status" : "2020-03-30T02:49:46.4121303Z",
"physical_devices" : [],
"firmware_version" : "1.6",
"learn_mode" : false,
"learn" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gateway_serial/learn",
"homekit_capable" : false,
"updated_date" : "2020-03-30T02:49:46.4171299Z"
},
"serial_number" : "gateway_serial"
},
{
"serial_number" : "gate_serial",
"state" : {
"report_ajar" : false,
"aux_relay_delay" : "00:00:00",
"is_unattended_close_allowed" : true,
"door_ajar_interval" : "00:00:00",
"aux_relay_behavior" : "None",
"last_status" : "2020-03-30T02:47:40.2794038Z",
"online" : true,
"rex_fires_door" : false,
"close" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gate_serial/close",
"invalid_shutout_period" : "00:00:00",
"invalid_credential_window" : "00:00:00",
"use_aux_relay" : false,
"command_channel_report_status" : false,
"last_update" : "2020-03-28T23:07:39.5611776Z",
"door_state" : "closed",
"max_invalid_attempts" : 0,
"open" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gate_serial/open",
"passthrough_interval" : "00:00:00",
"control_from_browser" : false,
"report_forced" : false,
"is_unattended_open_allowed" : true
},
"parent_device_id" : "gateway_serial",
"name" : "Gate",
"device_platform" : "myq",
"device_family" : "garagedoor",
"parent_device" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gateway_serial",
"href" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gate_serial",
"device_type" : "gate",
"created_date" : "2020-02-10T22:54:58.423"
},
{
"parent_device" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gateway_serial",
"href" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/large_garage_serial",
"device_type" : "wifigaragedooropener",
"created_date" : "2020-02-10T22:55:25.863",
"device_platform" : "myq",
"name" : "Large Garage Door",
"device_family" : "garagedoor",
"serial_number" : "large_garage_serial",
"state" : {
"report_forced" : false,
"is_unattended_open_allowed" : true,
"passthrough_interval" : "00:00:00",
"control_from_browser" : false,
"attached_work_light_error_present" : false,
"max_invalid_attempts" : 0,
"open" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/large_garage_serial/open",
"command_channel_report_status" : false,
"last_update" : "2020-03-28T23:58:55.5906643Z",
"door_state" : "closed",
"invalid_shutout_period" : "00:00:00",
"use_aux_relay" : false,
"invalid_credential_window" : "00:00:00",
"rex_fires_door" : false,
"close" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/large_garage_serial/close",
"online" : true,
"last_status" : "2020-03-30T02:49:46.4121303Z",
"aux_relay_behavior" : "None",
"door_ajar_interval" : "00:00:00",
"gdo_lock_connected" : false,
"report_ajar" : false,
"aux_relay_delay" : "00:00:00",
"is_unattended_close_allowed" : true
},
"parent_device_id" : "gateway_serial"
},
{
"serial_number" : "small_garage_serial",
"state" : {
"last_status" : "2020-03-30T02:48:45.7501595Z",
"online" : true,
"report_ajar" : false,
"aux_relay_delay" : "00:00:00",
"is_unattended_close_allowed" : true,
"gdo_lock_connected" : false,
"door_ajar_interval" : "00:00:00",
"aux_relay_behavior" : "None",
"attached_work_light_error_present" : false,
"control_from_browser" : false,
"passthrough_interval" : "00:00:00",
"is_unattended_open_allowed" : true,
"report_forced" : false,
"close" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/small_garage_serial/close",
"rex_fires_door" : false,
"invalid_credential_window" : "00:00:00",
"use_aux_relay" : false,
"invalid_shutout_period" : "00:00:00",
"door_state" : "closed",
"last_update" : "2020-03-26T15:45:31.4713796Z",
"command_channel_report_status" : false,
"open" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/small_garage_serial/open",
"max_invalid_attempts" : 0
},
"parent_device_id" : "gateway_serial",
"device_platform" : "myq",
"name" : "Small Garage Door",
"device_family" : "garagedoor",
"parent_device" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/gateway_serial",
"href" : "http://api.myqdevice.com/api/v5/accounts/account_id/devices/small_garage_serial",
"device_type" : "wifigaragedooropener",
"created_date" : "2020-02-10T23:11:47.487"
}
]
}