Exemple #1
0
from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST, CONF_PASSWORD, EVENT_OPENPEERPOWER_STOP
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

DEFAULT_IP = "192.168.0.1"

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_PASSWORD):
    cv.string,
    vol.Optional(CONF_HOST, default=DEFAULT_IP):
    cv.string,
})


async def async_get_scanner(opp, config):
    """Return the UPC device scanner."""
    conf = config[DOMAIN]
    session = opp.helpers.aiohttp_client.async_get_clientsession()
    connect_box = ConnectBox(session,
                             conf[CONF_PASSWORD],
                             host=conf[CONF_HOST])

    # Check login data
    try:
        await connect_box.async_initialize_token()
Exemple #2
0
)
from openpeerpower.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

DEFAULT_SSH_PORT = 22
UNIFI_COMMAND = 'mca-dump | tr -d "\n"'
UNIFI_SSID_TABLE = "vap_table"
UNIFI_CLIENT_TABLE = "sta_table"

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Required(CONF_PASSWORD):
    cv.string,
    vol.Required(CONF_USERNAME):
    cv.string,
    vol.Optional(CONF_PORT, default=DEFAULT_SSH_PORT):
    cv.port,
})


def get_scanner(opp, config):
    """Validate the configuration and return a Unifi direct scanner."""
    scanner = UnifiDeviceScanner(config[DOMAIN])
    if not scanner.connected:
        return False
    return scanner


class UnifiDeviceScanner(DeviceScanner):
Exemple #3
0
CONF_DEVICES = "devices"
CONF_SECRET = "secret"

DATA_CONFIGURING = "automatic_configurator_clients"
DATA_REFRESH_TOKEN = "refresh_token"
DEFAULT_SCOPE = ["location", "trip", "vehicle:events", "vehicle:profile"]
DEFAULT_TIMEOUT = 5
EVENT_AUTOMATIC_UPDATE = "automatic_update"

FULL_SCOPE = DEFAULT_SCOPE + ["current_location"]

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_CLIENT_ID):
    cv.string,
    vol.Required(CONF_SECRET):
    cv.string,
    vol.Optional(CONF_CURRENT_LOCATION, default=False):
    cv.boolean,
    vol.Optional(CONF_DEVICES):
    vol.All(cv.ensure_list, [cv.string]),
})


def _get_refresh_token_from_file(opp, filename):
    """Attempt to load session data from file."""
    path = opp.config.path(filename)

    if not os.path.isfile(path):
        return None

    try:
        with open(path) as data_file:
Exemple #4
0
_DDWRT_DATA_REGEX = re.compile(r"\{(\w+)::([^\}]*)\}")
_MAC_REGEX = re.compile(r"(([0-9A-Fa-f]{1,2}\:){5}[0-9A-Fa-f]{1,2})")

DEFAULT_SSL = False
DEFAULT_VERIFY_SSL = True
CONF_WIRELESS_ONLY = "wireless_only"
DEFAULT_WIRELESS_ONLY = True

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Required(CONF_PASSWORD):
    cv.string,
    vol.Required(CONF_USERNAME):
    cv.string,
    vol.Optional(CONF_SSL, default=DEFAULT_SSL):
    cv.boolean,
    vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL):
    cv.boolean,
    vol.Optional(CONF_WIRELESS_ONLY, default=DEFAULT_WIRELESS_ONLY):
    cv.boolean,
})


def get_scanner(opp, config):
    """Validate the configuration and return a DD-WRT scanner."""
    try:
        return DdWrtDeviceScanner(config[DOMAIN])
    except ConnectionError:
        return None
Exemple #5
0
_LOGGER = logging.getLogger(__name__)

_DEVICES_REGEX = re.compile(
    r"(?P<mac>(([0-9a-f]{2}[:-]){5}([0-9a-f]{2})))\s"
    r"(?P<ip>([0-9]{1,3}[\.]){3}[0-9]{1,3})\s+"
    r"(?P<status>([^\s]+))\s+"
    r"(?P<type>([^\s]+))\s+"
    r"(?P<intf>([^\s]+))\s+"
    r"(?P<hwintf>([^\s]+))\s+"
    r"(?P<host>([^\s]+))"
)

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


def get_scanner(opp, config):
    """Validate the configuration and return a THOMSON scanner."""
    scanner = ThomsonDeviceScanner(config[DOMAIN])

    return scanner if scanner.success_init else None


class ThomsonDeviceScanner(DeviceScanner):
    """This class queries a router running THOMSON firmware."""
Exemple #6
0
    HTTP_UNAUTHORIZED,
)
import openpeerpower.helpers.config_validation as cv

CONF_HTTP_ID = "http_id"

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Optional(CONF_PORT):
    cv.port,
    vol.Optional(CONF_SSL, default=False):
    cv.boolean,
    vol.Optional(CONF_VERIFY_SSL, default=True):
    vol.Any(cv.boolean, cv.isfile),
    vol.Required(CONF_PASSWORD):
    cv.string,
    vol.Required(CONF_USERNAME):
    cv.string,
    vol.Required(CONF_HTTP_ID):
    cv.string,
})


def get_scanner(opp, config):
    """Validate the configuration and returns a Tomato scanner."""
    return TomatoDeviceScanner(config[DOMAIN])


class TomatoDeviceScanner(DeviceScanner):
Exemple #7
0
from .const import (
    CONF_AUTH_KEY,
    CONF_BASEOID,
    CONF_COMMUNITY,
    CONF_PRIV_KEY,
    DEFAULT_COMMUNITY,
)

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_BASEOID):
    cv.string,
    vol.Required(CONF_HOST):
    cv.string,
    vol.Optional(CONF_COMMUNITY, default=DEFAULT_COMMUNITY):
    cv.string,
    vol.Inclusive(CONF_AUTH_KEY, "keys"):
    cv.string,
    vol.Inclusive(CONF_PRIV_KEY, "keys"):
    cv.string,
})


def get_scanner(opp, config):
    """Validate the configuration and return an SNMP scanner."""
    scanner = SnmpScanner(config[DOMAIN])

    return scanner if scanner.success_init else None


class SnmpScanner(DeviceScanner):
Exemple #8
0
from pyskyqhub.skyq_hub import SkyQHub
import voluptuous as vol

from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST
from openpeerpower.helpers.aiohttp_client import async_get_clientsession
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string})


async def async_get_scanner(opp, config):
    """Return a Sky Hub scanner if successful."""
    host = config[DOMAIN].get(CONF_HOST, "192.168.1.254")
    websession = async_get_clientsession(opp)
    hub = SkyQHub(websession, host)

    _LOGGER.debug("Initialising Sky Hub")
    await hub.async_connect()
    if hub.success_init:
        scanner = SkyHubDeviceScanner(hub)
        return scanner

    return None
Exemple #9
0
)
from openpeerpower.components.http import OpenPeerPowerView
from openpeerpower.const import HTTP_BAD_REQUEST, HTTP_UNPROCESSABLE_ENTITY
from openpeerpower.core import callback
import openpeerpower.helpers.config_validation as cv

CONF_VALIDATOR = "validator"
CONF_SECRET = "secret"
URL = "/api/meraki"
VERSION = "2.0"

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_VALIDATOR):
    cv.string,
    vol.Required(CONF_SECRET):
    cv.string
})


async def async_setup_scanner(opp, config, async_see, discovery_info=None):
    """Set up an endpoint for the Meraki tracker."""
    opp.http.register_view(MerakiView(config, async_see))

    return True


class MerakiView(OpenPeerPowerView):
    """View to handle Meraki requests."""

    url = URL
Exemple #10
0
    DEFAULT_INTERFACE,
    DEFAULT_SCAN_INTERVAL,
    DEFAULT_TELNET_PORT,
    DOMAIN,
    ROUTER,
)
from .router import KeeneticRouter

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = DEVICE_TRACKER_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Required(CONF_USERNAME):
    cv.string,
    vol.Required(CONF_PORT, default=DEFAULT_TELNET_PORT):
    cv.port,
    vol.Required(CONF_PASSWORD):
    cv.string,
    vol.Required(CONF_LEGACY_INTERFACE, default=DEFAULT_INTERFACE):
    cv.string,
})


async def async_get_scanner(opp: OpenPeerPower, config):
    """Import legacy configuration from YAML."""

    scanner_config = config[DEVICE_TRACKER_DOMAIN]
    scan_interval: timedelta | None = scanner_config.get(CONF_SCAN_INTERVAL)
    consider_home: timedelta | None = scanner_config.get(CONF_CONSIDER_HOME)

    host: str = scanner_config[CONF_HOST]
Exemple #11
0
from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST, CONF_TOKEN, CONF_VERIFY_SSL
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)
DEFAULT_VERIFY_SSL = False

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Required(CONF_TOKEN):
    cv.string,
    vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL):
    cv.boolean,
})


def get_scanner(opp, config):
    """Validate the configuration and return a FortiOSDeviceScanner."""
    host = config[DOMAIN][CONF_HOST]
    verify_ssl = config[DOMAIN][CONF_VERIFY_SSL]
    token = config[DOMAIN][CONF_TOKEN]

    fgt = FortiOSAPI()

    try:
        fgt.tokenlogin(host, token, verify_ssl)
Exemple #12
0
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

CONF_DHCP_SOFTWARE = "dhcp_software"
DEFAULT_DHCP_SOFTWARE = "dnsmasq"
DHCP_SOFTWARES = ["dnsmasq", "odhcpd", "none"]

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_HOST): cv.string,
        vol.Required(CONF_PASSWORD): cv.string,
        vol.Required(CONF_USERNAME): cv.string,
        vol.Optional(CONF_DHCP_SOFTWARE, default=DEFAULT_DHCP_SOFTWARE): vol.In(
            DHCP_SOFTWARES
        ),
    }
)


def get_scanner(opp, config):
    """Validate the configuration and return an ubus scanner."""
    dhcp_sw = config[DOMAIN][CONF_DHCP_SOFTWARE]
    if dhcp_sw == "dnsmasq":
        scanner = DnsmasqUbusDeviceScanner(config[DOMAIN])
    elif dhcp_sw == "odhcpd":
        scanner = OdhcpdUbusDeviceScanner(config[DOMAIN])
    else:
        scanner = UbusDeviceScanner(config[DOMAIN])
Exemple #13
0
from openpeerpower.core import callback
import openpeerpower.helpers.config_validation as cv

from ... import mqtt
from ..const import CONF_QOS

CONF_PAYLOAD_HOME = "payload_home"
CONF_PAYLOAD_NOT_HOME = "payload_not_home"
CONF_SOURCE_TYPE = "source_type"

PLATFORM_SCHEMA_YAML = PLATFORM_SCHEMA.extend(mqtt.SCHEMA_BASE).extend({
    vol.Required(CONF_DEVICES): {
        cv.string: mqtt.valid_subscribe_topic
    },
    vol.Optional(CONF_PAYLOAD_HOME, default=STATE_HOME):
    cv.string,
    vol.Optional(CONF_PAYLOAD_NOT_HOME, default=STATE_NOT_HOME):
    cv.string,
    vol.Optional(CONF_SOURCE_TYPE):
    vol.In(SOURCE_TYPES),
})


async def async_setup_scanner_from_yaml(opp,
                                        config,
                                        async_see,
                                        discovery_info=None):
    """Set up the MQTT tracker."""
    devices = config[CONF_DEVICES]
    qos = config[CONF_QOS]
    payload_home = config[CONF_PAYLOAD_HOME]
Exemple #14
0
from miio import DeviceException, WifiRepeater
import voluptuous as vol

from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST, CONF_TOKEN
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Required(CONF_TOKEN):
    vol.All(cv.string, vol.Length(min=32, max=32)),
})


def get_scanner(opp, config):
    """Return a Xiaomi MiIO device scanner."""
    scanner = None
    host = config[DOMAIN][CONF_HOST]
    token = config[DOMAIN][CONF_TOKEN]

    _LOGGER.info("Initializing with host %s (token %s...)", host, token[:5])

    try:
        device = WifiRepeater(host, token)
        device_info = device.info()
Exemple #15
0
CONF_CALLSIGNS = "callsigns"

DEFAULT_HOST = "rotate.aprs2.net"
DEFAULT_PASSWORD = "******"
DEFAULT_TIMEOUT = 30.0

FILTER_PORT = 14580

MSG_FORMATS = ["compressed", "uncompressed", "mic-e"]

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_CALLSIGNS): cv.ensure_list,
        vol.Required(CONF_USERNAME): cv.string,
        vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
        vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
        vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): vol.Coerce(float),
    }
)


def make_filter(callsigns: list) -> str:
    """Make a server-side filter from a list of callsigns."""
    return " ".join(f"b/{sign.upper()}" for sign in callsigns)


def gps_accuracy(gps, posambiguity: int) -> int:
    """Calculate the GPS accuracy based on APRS posambiguity."""

    pos_a_map = {0: 0, 1: 1 / 600, 2: 1 / 60, 3: 1 / 6, 4: 1}
Exemple #16
0
import bthomehub5_devicelist
import voluptuous as vol

from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

CONF_DEFAULT_IP = "192.168.1.254"

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
    {vol.Optional(CONF_HOST, default=CONF_DEFAULT_IP): cv.string})


def get_scanner(opp, config):
    """Return a BT Home Hub 5 scanner if successful."""
    scanner = BTHomeHub5DeviceScanner(config[DOMAIN])

    return scanner if scanner.success_init else None


class BTHomeHub5DeviceScanner(DeviceScanner):
    """This class queries a BT Home Hub 5."""
    def __init__(self, config):
        """Initialise the scanner."""

        _LOGGER.info("Initialising BT Home Hub 5")
Exemple #17
0
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

GPS_JSON_PAYLOAD_SCHEMA = vol.Schema(
    {
        vol.Required(ATTR_LATITUDE): vol.Coerce(float),
        vol.Required(ATTR_LONGITUDE): vol.Coerce(float),
        vol.Optional(ATTR_GPS_ACCURACY): vol.Coerce(int),
        vol.Optional(ATTR_BATTERY_LEVEL): vol.Coerce(str),
    },
    extra=vol.ALLOW_EXTRA,
)

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(mqtt.SCHEMA_BASE).extend(
    {vol.Required(CONF_DEVICES): {cv.string: mqtt.valid_subscribe_topic}}
)


async def async_setup_scanner(opp, config, async_see, discovery_info=None):
    """Set up the MQTT JSON tracker."""
    devices = config[CONF_DEVICES]
    qos = config[CONF_QOS]

    for dev_id, topic in devices.items():

        @callback
        def async_message_received(msg, dev_id=dev_id):
            """Handle received MQTT message."""
            try:
                data = GPS_JSON_PAYLOAD_SCHEMA(json.loads(msg.payload))
Exemple #18
0
from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_HOST, CONF_PASSWORD, CONF_SSL
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

DEFAULT_HOST = "myfiosgateway.com"

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_HOST, default=DEFAULT_HOST):
    cv.string,
    vol.Optional(CONF_SSL, default=True):
    cv.boolean,
    vol.Required(CONF_PASSWORD):
    cv.string,
})


def get_scanner(opp, config):
    """Validate the configuration and return a Quantum Gateway scanner."""
    scanner = QuantumGatewayDeviceScanner(config[DOMAIN])

    return scanner if scanner.success_init else None


class QuantumGatewayDeviceScanner(DeviceScanner):
    """This class queries a Quantum Gateway."""
    def __init__(self, config):
Exemple #19
0
from openpeerpower.components.device_tracker import (
    DOMAIN,
    PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
    DeviceScanner,
)
from openpeerpower.const import CONF_API_KEY, CONF_CLIENT_ID, CONF_HOST
import openpeerpower.helpers.config_validation as cv

SCAN_INTERVAL = timedelta(seconds=120)

GRANT_TYPE = "client_credentials"

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Required(CONF_CLIENT_ID):
    cv.string,
    vol.Required(CONF_API_KEY):
    cv.string,
})

_LOGGER = logging.getLogger(__name__)


def get_scanner(opp, config):
    """Initialize Scanner."""

    data = {
        "server": config[DOMAIN][CONF_HOST],
        "grant_type": GRANT_TYPE,
        "secret": config[DOMAIN][CONF_API_KEY],
        "client": config[DOMAIN][CONF_CLIENT_ID],
Exemple #20
0
    CONF_PORT,
    CONF_SSL,
    CONF_USERNAME,
)
import openpeerpower.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

CONF_APS = "accesspoints"

PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
    {
        vol.Optional(CONF_HOST, default=""): cv.string,
        vol.Optional(CONF_SSL, default=False): cv.boolean,
        vol.Optional(CONF_USERNAME, default=""): cv.string,
        vol.Required(CONF_PASSWORD): cv.string,
        vol.Optional(CONF_PORT): cv.port,
        vol.Optional(CONF_DEVICES, default=[]): vol.All(cv.ensure_list, [cv.string]),
        vol.Optional(CONF_EXCLUDE, default=[]): vol.All(cv.ensure_list, [cv.string]),
        vol.Optional(CONF_APS, default=[]): vol.All(cv.ensure_list, [cv.string]),
    }
)


def get_scanner(opp, config):
    """Validate the configuration and returns a Netgear scanner."""
    info = config[DOMAIN]
    host = info[CONF_HOST]
    ssl = info[CONF_SSL]
    username = info[CONF_USERNAME]
    password = info[CONF_PASSWORD]
    port = info.get(CONF_PORT)