Move ee_brightbox imports at top-level (#29054)

* Move ee_brightbox imports at top-level

* Fix tests

* Fix : Commented out code
pull/29113/head^2
Quentame 2019-11-26 17:59:55 +01:00 committed by Paulus Schoutsen
parent 78d5184186
commit 44e708f72b
2 changed files with 5 additions and 9 deletions

View File

@ -1,6 +1,7 @@
"""Support for EE Brightbox router."""
import logging
from eebrightbox import EEBrightBox, EEBrightBoxException
import voluptuous as vol
from homeassistant.components.device_tracker import (
@ -46,8 +47,6 @@ class EEBrightBoxScanner(DeviceScanner):
def check_config(self):
"""Check if provided configuration and credentials are correct."""
from eebrightbox import EEBrightBox, EEBrightBoxException
try:
with EEBrightBox(self.config) as ee_brightbox:
return bool(ee_brightbox.get_devices())
@ -57,8 +56,6 @@ class EEBrightBoxScanner(DeviceScanner):
def scan_devices(self):
"""Scan for devices."""
from eebrightbox import EEBrightBox
with EEBrightBox(self.config) as ee_brightbox:
self.devices = {d["mac"]: d for d in ee_brightbox.get_devices()}

View File

@ -2,6 +2,7 @@
from datetime import datetime
from asynctest import patch
from eebrightbox import EEBrightBoxException
import pytest
from homeassistant.components.device_tracker import DOMAIN
@ -41,8 +42,6 @@ def _configure_mock_get_devices(eebrightbox_mock):
def _configure_mock_failed_config_check(eebrightbox_mock):
from eebrightbox import EEBrightBoxException
eebrightbox_instance = eebrightbox_mock.return_value
eebrightbox_instance.__enter__.side_effect = EEBrightBoxException(
"Failed to connect to the router"
@ -55,7 +54,7 @@ def mock_dev_track(mock_device_tracker_conf):
pass
@patch("eebrightbox.EEBrightBox")
@patch("homeassistant.components.ee_brightbox.device_tracker.EEBrightBox")
async def test_missing_credentials(eebrightbox_mock, hass):
"""Test missing credentials."""
_configure_mock_get_devices(eebrightbox_mock)
@ -73,7 +72,7 @@ async def test_missing_credentials(eebrightbox_mock, hass):
assert hass.states.get("device_tracker.hostnameff") is None
@patch("eebrightbox.EEBrightBox")
@patch("homeassistant.components.ee_brightbox.device_tracker.EEBrightBox")
async def test_invalid_credentials(eebrightbox_mock, hass):
"""Test invalid credentials."""
_configure_mock_failed_config_check(eebrightbox_mock)
@ -93,7 +92,7 @@ async def test_invalid_credentials(eebrightbox_mock, hass):
assert hass.states.get("device_tracker.hostnameff") is None
@patch("eebrightbox.EEBrightBox")
@patch("homeassistant.components.ee_brightbox.device_tracker.EEBrightBox")
async def test_get_devices(eebrightbox_mock, hass):
"""Test valid configuration."""
_configure_mock_get_devices(eebrightbox_mock)