Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ omit =
homeassistant/components/russound_rnet/media_player.py
homeassistant/components/sabnzbd/*
homeassistant/components/saj/sensor.py
homeassistant/components/salt/device_tracker.py
homeassistant/components/satel_integra/*
homeassistant/components/scrape/sensor.py
homeassistant/components/scsgate/*
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ homeassistant/components/rmvtransport/* @cgtobi
homeassistant/components/roomba/* @pschmitt
homeassistant/components/safe_mode/* @home-assistant/core
homeassistant/components/saj/* @fredericvl
homeassistant/components/salt/* @bjornorri
homeassistant/components/samsungtv/* @escoand
homeassistant/components/scene/* @home-assistant/core
homeassistant/components/scrape/* @fabaff
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/salt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The salt component."""
71 changes: 71 additions & 0 deletions homeassistant/components/salt/device_tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Support for Salt Fiber Box routers."""
import logging

from saltbox import RouterLoginException, RouterNotReachableException, SaltBox
import voluptuous as vol

from homeassistant.components.device_tracker import (
DOMAIN,
PLATFORM_SCHEMA,
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}
)


def get_scanner(hass, config):
"""Return the Salt device scanner."""
scanner = SaltDeviceScanner(config[DOMAIN])

# Test whether the router is accessible.
data = scanner.get_salt_data()
return scanner if data is not None else None
Comment thread
bjornorri marked this conversation as resolved.


class SaltDeviceScanner(DeviceScanner):
"""This class queries a Salt Fiber Box router."""

def __init__(self, config):
"""Initialize the scanner."""
host = config[CONF_HOST]
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
self.saltbox = SaltBox(f"http://{host}", username, password)
self.online_clients = []

def scan_devices(self):
"""Scan for new devices and return a list with found device IDs."""
self._update_info()
return [client["mac"] for client in self.online_clients]

def get_device_name(self, device):
"""Return the name of the given device or None if we don't know."""
for client in self.online_clients:
if client["mac"] == device:
return client["name"]
return None

def get_salt_data(self):
"""Retrieve data from Salt router and return parsed result."""
try:
clients = self.saltbox.get_online_clients()
return clients
except (RouterLoginException, RouterNotReachableException) as error:
_LOGGER.warning(error)
return None

def _update_info(self):
"""Pull the current information from the Salt router."""
_LOGGER.debug("Loading data from Salt Fiber Box")
data = self.get_salt_data()
self.online_clients = data or []
8 changes: 8 additions & 0 deletions homeassistant/components/salt/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"domain": "salt",
"name": "Salt Fiber Box",
"documentation": "https://www.home-assistant.io/integrations/salt",
"requirements": ["saltbox==0.1.3"],
"dependencies": [],
"codeowners": ["@bjornorri"]
}
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,9 @@ russound_rio==0.1.7
# homeassistant.components.yamaha
rxv==0.6.0

# homeassistant.components.salt
saltbox==0.1.3

# homeassistant.components.samsungtv
samsungctl[websocket]==0.7.1

Expand Down