Ejemplo n.º 1
0
    def __init__(
        self,
        hass: HomeAssistant,
        *,
        config: Mapping[str, Any],
        options: Mapping[str, Any],
    ) -> None:
        """Initialize global NZBGet data updater."""
        self.nzbget = NZBGetAPI(
            config[CONF_HOST],
            config.get(CONF_USERNAME),
            config.get(CONF_PASSWORD),
            config[CONF_SSL],
            config[CONF_VERIFY_SSL],
            config[CONF_PORT],
        )

        self._completed_downloads_init = False
        self._completed_downloads = set[tuple]()

        update_interval = timedelta(seconds=options[CONF_SCAN_INTERVAL])

        super().__init__(
            hass,
            _LOGGER,
            name=DOMAIN,
            update_interval=update_interval,
        )
Ejemplo n.º 2
0
    def __init__(self, opp: OpenPeerPower, *, config: dict,
                 options: dict) -> None:
        """Initialize global NZBGet data updater."""
        self.nzbget = NZBGetAPI(
            config[CONF_HOST],
            config.get(CONF_USERNAME),
            config.get(CONF_PASSWORD),
            config[CONF_SSL],
            config[CONF_VERIFY_SSL],
            config[CONF_PORT],
        )

        self._completed_downloads_init = False
        self._completed_downloads = {}

        update_interval = timedelta(seconds=options[CONF_SCAN_INTERVAL])

        super().__init__(
            opp,
            _LOGGER,
            name=DOMAIN,
            update_interval=update_interval,
        )
Ejemplo n.º 3
0
import sys
import argparse
from pynzbgetapi import NZBGetAPI


if __name__=="__main__":
        
    parser = argparse.ArgumentParser(description='Call NZBGet APIs.')
    parser.add_argument('host', help='the host')
    parser.add_argument('-u', '--username', dest='username', action='store', required=False,
                        help='the host')
    parser.add_argument('-pw', '--password', dest='password', action='store', required=False,
                        help='the host')                                                
    args = parser.parse_args()
    nzb_api = NZBGetAPI(args.host, port=6789, username=args.username, password=args.password, secure=False, verify_certificate=False)

    print(nzb_api.version())
    print(nzb_api.status())
    
    res = nzb_api.history()
    print(res)

    print(res.scan())
    print(res.status())

Ejemplo n.º 4
0
class NZBGetDataUpdateCoordinator(DataUpdateCoordinator):
    """Class to manage fetching NZBGet data."""
    def __init__(self, hass: HomeAssistant, *, config: dict,
                 options: dict) -> None:
        """Initialize global NZBGet data updater."""
        self.nzbget = NZBGetAPI(
            config[CONF_HOST],
            config.get(CONF_USERNAME),
            config.get(CONF_PASSWORD),
            config[CONF_SSL],
            config[CONF_VERIFY_SSL],
            config[CONF_PORT],
        )

        self._completed_downloads_init = False
        self._completed_downloads = {}

        update_interval = timedelta(seconds=options[CONF_SCAN_INTERVAL])

        super().__init__(
            hass,
            _LOGGER,
            name=DOMAIN,
            update_interval=update_interval,
        )

    def _check_completed_downloads(self, history):
        """Check history for newly completed downloads."""
        actual_completed_downloads = {(x["Name"], x["Category"], x["Status"])
                                      for x in history}

        if self._completed_downloads_init:
            tmp_completed_downloads = list(
                actual_completed_downloads.difference(
                    self._completed_downloads))

            for download in tmp_completed_downloads:
                self.hass.bus.fire(
                    "nzbget_download_complete",
                    {
                        "name": download[0],
                        "category": download[1],
                        "status": download[2],
                    },
                )

        self._completed_downloads = actual_completed_downloads
        self._completed_downloads_init = True

    async def _async_update_data(self) -> dict:
        """Fetch data from NZBGet."""
        def _update_data() -> dict:
            """Fetch data from NZBGet via sync functions."""
            status = self.nzbget.status()
            history = self.nzbget.history()

            self._check_completed_downloads(history)

            return {
                "status": status,
                "downloads": history,
            }

        try:
            async with timeout(4):
                return await self.hass.async_add_executor_job(_update_data)
        except NZBGetAPIException as error:
            raise UpdateFailed(
                f"Invalid response from API: {error}") from error