Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for Lupusec Home Security system."""
2 
3 from json import JSONDecodeError
4 import logging
5 
6 import lupupy
7 from lupupy.exceptions import LupusecException
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
11 from homeassistant.core import HomeAssistant
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 DOMAIN = "lupusec"
16 
17 NOTIFICATION_ID = "lupusec_notification"
18 NOTIFICATION_TITLE = "Lupusec Security Setup"
19 
20 
21 PLATFORMS: list[Platform] = [
22  Platform.ALARM_CONTROL_PANEL,
23  Platform.BINARY_SENSOR,
24  Platform.SWITCH,
25 ]
26 
27 
28 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
29  """Set up this integration using UI."""
30 
31  host = entry.data[CONF_HOST]
32  username = entry.data[CONF_USERNAME]
33  password = entry.data[CONF_PASSWORD]
34 
35  try:
36  lupusec_system = await hass.async_add_executor_job(
37  lupupy.Lupusec, username, password, host
38  )
39  except LupusecException:
40  _LOGGER.error("Failed to connect to Lupusec device at %s", host)
41  return False
42  except JSONDecodeError:
43  _LOGGER.error("Failed to connect to Lupusec device at %s", host)
44  return False
45 
46  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = lupusec_system
47 
48  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
49 
50  return True
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:28