Python homeassistant.config_entries.ConfigEntry() Examples

The following are 22 code examples of homeassistant.config_entries.ConfigEntry(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module homeassistant.config_entries , or try the search function .
Example #1
Source File: __init__.py    From blueprint with MIT License 6 votes vote down vote up
def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Handle removal of an entry."""
    coordinator = hass.data[DOMAIN][entry.entry_id]
    unloaded = all(
        await asyncio.gather(
            *[
                hass.config_entries.async_forward_entry_unload(entry, platform)
                for platform in PLATFORMS
                if platform in coordinator.platforms
            ]
        )
    )
    if unloaded:
        hass.data[DOMAIN].pop(entry.entry_id)

    return unloaded 
Example #2
Source File: __init__.py    From visonic with Apache License 2.0 6 votes vote down vote up
def async_options_updated(hass: HomeAssistant, entry: ConfigEntry):
    """Edit visonic entry."""
    log.info("************* update connection here ************** {0}".format(entry.entry_id))
    #log.info("     options {0}".format(entry.options))
    #log.info("     data    {0}".format(entry.data))

    client = hass.data[DOMAIN][DOMAINCLIENT][entry.unique_id]

    # convert python map to dictionary
    conf = {}
    # the entry.data dictionary contains all the old data used on creation and is a complete set
    for k in entry.data:
        conf[k] = entry.data[k]
    # the entry.config dictionary contains the latest/updated values but may not be a complete set
    for k in entry.options:
        conf[k] = entry.options[k]
       
    # save the parameters for control flow editing
    set_defaults(conf)
    
    # update the client parameter set
    client.updateConfig(conf)
    
    return True 
Example #3
Source File: __init__.py    From homeassistant-homeconnect with MIT License 6 votes vote down vote up
def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Home Connect from a config entry."""
    implementation = await config_entry_oauth2_flow.async_get_config_entry_implementation(
        hass, entry
    )

    hc_api = api.ConfigEntryAuth(hass, entry, implementation)

    hass.data[DOMAIN][entry.entry_id] = hc_api

    await update_all_devices(hass, entry)

    for component in PLATFORMS:
        hass.async_create_task(
            hass.config_entries.async_forward_entry_setup(entry, component)
        )

    return True 
Example #4
Source File: sensor.py    From unifiprotect with MIT License 6 votes vote down vote up
def async_setup_entry(
    hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) -> None:
    """A Ubiquiti Unifi Protect Sensor."""
    upv_object = hass.data[DOMAIN][entry.entry_id]["upv"]
    coordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
    if not coordinator.data:
        return

    sensors = []
    for sensor in SENSOR_TYPES:
        for camera in coordinator.data:
            sensors.append(UnifiProtectSensor(upv_object, coordinator, camera, sensor))
            _LOGGER.debug("UNIFIPROTECT SENSOR CREATED: %s", sensor)

    async_add_entities(sensors, True)

    return True 
Example #5
Source File: __init__.py    From unifiprotect with MIT License 5 votes vote down vote up
def _async_get_or_create_nvr_device_in_registry(
    hass: HomeAssistantType, entry: ConfigEntry, nvr
) -> None:
    device_registry = await dr.async_get_registry(hass)
    device_registry.async_get_or_create(
        config_entry_id=entry.entry_id,
        connections={(dr.CONNECTION_NETWORK_MAC, nvr["server_id"])},
        identifiers={(DOMAIN, nvr["server_id"])},
        manufacturer=DEFAULT_BRAND,
        name=entry.data[CONF_ID],
        model=nvr["server_model"],
        sw_version=nvr["server_version"],
    ) 
Example #6
Source File: config_flow.py    From wiserHomeAssistantPlatform with MIT License 5 votes vote down vote up
def __init__(self, config_entry: config_entries.ConfigEntry):
        """Initialize options flow."""
        self.config_entry = config_entry 
Example #7
Source File: __init__.py    From blueprint with MIT License 5 votes vote down vote up
def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Reload config entry."""
    await async_unload_entry(hass, entry)
    await async_setup_entry(hass, entry) 
Example #8
Source File: __init__.py    From blueprint with MIT License 5 votes vote down vote up
def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Set up this integration using UI."""
    if hass.data.get(DOMAIN) is None:
        hass.data.setdefault(DOMAIN, {})
        _LOGGER.info(STARTUP_MESSAGE)

    username = entry.data.get(CONF_USERNAME)
    password = entry.data.get(CONF_PASSWORD)

    coordinator = BlueprintDataUpdateCoordinator(
        hass, username=username, password=password
    )
    await coordinator.async_refresh()

    if not coordinator.last_update_success:
        raise ConfigEntryNotReady

    hass.data[DOMAIN][entry.entry_id] = coordinator

    for platform in PLATFORMS:
        if entry.options.get(platform, True):
            coordinator.platforms.append(platform)
            hass.async_add_job(
                hass.config_entries.async_forward_entry_setup(entry, platform)
            )

    entry.add_update_listener(async_reload_entry)
    return True 
Example #9
Source File: __init__.py    From hass-opensprinkler with MIT License 5 votes vote down vote up
def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Unload a config entry."""
    unload_ok = all(
        await asyncio.gather(
            *[
                hass.config_entries.async_forward_entry_unload(entry, component)
                for component in PLATFORMS
            ]
        )
    )
    if unload_ok:
        hass.data[DOMAIN].pop(entry.entry_id)

    return unload_ok 
Example #10
Source File: config_flow.py    From SmartHouse with MIT License 5 votes vote down vote up
def __init__(self, config_entry: config_entries.ConfigEntry):
        """Initialize options flow."""
        self.config_entry = config_entry 
Example #11
Source File: __init__.py    From unifiprotect with MIT License 5 votes vote down vote up
def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
    """Unload Unifi Protect config entry."""
    unload_ok = all(
        await asyncio.gather(
            *[
                hass.config_entries.async_forward_entry_unload(entry, component)
                for component in UNIFI_PROTECT_PLATFORMS
            ]
        )
    )

    if unload_ok:
        hass.data[DOMAIN].pop(entry.entry_id)

    return unload_ok 
Example #12
Source File: __init__.py    From unifiprotect with MIT License 5 votes vote down vote up
def async_update_options(hass: HomeAssistantType, entry: ConfigEntry):
    """Update options."""
    await hass.config_entries.async_reload(entry.entry_id) 
Example #13
Source File: switch.py    From visonic with Apache License 2.0 5 votes vote down vote up
def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities ) -> None:
    """Set up the Visonic Alarm Binary Sensors"""
    if DOMAIN in hass.data:
        client = hass.data[DOMAIN][DOMAINCLIENT][entry.unique_id]
        devices = [
            VisonicSwitch(hass, client, device)
            for device in hass.data[DOMAIN]['switch']   
        ]
        hass.data[DOMAIN]["switch"] = list()
        async_add_entities(devices) 
Example #14
Source File: binary_sensor.py    From unifiprotect with MIT License 5 votes vote down vote up
def async_setup_entry(
    hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) -> None:
    """A Ubiquiti Unifi Protect Binary Sensor."""
    upv_object = hass.data[DOMAIN][entry.entry_id]["upv"]
    coordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
    if not coordinator.data:
        return

    sensors = []
    for camera in coordinator.data:
        if coordinator.data[camera]["type"] == DEVICE_CLASS_DOORBELL:
            sensors.append(
                UnifiProtectBinarySensor(
                    upv_object, coordinator, camera, DEVICE_CLASS_DOORBELL
                )
            )
            _LOGGER.debug(
                "UNIFIPROTECT DOORBELL SENSOR CREATED: %s",
                coordinator.data[camera]["name"],
            )

        sensors.append(
            UnifiProtectBinarySensor(
                upv_object, coordinator, camera, DEVICE_CLASS_MOTION
            )
        )
        _LOGGER.debug(
            "UNIFIPROTECT MOTION SENSOR CREATED: %s", coordinator.data[camera]["name"]
        )

    async_add_entities(sensors, True)

    return True 
Example #15
Source File: switch.py    From unifiprotect with MIT License 5 votes vote down vote up
def async_setup_entry(
    hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) -> None:
    """A Ubiquiti Unifi Protect Sensor."""
    upv_object = hass.data[DOMAIN][entry.entry_id]["upv"]
    coordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
    if not coordinator.data:
        return

    ir_on = entry.data[CONF_IR_ON]
    if ir_on == "always_on":
        ir_on = "on"

    ir_off = entry.data[CONF_IR_OFF]
    if ir_off == "led_off":
        ir_off = "autoFilterOnly"
    elif ir_off == "always_off":
        ir_off = "off"

    switches = []
    for switch in SWITCH_TYPES:
        for camera in coordinator.data:
            switches.append(
                UnifiProtectSwitch(
                    upv_object, coordinator, camera, switch, ir_on, ir_off,
                )
            )
            _LOGGER.debug("UNIFIPROTECT SWITCH CREATED: %s", switch)

    async_add_entities(switches, True)

    return True 
Example #16
Source File: api.py    From homeassistant-homeconnect with MIT License 5 votes vote down vote up
def __init__(
        self,
        hass: core.HomeAssistant,
        config_entry: config_entries.ConfigEntry,
        implementation: config_entry_oauth2_flow.AbstractOAuth2Implementation,
    ):
        """Initialize Home Connect Auth."""
        self.hass = hass
        self.config_entry = config_entry
        self.session = config_entry_oauth2_flow.OAuth2Session(
            hass, config_entry, implementation
        )
        super().__init__(self.session.token)
        self.devices = [] 
Example #17
Source File: __init__.py    From homeassistant-homeconnect with MIT License 5 votes vote down vote up
def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Unload a config entry."""
    unload_ok = all(
        await asyncio.gather(
            *[
                hass.config_entries.async_forward_entry_unload(entry, component)
                for component in PLATFORMS
            ]
        )
    )
    if unload_ok:
        hass.data[DOMAIN].pop(entry.entry_id)

    return unload_ok 
Example #18
Source File: alarm_control_panel.py    From visonic with Apache License 2.0 5 votes vote down vote up
def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities ) -> None:
    #_LOGGER.info("alarm control panel async_setup_entry called")
    client = hass.data[DOMAIN][DOMAINCLIENT][entry.unique_id]
    va = VisonicAlarm(hass, client, 1)
    devices = [va]
    async_add_entities(devices) 
Example #19
Source File: __init__.py    From visonic with Apache License 2.0 5 votes vote down vote up
def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Unload visonic entry."""
    log.info("************* terminate connection here ************** {0}".format(entry.entry_id))
    #log.info("     options {0}".format(entry.options))
    #log.info("     data    {0}".format(entry.data))

    client = hass.data[DOMAIN][DOMAINCLIENT][entry.unique_id]

    # stop the comms to/from the panel
    await client.service_comms_stop(None)
    # stop all activity in the client
    await client.service_panel_stop(None)
    
    unload_ok = all(
        await asyncio.gather(
            *[
                hass.config_entries.async_forward_entry_unload(entry, component)
                for component in PLATFORMS
            ]
        )
    )

    if not unload_ok:
        return False
    return True


# This function is called when there have been changes made to the parameters in the control flow 
Example #20
Source File: binary_sensor.py    From visonic with Apache License 2.0 5 votes vote down vote up
def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities ) -> None:
    """Set up the Visonic Alarm Binary Sensors"""
    
    _LOGGER.info("************* binary sensor async_setup_entry **************")
    #_LOGGER.info("     options {0}".format(entry.options))
    #_LOGGER.info("     data    {0}".format(entry.data))
    
#    @callback
#    def async_add_binary_sensor(binary_sensor):
#        """Add Visonic binary sensor."""
#        _LOGGER.info(f"   got device {binary_sensor.getDeviceID()}")
#        async_add_entities([binary_sensor], True)

#    async_dispatcher_connect(hass, "visonic_new_binary_sensor", async_add_binary_sensor)

    if DOMAIN in hass.data:
        _LOGGER.info("   In binary sensor async_setup_entry")
        sensors = [
            VisonicSensor(device)
            for device in hass.data[DOMAIN]['binary_sensor']   
        ]
        # empty the list as we have copied the entries so far in to sensors
        hass.data[DOMAIN]["binary_sensor"] = list()       
        async_add_entities(sensors, True)

#   Each Sensor in Visonic Alarms can be Armed/Bypassed individually 
Example #21
Source File: __init__.py    From hass-opensprinkler with MIT License 4 votes vote down vote up
def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Set up OpenSprinkler from a config entry."""
    hass.data.setdefault(DOMAIN, {})

    url = entry.data.get(CONF_URL)
    password = entry.data.get(CONF_PASSWORD)
    try:
        controller = OpenSprinkler(url, password)
        controller.refresh_on_update = False

        async def async_update_data():
            """Fetch data from OpenSprinkler."""
            _LOGGER.debug("refreshing data")
            async with async_timeout.timeout(TIMEOUT):
                try:
                    await hass.async_add_executor_job(controller.refresh)
                except Exception as exc:
                    raise UpdateFailed("Error fetching OpenSprinkler state") from exc

                if not controller._state:
                    raise UpdateFailed("Error fetching OpenSprinkler state")

                return controller._state

        scan_interval = entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
        coordinator = DataUpdateCoordinator(
            hass,
            _LOGGER,
            name="OpenSprinkler resource status",
            update_method=async_update_data,
            update_interval=timedelta(seconds=scan_interval),
        )

        # initial load before loading platforms
        await coordinator.async_refresh()

        hass.data[DOMAIN][entry.entry_id] = {
            "coordinator": coordinator,
            "controller": controller,
        }

    except (OpenSprinklerAuthError, OpenSprinklerConnectionError) as exc:
        _LOGGER.error("Unable to connect to OpenSprinkler controller: %s", str(exc))
        raise ConfigEntryNotReady

    for component in PLATFORMS:
        hass.async_create_task(
            hass.config_entries.async_forward_entry_setup(entry, component)
        )

    return True 
Example #22
Source File: __init__.py    From visonic with Apache License 2.0 4 votes vote down vote up
def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Set up visonic from a config entry."""

    if entry.unique_id is None:
        log.info("visonic unique id was None")
        hass.config_entries.async_update_entry(entry, unique_id=VISONIC_UNIQUE_ID)
    
    log.info("************* create connection here ************** {0}".format(entry.entry_id))
    #log.info("     options {0}".format(entry.options))
    #log.info("     data    {0}".format(entry.data))

    # convert python map to dictionary
    conf = {}
    # the entry.data dictionary contains all the old data used on creation and is a complete set
    for k in entry.data:
        conf[k] = entry.data[k]
    # the entry.config dictionary contains the latest/updated values but may not be a complete set
    for k in entry.options:
        conf[k] = entry.options[k]

    # push the merged data back in to HA
    hass.config_entries.async_update_entry(entry, options=conf)

    # save the parameters for control flow editing purposes
    set_defaults(conf)

    # create client and connect to the panel
    try:
        # create the client ready to connect to the panel
        client = VisonicClient(hass, conf, entry)
        # Save the client ref
        hass.data[DOMAIN][DOMAINCLIENT][entry.unique_id] = client
        # connect to the panel
        await hass.async_add_executor_job(client.connect)
        # add update listener
        entry.add_update_listener(async_options_updated)
        # return true to indicate success
        return True
    except requests.exceptions.ConnectionError as error:
        log.error( "Visonic Panel could not be reached: [%s]", error)
        raise ConfigEntryNotReady
    return False

# This function is called to terminate a client connection to the alarm panel