2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lupusec Home Security system."""
|
2018-11-07 11:51:12 +00:00
|
|
|
import logging
|
|
|
|
|
2019-10-21 08:07:09 +00:00
|
|
|
import lupupy
|
|
|
|
from lupupy.exceptions import LupusecException
|
2018-11-07 11:51:12 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-10-21 08:07:09 +00:00
|
|
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
|
|
|
from homeassistant.helpers import config_validation as cv, discovery
|
2018-11-07 11:51:12 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2019-02-14 04:35:12 +00:00
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN = "lupusec"
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
NOTIFICATION_ID = "lupusec_notification"
|
|
|
|
NOTIFICATION_TITLE = "Lupusec Security Setup"
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
DOMAIN: vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
vol.Required(CONF_IP_ADDRESS): cv.string,
|
|
|
|
vol.Optional(CONF_NAME): cv.string,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
LUPUSEC_PLATFORMS = ["alarm_control_panel", "binary_sensor", "switch"]
|
2018-11-07 11:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup(hass, config):
|
|
|
|
"""Set up Lupusec component."""
|
|
|
|
conf = config[DOMAIN]
|
|
|
|
username = conf[CONF_USERNAME]
|
|
|
|
password = conf[CONF_PASSWORD]
|
|
|
|
ip_address = conf[CONF_IP_ADDRESS]
|
|
|
|
name = conf.get(CONF_NAME)
|
|
|
|
|
|
|
|
try:
|
|
|
|
hass.data[DOMAIN] = LupusecSystem(username, password, ip_address, name)
|
|
|
|
except LupusecException as ex:
|
|
|
|
_LOGGER.error(ex)
|
|
|
|
|
|
|
|
hass.components.persistent_notification.create(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Error: {}<br />"
|
|
|
|
"You will need to restart hass after fixing."
|
|
|
|
"".format(ex),
|
2018-11-07 11:51:12 +00:00
|
|
|
title=NOTIFICATION_TITLE,
|
2019-07-31 19:25:30 +00:00
|
|
|
notification_id=NOTIFICATION_ID,
|
|
|
|
)
|
2018-11-07 11:51:12 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
for platform in LUPUSEC_PLATFORMS:
|
|
|
|
discovery.load_platform(hass, platform, DOMAIN, {}, config)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class LupusecSystem:
|
|
|
|
"""Lupusec System class."""
|
|
|
|
|
|
|
|
def __init__(self, username, password, ip_address, name):
|
|
|
|
"""Initialize the system."""
|
|
|
|
self.lupusec = lupupy.Lupusec(username, password, ip_address)
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
|
|
|
|
class LupusecDevice(Entity):
|
|
|
|
"""Representation of a Lupusec device."""
|
|
|
|
|
|
|
|
def __init__(self, data, device):
|
|
|
|
"""Initialize a sensor for Lupusec device."""
|
|
|
|
self._data = data
|
|
|
|
self._device = device
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update automation state."""
|
|
|
|
self._device.refresh()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._device.name
|