Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -7,8 +7,7 @@ from homeassistant.components.ring import binary_sensor as ring
|
||||
from homeassistant.components import ring as base_ring
|
||||
|
||||
from tests.components.ring.test_init import ATTRIBUTION, VALID_CONFIG
|
||||
from tests.common import (
|
||||
get_test_config_dir, get_test_home_assistant, load_fixture)
|
||||
from tests.common import get_test_config_dir, get_test_home_assistant, load_fixture
|
||||
|
||||
|
||||
class TestRingBinarySensorSetup(unittest.TestCase):
|
||||
@@ -31,9 +30,9 @@ class TestRingBinarySensorSetup(unittest.TestCase):
|
||||
self.hass = get_test_home_assistant()
|
||||
self.cache = get_test_config_dir(base_ring.DEFAULT_CACHEDB)
|
||||
self.config = {
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
'monitored_conditions': ['ding', 'motion'],
|
||||
"username": "foo",
|
||||
"password": "bar",
|
||||
"monitored_conditions": ["ding", "motion"],
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
@@ -44,35 +43,41 @@ class TestRingBinarySensorSetup(unittest.TestCase):
|
||||
@requests_mock.Mocker()
|
||||
def test_binary_sensor(self, mock):
|
||||
"""Test the Ring sensor class and methods."""
|
||||
mock.post('https://oauth.ring.com/oauth/token',
|
||||
text=load_fixture('ring_oauth.json'))
|
||||
mock.post('https://api.ring.com/clients_api/session',
|
||||
text=load_fixture('ring_session.json'))
|
||||
mock.get('https://api.ring.com/clients_api/ring_devices',
|
||||
text=load_fixture('ring_devices.json'))
|
||||
mock.get('https://api.ring.com/clients_api/dings/active',
|
||||
text=load_fixture('ring_ding_active.json'))
|
||||
mock.get('https://api.ring.com/clients_api/doorbots/987652/health',
|
||||
text=load_fixture('ring_doorboot_health_attrs.json'))
|
||||
mock.get('https://api.ring.com/clients_api/chimes/999999/health',
|
||||
text=load_fixture('ring_chime_health_attrs.json'))
|
||||
mock.post(
|
||||
"https://oauth.ring.com/oauth/token", text=load_fixture("ring_oauth.json")
|
||||
)
|
||||
mock.post(
|
||||
"https://api.ring.com/clients_api/session",
|
||||
text=load_fixture("ring_session.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/ring_devices",
|
||||
text=load_fixture("ring_devices.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/dings/active",
|
||||
text=load_fixture("ring_ding_active.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/doorbots/987652/health",
|
||||
text=load_fixture("ring_doorboot_health_attrs.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/chimes/999999/health",
|
||||
text=load_fixture("ring_chime_health_attrs.json"),
|
||||
)
|
||||
|
||||
base_ring.setup(self.hass, VALID_CONFIG)
|
||||
ring.setup_platform(self.hass,
|
||||
self.config,
|
||||
self.add_entities,
|
||||
None)
|
||||
ring.setup_platform(self.hass, self.config, self.add_entities, None)
|
||||
|
||||
for device in self.DEVICES:
|
||||
device.update()
|
||||
if device.name == 'Front Door Ding':
|
||||
assert 'on' == device.state
|
||||
assert 'America/New_York' == \
|
||||
device.device_state_attributes['timezone']
|
||||
elif device.name == 'Front Door Motion':
|
||||
assert 'off' == device.state
|
||||
assert 'motion' == device.device_class
|
||||
if device.name == "Front Door Ding":
|
||||
assert "on" == device.state
|
||||
assert "America/New_York" == device.device_state_attributes["timezone"]
|
||||
elif device.name == "Front Door Motion":
|
||||
assert "off" == device.state
|
||||
assert "motion" == device.device_class
|
||||
|
||||
assert device.entity_picture is None
|
||||
assert ATTRIBUTION == \
|
||||
device.device_state_attributes['attribution']
|
||||
assert ATTRIBUTION == device.device_state_attributes["attribution"]
|
||||
@@ -7,17 +7,12 @@ from datetime import timedelta
|
||||
from homeassistant import setup
|
||||
import homeassistant.components.ring as ring
|
||||
|
||||
from tests.common import (
|
||||
get_test_config_dir, get_test_home_assistant, load_fixture)
|
||||
from tests.common import get_test_config_dir, get_test_home_assistant, load_fixture
|
||||
|
||||
ATTRIBUTION = 'Data provided by Ring.com'
|
||||
ATTRIBUTION = "Data provided by Ring.com"
|
||||
|
||||
VALID_CONFIG = {
|
||||
"ring": {
|
||||
"username": "foo",
|
||||
"password": "bar",
|
||||
"scan_interval": timedelta(10)
|
||||
}
|
||||
"ring": {"username": "foo", "password": "bar", "scan_interval": timedelta(10)}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,33 +38,46 @@ class TestRing(unittest.TestCase):
|
||||
@requests_mock.Mocker()
|
||||
def test_setup(self, mock):
|
||||
"""Test the setup."""
|
||||
mock.post('https://oauth.ring.com/oauth/token',
|
||||
text=load_fixture('ring_oauth.json'))
|
||||
mock.post('https://api.ring.com/clients_api/session',
|
||||
text=load_fixture('ring_session.json'))
|
||||
mock.get('https://api.ring.com/clients_api/ring_devices',
|
||||
text=load_fixture('ring_devices.json'))
|
||||
mock.get('https://api.ring.com/clients_api/chimes/999999/health',
|
||||
text=load_fixture('ring_chime_health_attrs.json'))
|
||||
mock.get('https://api.ring.com/clients_api/doorbots/987652/health',
|
||||
text=load_fixture('ring_doorboot_health_attrs.json'))
|
||||
mock.post(
|
||||
"https://oauth.ring.com/oauth/token", text=load_fixture("ring_oauth.json")
|
||||
)
|
||||
mock.post(
|
||||
"https://api.ring.com/clients_api/session",
|
||||
text=load_fixture("ring_session.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/ring_devices",
|
||||
text=load_fixture("ring_devices.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/chimes/999999/health",
|
||||
text=load_fixture("ring_chime_health_attrs.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/doorbots/987652/health",
|
||||
text=load_fixture("ring_doorboot_health_attrs.json"),
|
||||
)
|
||||
response = ring.setup(self.hass, self.config)
|
||||
assert response
|
||||
|
||||
@requests_mock.Mocker()
|
||||
def test_setup_component_no_login(self, mock):
|
||||
"""Test the setup when no login is configured."""
|
||||
mock.post('https://api.ring.com/clients_api/session',
|
||||
text=load_fixture('ring_session.json'))
|
||||
mock.post(
|
||||
"https://api.ring.com/clients_api/session",
|
||||
text=load_fixture("ring_session.json"),
|
||||
)
|
||||
conf = deepcopy(VALID_CONFIG)
|
||||
del conf['ring']['username']
|
||||
del conf["ring"]["username"]
|
||||
assert not setup.setup_component(self.hass, ring.DOMAIN, conf)
|
||||
|
||||
@requests_mock.Mocker()
|
||||
def test_setup_component_no_pwd(self, mock):
|
||||
"""Test the setup when no password is configured."""
|
||||
mock.post('https://api.ring.com/clients_api/session',
|
||||
text=load_fixture('ring_session.json'))
|
||||
mock.post(
|
||||
"https://api.ring.com/clients_api/session",
|
||||
text=load_fixture("ring_session.json"),
|
||||
)
|
||||
conf = deepcopy(VALID_CONFIG)
|
||||
del conf['ring']['password']
|
||||
del conf["ring"]["password"]
|
||||
assert not setup.setup_component(self.hass, ring.DOMAIN, conf)
|
||||
@@ -7,8 +7,7 @@ import homeassistant.components.ring.sensor as ring
|
||||
from homeassistant.components import ring as base_ring
|
||||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
from tests.components.ring.test_init import ATTRIBUTION, VALID_CONFIG
|
||||
from tests.common import (
|
||||
get_test_config_dir, get_test_home_assistant, load_fixture)
|
||||
from tests.common import get_test_config_dir, get_test_home_assistant, load_fixture
|
||||
|
||||
|
||||
class TestRingSensorSetup(unittest.TestCase):
|
||||
@@ -31,16 +30,17 @@ class TestRingSensorSetup(unittest.TestCase):
|
||||
self.hass = get_test_home_assistant()
|
||||
self.cache = get_test_config_dir(base_ring.DEFAULT_CACHEDB)
|
||||
self.config = {
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
'monitored_conditions': [
|
||||
'battery',
|
||||
'last_activity',
|
||||
'last_ding',
|
||||
'last_motion',
|
||||
'volume',
|
||||
'wifi_signal_category',
|
||||
'wifi_signal_strength']
|
||||
"username": "foo",
|
||||
"password": "bar",
|
||||
"monitored_conditions": [
|
||||
"battery",
|
||||
"last_activity",
|
||||
"last_ding",
|
||||
"last_motion",
|
||||
"volume",
|
||||
"wifi_signal_category",
|
||||
"wifi_signal_strength",
|
||||
],
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
@@ -51,65 +51,65 @@ class TestRingSensorSetup(unittest.TestCase):
|
||||
@requests_mock.Mocker()
|
||||
def test_sensor(self, mock):
|
||||
"""Test the Ring sensor class and methods."""
|
||||
mock.post('https://oauth.ring.com/oauth/token',
|
||||
text=load_fixture('ring_oauth.json'))
|
||||
mock.post('https://api.ring.com/clients_api/session',
|
||||
text=load_fixture('ring_session.json'))
|
||||
mock.get('https://api.ring.com/clients_api/ring_devices',
|
||||
text=load_fixture('ring_devices.json'))
|
||||
mock.get('https://api.ring.com/clients_api/doorbots/987652/history',
|
||||
text=load_fixture('ring_doorbots.json'))
|
||||
mock.get('https://api.ring.com/clients_api/doorbots/987652/health',
|
||||
text=load_fixture('ring_doorboot_health_attrs.json'))
|
||||
mock.get('https://api.ring.com/clients_api/chimes/999999/health',
|
||||
text=load_fixture('ring_chime_health_attrs.json'))
|
||||
mock.post(
|
||||
"https://oauth.ring.com/oauth/token", text=load_fixture("ring_oauth.json")
|
||||
)
|
||||
mock.post(
|
||||
"https://api.ring.com/clients_api/session",
|
||||
text=load_fixture("ring_session.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/ring_devices",
|
||||
text=load_fixture("ring_devices.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/doorbots/987652/history",
|
||||
text=load_fixture("ring_doorbots.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/doorbots/987652/health",
|
||||
text=load_fixture("ring_doorboot_health_attrs.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/chimes/999999/health",
|
||||
text=load_fixture("ring_chime_health_attrs.json"),
|
||||
)
|
||||
base_ring.setup(self.hass, VALID_CONFIG)
|
||||
ring.setup_platform(self.hass,
|
||||
self.config,
|
||||
self.add_entities,
|
||||
None)
|
||||
ring.setup_platform(self.hass, self.config, self.add_entities, None)
|
||||
|
||||
for device in self.DEVICES:
|
||||
device.update()
|
||||
if device.name == 'Front Battery':
|
||||
if device.name == "Front Battery":
|
||||
expected_icon = icon_for_battery_level(
|
||||
battery_level=int(device.state), charging=False)
|
||||
battery_level=int(device.state), charging=False
|
||||
)
|
||||
assert device.icon == expected_icon
|
||||
assert 80 == device.state
|
||||
assert 'hp_cam_v1' == \
|
||||
device.device_state_attributes['kind']
|
||||
assert 'stickup_cams' == \
|
||||
device.device_state_attributes['type']
|
||||
if device.name == 'Front Door Battery':
|
||||
assert "hp_cam_v1" == device.device_state_attributes["kind"]
|
||||
assert "stickup_cams" == device.device_state_attributes["type"]
|
||||
if device.name == "Front Door Battery":
|
||||
assert 100 == device.state
|
||||
assert 'lpd_v1' == \
|
||||
device.device_state_attributes['kind']
|
||||
assert 'chimes' != \
|
||||
device.device_state_attributes['type']
|
||||
if device.name == 'Downstairs Volume':
|
||||
assert "lpd_v1" == device.device_state_attributes["kind"]
|
||||
assert "chimes" != device.device_state_attributes["type"]
|
||||
if device.name == "Downstairs Volume":
|
||||
assert 2 == device.state
|
||||
assert '1.2.3' == \
|
||||
device.device_state_attributes['firmware']
|
||||
assert 'ring_mock_wifi' == \
|
||||
device.device_state_attributes['wifi_name']
|
||||
assert 'mdi:bell-ring' == device.icon
|
||||
assert 'chimes' == \
|
||||
device.device_state_attributes['type']
|
||||
if device.name == 'Front Door Last Activity':
|
||||
assert not device.device_state_attributes['answered']
|
||||
assert 'America/New_York' == \
|
||||
device.device_state_attributes['timezone']
|
||||
assert "1.2.3" == device.device_state_attributes["firmware"]
|
||||
assert "ring_mock_wifi" == device.device_state_attributes["wifi_name"]
|
||||
assert "mdi:bell-ring" == device.icon
|
||||
assert "chimes" == device.device_state_attributes["type"]
|
||||
if device.name == "Front Door Last Activity":
|
||||
assert not device.device_state_attributes["answered"]
|
||||
assert "America/New_York" == device.device_state_attributes["timezone"]
|
||||
|
||||
if device.name == 'Downstairs WiFi Signal Strength':
|
||||
if device.name == "Downstairs WiFi Signal Strength":
|
||||
assert -39 == device.state
|
||||
|
||||
if device.name == 'Front Door WiFi Signal Category':
|
||||
assert 'good' == device.state
|
||||
if device.name == "Front Door WiFi Signal Category":
|
||||
assert "good" == device.state
|
||||
|
||||
if device.name == 'Front Door WiFi Signal Strength':
|
||||
if device.name == "Front Door WiFi Signal Strength":
|
||||
assert -58 == device.state
|
||||
|
||||
assert device.entity_picture is None
|
||||
assert ATTRIBUTION == \
|
||||
device.device_state_attributes['attribution']
|
||||
assert ATTRIBUTION == device.device_state_attributes["attribution"]
|
||||
assert not device.should_poll
|
||||
Reference in new issue
Block a user