Add device tracking support for the Arris TG2492LG router (#30972)
* Add device tracker based on arris-tg2492lg * Return name of device and update version of arris_tg2492lg * Update CODEOWNERS, requirements_all.txt and .coveragerc * Change default url to host * Use f-strings Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Clean up * Fix formatting Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
5a2eddb32c
commit
3d9ae1b8bd
6 changed files with 87 additions and 0 deletions
|
@ -45,6 +45,7 @@ omit =
|
|||
homeassistant/components/arest/sensor.py
|
||||
homeassistant/components/arest/switch.py
|
||||
homeassistant/components/arlo/*
|
||||
homeassistant/components/arris_tg2492lg/*
|
||||
homeassistant/components/aruba/device_tracker.py
|
||||
homeassistant/components/arwn/sensor.py
|
||||
homeassistant/components/asterisk_cdr/mailbox.py
|
||||
|
|
|
@ -33,6 +33,7 @@ homeassistant/components/aprs/* @PhilRW
|
|||
homeassistant/components/arcam_fmj/* @elupus
|
||||
homeassistant/components/arduino/* @fabaff
|
||||
homeassistant/components/arest/* @fabaff
|
||||
homeassistant/components/arris_tg2492lg/* @vanbalken
|
||||
homeassistant/components/asuswrt/* @kennedyshead
|
||||
homeassistant/components/aten_pe/* @mtdcr
|
||||
homeassistant/components/atome/* @baqs
|
||||
|
|
1
homeassistant/components/arris_tg2492lg/__init__.py
Normal file
1
homeassistant/components/arris_tg2492lg/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
"""The Arris TG2492LG component."""
|
70
homeassistant/components/arris_tg2492lg/device_tracker.py
Normal file
70
homeassistant/components/arris_tg2492lg/device_tracker.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
"""Support for Arris TG2492LG router."""
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from arris_tg2492lg import ConnectBox, Device
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import (
|
||||
DOMAIN,
|
||||
PLATFORM_SCHEMA,
|
||||
DeviceScanner,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_HOST = "192.168.178.1"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
"""Return the Arris device scanner."""
|
||||
conf = config[DOMAIN]
|
||||
url = f"http://{conf[CONF_HOST]}"
|
||||
connect_box = ConnectBox(url, conf[CONF_PASSWORD])
|
||||
return ArrisDeviceScanner(connect_box)
|
||||
|
||||
|
||||
class ArrisDeviceScanner(DeviceScanner):
|
||||
"""This class queries a Arris TG2492LG router for connected devices."""
|
||||
|
||||
def __init__(self, connect_box: ConnectBox):
|
||||
"""Initialize the scanner."""
|
||||
self.connect_box = connect_box
|
||||
self.last_results: List[Device] = []
|
||||
|
||||
def scan_devices(self):
|
||||
"""Scan for new devices and return a list with found device IDs."""
|
||||
self._update_info()
|
||||
|
||||
return [device.mac for device in self.last_results]
|
||||
|
||||
def get_device_name(self, device):
|
||||
"""Return the name of the given device or None if we don't know."""
|
||||
name = next(
|
||||
(result.hostname for result in self.last_results if result.mac == device),
|
||||
None,
|
||||
)
|
||||
return name
|
||||
|
||||
def _update_info(self):
|
||||
"""Ensure the information from the Arris TG2492LG router is up to date."""
|
||||
result = self.connect_box.get_connected_devices()
|
||||
|
||||
last_results = []
|
||||
mac_addresses = set()
|
||||
|
||||
for device in result:
|
||||
if device.online and device.mac not in mac_addresses:
|
||||
last_results.append(device)
|
||||
mac_addresses.add(device.mac)
|
||||
|
||||
self.last_results = last_results
|
11
homeassistant/components/arris_tg2492lg/manifest.json
Normal file
11
homeassistant/components/arris_tg2492lg/manifest.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"domain": "arris_tg2492lg",
|
||||
"name": "Arris TG2492LG",
|
||||
"documentation": "https://www.home-assistant.io/integrations/arris_tg2492lg",
|
||||
"requirements": [
|
||||
"arris-tg2492lg==1.0.0"
|
||||
],
|
||||
"codeowners": [
|
||||
"@vanbalken"
|
||||
]
|
||||
}
|
|
@ -261,6 +261,9 @@ aqualogic==1.0
|
|||
# homeassistant.components.arcam_fmj
|
||||
arcam-fmj==0.4.3
|
||||
|
||||
# homeassistant.components.arris_tg2492lg
|
||||
arris-tg2492lg==1.0.0
|
||||
|
||||
# homeassistant.components.ampio
|
||||
asmog==0.0.6
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue