Add verisure ethernet status (#28656)

This commit is contained in:
Thomas Germain authored and Martin Hjelmare committed 2019-11-13 14:12:36 +01:00
1 parent 8f390d099a
commit ec45e72bea
3 files changed
+109 -4

No files matched your search

@@ -0,0 +1,67 @@
"""Test Verisure ethernet status."""
from contextlib import contextmanager
from unittest.mock import patch
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.setup import async_setup_component
from homeassistant.components.verisure import DOMAIN as VERISURE_DOMAIN
CONFIG = {
"verisure": {
"username": "test",
"password": "test",
"alarm": False,
"door_window": False,
"hygrometers": False,
"mouse": False,
"smartplugs": False,
"thermometers": False,
"smartcam": False,
}
}
@contextmanager
def mock_hub(config, response):
"""Extensively mock out a verisure hub."""
hub_prefix = "homeassistant.components.verisure.binary_sensor.hub"
verisure_prefix = "verisure.Session"
with patch(verisure_prefix) as session, patch(hub_prefix) as hub:
session.login.return_value = True
hub.config = config["verisure"]
hub.get.return_value = response
hub.get_first.return_value = response.get("ethernetConnectedNow", None)
yield hub
async def setup_verisure(hass, config, response):
"""Set up mock verisure."""
with mock_hub(config, response):
await async_setup_component(hass, VERISURE_DOMAIN, config)
await hass.async_block_till_done()
async def test_verisure_no_ethernet_status(hass):
"""Test no data from API."""
await setup_verisure(hass, CONFIG, {})
assert len(hass.states.async_all()) == 1
entity_id = hass.states.async_entity_ids()[0]
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
async def test_verisure_ethernet_status_disconnected(hass):
"""Test disconnected."""
await setup_verisure(hass, CONFIG, {"ethernetConnectedNow": False})
assert len(hass.states.async_all()) == 1
entity_id = hass.states.async_entity_ids()[0]
assert hass.states.get(entity_id).state == "off"
async def test_verisure_ethernet_status_connected(hass):
"""Test connected."""
await setup_verisure(hass, CONFIG, {"ethernetConnectedNow": True})
assert len(hass.states.async_all()) == 1
entity_id = hass.states.async_entity_ids()[0]
assert hass.states.get(entity_id).state == "on"
+7 -3
View File
@@ -50,6 +50,9 @@ LOCKS = ["door_lock"]
def mock_hub(config, get_response=LOCKS[0]):
"""Extensively mock out a verisure hub."""
hub_prefix = "homeassistant.components.verisure.lock.hub"
# Since there is no conf to disable ethernet status, mock hub for
# binary sensor too
hub_binary_sensor = "homeassistant.components.verisure.binary_sensor.hub"
verisure_prefix = "verisure.Session"
with patch(verisure_prefix) as session, patch(hub_prefix) as hub:
session.login.return_value = True
@@ -62,7 +65,8 @@ def mock_hub(config, get_response=LOCKS[0]):
}
hub.session.get_lock_state_transaction.return_value = {"result": "OK"}
yield hub
with patch(hub_binary_sensor, hub):
yield hub
async def setup_verisure_locks(hass, config):
@@ -70,8 +74,8 @@ async def setup_verisure_locks(hass, config):
with mock_hub(config):
await async_setup_component(hass, VERISURE_DOMAIN, config)
await hass.async_block_till_done()
# lock.door_lock, group.all_locks
assert len(hass.states.async_all()) == 2
# lock.door_lock, group.all_locks, ethernet_status
assert len(hass.states.async_all()) == 3
async def test_verisure_no_default_code(hass):