core/homeassistant/components/lupusec/__init__.py

89 lines
2.4 KiB
Python
Raw Normal View History

"""Support for Lupusec Home Security system."""
import logging
import lupupy
from lupupy.exceptions import LupusecException
import voluptuous as vol
from homeassistant.const import CONF_IP_ADDRESS, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
2019-07-31 19:25:30 +00:00
DOMAIN = "lupusec"
2019-07-31 19:25:30 +00:00
NOTIFICATION_ID = "lupusec_notification"
NOTIFICATION_TITLE = "Lupusec Security Setup"
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,
)
2019-07-31 19:25:30 +00:00
LUPUSEC_PLATFORMS = ["alarm_control_panel", "binary_sensor", "switch"]
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),
title=NOTIFICATION_TITLE,
2019-07-31 19:25:30 +00:00
notification_id=NOTIFICATION_ID,
)
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