Remove ee brightbox integration (#63839)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/63854/head
epenet 2022-01-10 20:21:46 +01:00 committed by GitHub
parent 003a1e87a7
commit 52959cf48c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 237 deletions

View File

@ -1 +0,0 @@
"""The ee_brightbox component."""

View File

@ -1,103 +0,0 @@
"""Support for EE Brightbox router."""
import logging
# pylint: disable=import-error
from eebrightbox import EEBrightBox, EEBrightBoxException
import voluptuous as vol
from homeassistant.components.device_tracker import (
DOMAIN,
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
CONF_VERSION = "version"
CONF_DEFAULT_IP = "192.168.1.1"
CONF_DEFAULT_USERNAME = "admin"
CONF_DEFAULT_VERSION = 2
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_VERSION, default=CONF_DEFAULT_VERSION): cv.positive_int,
vol.Required(CONF_HOST, default=CONF_DEFAULT_IP): cv.string,
vol.Required(CONF_USERNAME, default=CONF_DEFAULT_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}
)
def get_scanner(hass, config):
"""Return a router scanner instance."""
scanner = EEBrightBoxScanner(config[DOMAIN])
return scanner if scanner.check_config() else None
class EEBrightBoxScanner(DeviceScanner):
"""Scan EE Brightbox router."""
def __init__(self, config):
"""Initialise the scanner."""
self.config = config
self.devices = {}
def check_config(self):
"""Check if provided configuration and credentials are correct."""
try:
with EEBrightBox(self.config) as ee_brightbox:
return bool(ee_brightbox.get_devices())
except EEBrightBoxException:
_LOGGER.exception("Failed to connect to the router")
return False
def scan_devices(self):
"""Scan for devices."""
with EEBrightBox(self.config) as ee_brightbox:
self.devices = {d["mac"]: d for d in ee_brightbox.get_devices()}
macs = [d["mac"] for d in self.devices.values() if d["activity_ip"]]
_LOGGER.debug("Scan devices %s", macs)
return macs
def get_device_name(self, device):
"""Get the name of a device from hostname."""
if device in self.devices:
return self.devices[device]["hostname"] or None
return None
def get_extra_attributes(self, device):
"""
Get the extra attributes of a device.
Extra attributes include:
- ip
- mac
- port - ethX or wifiX
- last_active
"""
port_map = {
"wl1": "wifi5Ghz",
"wl0": "wifi2.4Ghz",
"eth0": "eth0",
"eth1": "eth1",
"eth2": "eth2",
"eth3": "eth3",
}
if device in self.devices:
return {
"ip": self.devices[device]["ip"],
"mac": self.devices[device]["mac"],
"port": port_map[self.devices[device]["port"]],
"last_active": self.devices[device]["time_last_active"],
}
return {}

View File

@ -1,9 +0,0 @@
{
"domain": "ee_brightbox",
"name": "EE Bright Box",
"disabled": "Library has incompatible requirements.",
"documentation": "https://www.home-assistant.io/integrations/ee_brightbox",
"requirements": ["eebrightbox==0.0.4"],
"codeowners": [],
"iot_class": "local_polling"
}

View File

@ -1 +0,0 @@
"""Tests for the ee_brightbox component."""

View File

@ -1,123 +0,0 @@
"""Tests for the EE BrightBox device scanner."""
from datetime import datetime
from unittest.mock import patch
# Integration is disabled
# from eebrightbox import EEBrightBoxException
import pytest
from homeassistant.components.device_tracker import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_PLATFORM
from homeassistant.setup import async_setup_component
# Integration is disabled
pytest.skip("Integration has been disabled in the manifest", allow_module_level=True)
def _configure_mock_get_devices(eebrightbox_mock):
eebrightbox_instance = eebrightbox_mock.return_value
eebrightbox_instance.__enter__.return_value = eebrightbox_instance
eebrightbox_instance.get_devices.return_value = [
{
"mac": "AA:BB:CC:DD:EE:FF",
"ip": "192.168.1.10",
"hostname": "hostnameAA",
"activity_ip": True,
"port": "eth0",
"time_last_active": datetime(2019, 1, 20, 16, 4, 0),
},
{
"mac": "11:22:33:44:55:66",
"hostname": "hostname11",
"ip": "192.168.1.11",
"activity_ip": True,
"port": "wl0",
"time_last_active": datetime(2019, 1, 20, 11, 9, 0),
},
{
"mac": "FF:FF:FF:FF:FF:FF",
"hostname": "hostnameFF",
"ip": "192.168.1.12",
"activity_ip": False,
"port": "wl1",
"time_last_active": datetime(2019, 1, 15, 16, 9, 0),
},
]
def _configure_mock_failed_config_check(eebrightbox_mock):
eebrightbox_instance = eebrightbox_mock.return_value
# Integration is disabled
eebrightbox_instance.__enter__.side_effect = EEBrightBoxException( # noqa: F821
"Failed to connect to the router"
)
@pytest.fixture(autouse=True)
def mock_dev_track(mock_device_tracker_conf):
"""Mock device tracker config loading."""
pass
@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)
result = await async_setup_component(
hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "ee_brightbox"}}
)
assert result
await hass.async_block_till_done()
assert hass.states.get("device_tracker.hostnameaa") is None
assert hass.states.get("device_tracker.hostname11") is None
assert hass.states.get("device_tracker.hostnameff") is None
@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)
result = await async_setup_component(
hass,
DOMAIN,
{DOMAIN: {CONF_PLATFORM: "ee_brightbox", CONF_PASSWORD: "test_password"}},
)
assert result
await hass.async_block_till_done()
assert hass.states.get("device_tracker.hostnameaa") is None
assert hass.states.get("device_tracker.hostname11") is None
assert hass.states.get("device_tracker.hostnameff") is None
@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)
result = await async_setup_component(
hass,
DOMAIN,
{DOMAIN: {CONF_PLATFORM: "ee_brightbox", CONF_PASSWORD: "test_password"}},
)
assert result
await hass.async_block_till_done()
assert hass.states.get("device_tracker.hostnameaa") is not None
assert hass.states.get("device_tracker.hostname11") is not None
assert hass.states.get("device_tracker.hostnameff") is None
state = hass.states.get("device_tracker.hostnameaa")
assert state.attributes["mac"] == "AA:BB:CC:DD:EE:FF"
assert state.attributes["ip"] == "192.168.1.10"
assert state.attributes["port"] == "eth0"
assert state.attributes["last_active"] == datetime(2019, 1, 20, 16, 4, 0)