Ejemplo n.º 1
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up this integration using UI."""
    hass.data.setdefault(DOMAIN, {})
    latitude = hass.config.latitude
    longitude = hass.config.longitude

    iss = pyiss.ISS()

    async def async_update() -> IssData:
        try:
            return await hass.async_add_executor_job(update, iss, latitude,
                                                     longitude)
        except (HTTPError, requests.exceptions.ConnectionError) as ex:
            raise UpdateFailed("Unable to retrieve data") from ex

    coordinator = DataUpdateCoordinator(
        hass,
        _LOGGER,
        name=DOMAIN,
        update_method=async_update,
        update_interval=timedelta(seconds=60),
    )

    await coordinator.async_config_entry_first_refresh()

    hass.data[DOMAIN] = coordinator

    entry.async_on_unload(entry.add_update_listener(update_listener))

    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

    return True
Ejemplo n.º 2
0
 def update(self):
     """Get the latest data from the ISS API."""
     try:
         iss = pyiss.ISS()
         self.is_above = iss.is_ISS_above(self.latitude, self.longitude)
         self.next_rise = iss.next_rise(self.latitude, self.longitude)
         self.number_of_people_in_space = iss.number_of_people_in_space()
         self.position = iss.current_location()
     except requests.exceptions.HTTPError as error:
         _LOGGER.error(error)
         return False
Ejemplo n.º 3
0
    def update(self):
        """Get the latest data from the ISS."""
        import pyiss

        try:
            iss = pyiss.ISS()
            self.is_above = iss.is_ISS_above(self.latitude, self.longitude)
            self.next_rise = iss.next_rise(self.latitude, self.longitude)
            self.number_of_people_in_space = iss.number_of_people_in_space()
            _LOGGER.error(self.next_rise.tzinfo)
        except requests.exceptions.HTTPError as error:
            _LOGGER.error(error)
            return False