Ejemplo n.º 1
0
    def need_update(self) -> bool:
        """Return True if an update is available."""
        if self.sys_dev:
            return False

        try:
            return pkg_parse(self.version) < pkg_parse(self.latest_version)
        except (TypeError, ValueError):
            return False
Ejemplo n.º 2
0
    async def _validate_version(self) -> None:
        """Validate Version of NetworkManager."""
        self.properties = await self.dbus.get_properties(DBUS_NAME_NM)

        try:
            if pkg_parse(self.version) >= pkg_parse(MINIMAL_VERSION):
                return
        except (TypeError, ValueError, KeyError):
            pass

        _LOGGER.error("Version '%s' of NetworkManager is not supported!", self.version)
        raise HostNotSupportedError()
Ejemplo n.º 3
0
    async def load(self) -> None:
        """Load Supervisor plugins."""
        # Sequential to avoid issue on slow IO
        for plugin in (
            self.dns,
            self.audio,
            self.cli,
            self.observer,
            self.multicast,
        ):
            try:
                await plugin.load()
            except Exception as err:  # pylint: disable=broad-except
                _LOGGER.warning("Can't load plugin %s: %s", type(plugin).__name__, err)
                self.sys_capture_exception(err)

        # Check requirements
        for plugin, required_version in (
            (self._audio, self.required_audio),
            (self._dns, self.required_dns),
            (self._cli, self.required_cli),
            (self._observer, self.required_observer),
            (self._multicast, self.required_multicast),
        ):
            # Check if need an update
            try:
                if pkg_parse(plugin.version) >= required_version:
                    continue
            except TypeError:
                _LOGGER.warning(
                    "Somethings going wrong with requirements on %s",
                    type(plugin).__name__,
                )

            _LOGGER.info(
                "Requirement need update for %s - %s",
                type(plugin).__name__,
                required_version,
            )
            try:
                await plugin.update(version=str(required_version))
            except HassioError:
                _LOGGER.error(
                    "Can't update %s to %s but it's a reuirement, the Supervisor is not health now!",
                    type(plugin).__name__,
                    required_version,
                )
            except Exception as err:  # pylint: disable=broad-except
                _LOGGER.warning(
                    "Can't update plugin %s: %s", type(plugin).__name__, err
                )
                self.sys_capture_exception(err)
Ejemplo n.º 4
0
class PluginManager(CoreSysAttributes):
    """Manage supported function for plugins."""

    required_cli: LegacyVersion = pkg_parse("26")
    required_dns: LegacyVersion = pkg_parse("9")
    required_audio: LegacyVersion = pkg_parse("17")
    required_observer: LegacyVersion = pkg_parse("2")
    required_multicast: LegacyVersion = pkg_parse("3")

    def __init__(self, coresys: CoreSys):
        """Initialize plugin manager."""
        self.coresys: CoreSys = coresys

        self._cli: HaCli = HaCli(coresys)
        self._dns: CoreDNS = CoreDNS(coresys)
        self._audio: Audio = Audio(coresys)
        self._observer: Observer = Observer(coresys)
        self._multicast: Multicast = Multicast(coresys)

    @property
    def cli(self) -> HaCli:
        """Return cli handler."""
        return self._cli

    @property
    def dns(self) -> CoreDNS:
        """Return dns handler."""
        return self._dns

    @property
    def audio(self) -> Audio:
        """Return audio handler."""
        return self._audio

    @property
    def observer(self) -> Observer:
        """Return observer handler."""
        return self._observer

    @property
    def multicast(self) -> Multicast:
        """Return multicast handler."""
        return self._multicast

    async def load(self) -> None:
        """Load Supervisor plugins."""
        # Sequential to avoid issue on slow IO
        for plugin in (
            self.dns,
            self.audio,
            self.cli,
            self.observer,
            self.multicast,
        ):
            try:
                await plugin.load()
            except Exception as err:  # pylint: disable=broad-except
                _LOGGER.warning("Can't load plugin %s: %s", type(plugin).__name__, err)
                self.sys_capture_exception(err)

        # Check requirements
        for plugin, required_version in (
            (self._audio, self.required_audio),
            (self._dns, self.required_dns),
            (self._cli, self.required_cli),
            (self._observer, self.required_observer),
            (self._multicast, self.required_multicast),
        ):
            # Check if need an update
            try:
                if pkg_parse(plugin.version) >= required_version:
                    continue
            except TypeError:
                _LOGGER.warning(
                    "Somethings going wrong with requirements on %s",
                    type(plugin).__name__,
                )

            _LOGGER.info(
                "Requirement need update for %s - %s",
                type(plugin).__name__,
                required_version,
            )
            try:
                await plugin.update(version=str(required_version))
            except HassioError:
                _LOGGER.error(
                    "Can't update %s to %s but it's a reuirement, the Supervisor is not health now!",
                    type(plugin).__name__,
                    required_version,
                )
            except Exception as err:  # pylint: disable=broad-except
                _LOGGER.warning(
                    "Can't update plugin %s: %s", type(plugin).__name__, err
                )
                self.sys_capture_exception(err)

    async def repair(self) -> None:
        """Repair Supervisor plugins."""
        await asyncio.wait(
            [
                self.dns.repair(),
                self.audio.repair(),
                self.cli.repair(),
                self.observer.repair(),
                self.multicast.repair(),
            ]
        )

    async def shutdown(self) -> None:
        """Shutdown Supervisor plugin."""
        # Sequential to avoid issue on slow IO
        for plugin in (
            self.audio,
            self.cli,
            self.multicast,
            self.dns,
        ):
            try:
                await plugin.stop()
            except Exception as err:  # pylint: disable=broad-except
                _LOGGER.warning("Can't stop plugin %s: %s", type(plugin).__name__, err)
                self.sys_capture_exception(err)
Ejemplo n.º 5
0
 def need_update(self) -> bool:
     """Return true if a cli update is available."""
     try:
         return pkg_parse(self.version) < pkg_parse(self.latest_version)
     except (TypeError, ValueError):
         return False