Example #1
0
def async_notify_setup_error(opp: OpenPeerPower,
                             component: str,
                             display_link: str | None = None) -> None:
    """Print a persistent notification.

    This method must be run in the event loop.
    """
    # pylint: disable=import-outside-toplevel
    from openpeerpower.components import persistent_notification

    errors = opp.data.get(DATA_PERSISTENT_ERRORS)

    if errors is None:
        errors = opp.data[DATA_PERSISTENT_ERRORS] = {}

    errors[component] = errors.get(component) or display_link

    message = "The following integrations and platforms could not be set up:\n\n"

    for name, link in errors.items():
        part = f"[{name}]({link})" if link else name
        message += f" - {part}\n"

    message += "\nPlease check your config and [logs](/config/logs)."

    persistent_notification.async_create(opp, message, "Invalid config",
                                         "invalid_config")
Example #2
0
 def connection_failed():
     """Connect failed tasks."""
     self.async_db_ready.set_result(False)
     persistent_notification.async_create(
         self.opp,
         "The recorder could not start, please check the log",
         "Recorder",
     )
Example #3
0
async def async_setup(opp: OpenPeerPower, config: dict):
    """Set up the Safe Mode component."""
    persistent_notification.async_create(
        opp,
        "Open Peer Power is running in safe mode. Check [the error log](/config/logs) to see what went wrong.",
        "Safe Mode",
    )
    return True
Example #4
0
def _reauth_flow_wrapper(opp, data):
    """Reauth flow wrapper."""
    opp.add_job(
        opp.config_entries.flow.async_init(DOMAIN,
                                           context={"source": SOURCE_REAUTH},
                                           data=data))
    persistent_notification.async_create(
        opp,
        "Blink configuration migrated to a new version. Please go to the integrations page to re-configure (such as sending a new 2FA key).",
        "Blink Migration",
    )
Example #5
0
    async def async_step_reauth(self, entry: dict[str, Any]) -> FlowResult:
        """Perform reauth upon migration of old entries."""
        if entry:
            self.entry = entry

        persistent_notification.async_create(
            self.opp,
            f"Spotify integration for account {entry['id']} needs to be re-authenticated. Please go to the integrations page to re-configure it.",
            "Spotify re-authentication",
            "spotify_reauth",
        )

        return await self.async_step_reauth_confirm()
Example #6
0
async def async_setup_entry(opp: core.OpenPeerPower,
                            entry: config_entries.ConfigEntry):
    """Set up a bridge from a config entry."""

    # Migrate allow_unreachable from config entry data to config entry options
    if (CONF_ALLOW_UNREACHABLE not in entry.options
            and CONF_ALLOW_UNREACHABLE in entry.data and
            entry.data[CONF_ALLOW_UNREACHABLE] != DEFAULT_ALLOW_UNREACHABLE):
        options = {
            **entry.options,
            CONF_ALLOW_UNREACHABLE:
            entry.data[CONF_ALLOW_UNREACHABLE],
        }
        data = entry.data.copy()
        data.pop(CONF_ALLOW_UNREACHABLE)
        opp.config_entries.async_update_entry(entry,
                                              data=data,
                                              options=options)

    # Migrate allow_hue_groups from config entry data to config entry options
    if (CONF_ALLOW_HUE_GROUPS not in entry.options
            and CONF_ALLOW_HUE_GROUPS in entry.data
            and entry.data[CONF_ALLOW_HUE_GROUPS] != DEFAULT_ALLOW_HUE_GROUPS):
        options = {
            **entry.options,
            CONF_ALLOW_HUE_GROUPS:
            entry.data[CONF_ALLOW_HUE_GROUPS],
        }
        data = entry.data.copy()
        data.pop(CONF_ALLOW_HUE_GROUPS)
        opp.config_entries.async_update_entry(entry,
                                              data=data,
                                              options=options)

    bridge = HueBridge(opp, entry)

    if not await bridge.async_setup():
        return False

    _register_services(opp)

    config = bridge.api.config

    # For backwards compat
    unique_id = normalize_bridge_id(config.bridgeid)
    if entry.unique_id is None:
        opp.config_entries.async_update_entry(entry, unique_id=unique_id)

    # For recovering from bug where we incorrectly assumed homekit ID = bridge ID
    elif entry.unique_id != unique_id:
        # Find entries with this unique ID
        other_entry = next(
            (entry for entry in opp.config_entries.async_entries(DOMAIN)
             if entry.unique_id == unique_id),
            None,
        )

        if other_entry is None:
            # If no other entry, update unique ID of this entry ID.
            opp.config_entries.async_update_entry(entry, unique_id=unique_id)

        elif other_entry.source == config_entries.SOURCE_IGNORE:
            # There is another entry but it is ignored, delete that one and update this one
            opp.async_create_task(
                opp.config_entries.async_remove(other_entry.entry_id))
            opp.config_entries.async_update_entry(entry, unique_id=unique_id)
        else:
            # There is another entry that already has the right unique ID. Delete this entry
            opp.async_create_task(
                opp.config_entries.async_remove(entry.entry_id))
            return False

    device_registry = await dr.async_get_registry(opp)
    device_registry.async_get_or_create(
        config_entry_id=entry.entry_id,
        connections={(dr.CONNECTION_NETWORK_MAC, config.mac)},
        identifiers={(DOMAIN, config.bridgeid)},
        manufacturer="Signify",
        name=config.name,
        model=config.modelid,
        sw_version=config.swversion,
    )

    if config.modelid == "BSB002" and config.swversion < "1935144040":
        persistent_notification.async_create(
            opp,
            "Your Hue hub has a known security vulnerability ([CVE-2020-6007](https://cve.circl.lu/cve/CVE-2020-6007)). Go to the Hue app and check for software updates.",
            "Signify Hue",
            "hue_hub_firmware",
        )

    elif config.swupdate2_bridge_state == "readytoinstall":
        err = (
            "Please check for software updates of the bridge in the Philips Hue App.",
            "Signify Hue",
            "hue_hub_firmware",
        )
        _LOGGER.warning(err)

    return True