Ejemplo n.º 1
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the buienradar platform."""
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
    longitude = config.get(CONF_LONGITUDE, hass.config.longitude)

    if None in (latitude, longitude):
        _LOGGER.error("Latitude or longitude not set in Home Assistant config")
        return False

    coordinates = {
        CONF_LATITUDE: float(latitude),
        CONF_LONGITUDE: float(longitude)
    }

    # create weather data:
    data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, None)
    # create weather device:
    async_add_devices([
        BrWeather(data, config.get(CONF_FORECAST, True),
                  config.get(CONF_NAME, None))
    ])

    # Update weather every 10 minutes, since
    # the data gets updated every 10 minutes
    async_track_time_interval(hass, data.async_update, timedelta(minutes=10))
    # schedule the first update in 1 minute from now:
    data.schedule_update(1)
Ejemplo n.º 2
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the buienradar platform."""
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
    longitude = config.get(CONF_LONGITUDE, hass.config.longitude)

    if None in (latitude, longitude):
        _LOGGER.error("Latitude or longitude not set in Home Assistant config")
        return False

    coordinates = {
        CONF_LATITUDE: float(latitude),
        CONF_LONGITUDE: float(longitude)
    }

    # create weather data:
    data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, None)
    # create weather device:
    _LOGGER.debug("Initializing buienradar weather: coordinates %s",
                  coordinates)
    async_add_devices([
        BrWeather(data, config.get(CONF_FORECAST, True),
                  config.get(CONF_NAME, None))
    ])

    # schedule the first update in 1 minute from now:
    yield from data.schedule_update(1)
Ejemplo n.º 3
0
def async_setup_platform(hass,
                         config,
                         async_add_entities,
                         discovery_info=None):
    """Set up the buienradar platform."""
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
    longitude = config.get(CONF_LONGITUDE, hass.config.longitude)

    if None in (latitude, longitude):
        _LOGGER.error("Latitude or longitude not set in Home Assistant config")
        return False

    coordinates = {
        CONF_LATITUDE: float(latitude),
        CONF_LONGITUDE: float(longitude)
    }

    # create weather data:
    data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, None)
    # create weather device:
    _LOGGER.debug("Initializing buienradar weather: coordinates %s",
                  coordinates)

    # create condition helper
    if DATA_CONDITION not in hass.data:
        cond_keys = [str(chr(x)) for x in range(97, 123)]
        hass.data[DATA_CONDITION] = dict.fromkeys(cond_keys)
        for cond, condlst in CONDITION_CLASSES.items():
            for condi in condlst:
                hass.data[DATA_CONDITION][condi] = cond

    async_add_entities([BrWeather(data, config)])

    # schedule the first update in 1 minute from now:
    yield from data.schedule_update(1)
Ejemplo n.º 4
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the buienradar platform."""
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
    longitude = config.get(CONF_LONGITUDE, hass.config.longitude)

    if None in (latitude, longitude):
        _LOGGER.error("Latitude or longitude not set in Home Assistant config")
        return False

    coordinates = {CONF_LATITUDE:  float(latitude),
                   CONF_LONGITUDE: float(longitude)}

    # create weather data:
    data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, None)
    # create weather device:
    _LOGGER.debug("Initializing buienradar weather: coordinates %s",
                  coordinates)

    # create condition helper
    if DATA_CONDITION not in hass.data:
        cond_keys = [str(chr(x)) for x in range(97, 123)]
        hass.data[DATA_CONDITION] = dict.fromkeys(cond_keys)
        for cond, condlst in CONDITION_CLASSES.items():
            for condi in condlst:
                hass.data[DATA_CONDITION][condi] = cond

    async_add_devices([BrWeather(data, config)])

    # schedule the first update in 1 minute from now:
    yield from data.schedule_update(1)
Ejemplo n.º 5
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the buienradar platform."""
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
    longitude = config.get(CONF_LONGITUDE, hass.config.longitude)

    if None in (latitude, longitude):
        _LOGGER.error("Latitude or longitude not set in Home Assistant config")
        return False

    coordinates = {CONF_LATITUDE:  float(latitude),
                   CONF_LONGITUDE: float(longitude)}

    # create weather data:
    data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, None)
    # create weather device:
    _LOGGER.debug("Initializing buienradar weather: coordinates %s",
                  coordinates)
    async_add_devices([BrWeather(data, config.get(CONF_FORECAST, True),
                                 config.get(CONF_NAME, None))])

    # schedule the first update in 1 minute from now:
    yield from data.schedule_update(1)
Ejemplo n.º 6
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the buienradar platform."""
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
    longitude = config.get(CONF_LONGITUDE, hass.config.longitude)

    if None in (latitude, longitude):
        _LOGGER.error("Latitude or longitude not set in Home Assistant config")
        return False

    coordinates = {CONF_LATITUDE:  float(latitude),
                   CONF_LONGITUDE: float(longitude)}

    # create weather data:
    data = BrData(hass, coordinates, DEFAULT_TIMEFRAME, None)
    # create weather device:
    async_add_devices([BrWeather(data, config.get(CONF_FORECAST, True),
                                 config.get(CONF_NAME, None))])

    # Update weather every 10 minutes, since
    # the data gets updated every 10 minutes
    async_track_time_interval(hass, data.async_update, timedelta(minutes=10))
    # schedule the first update in 1 minute from now:
    data.schedule_update(1)