Esempio n. 1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Yahoo! weather platform."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    forecast = config.get(CONF_FORECAST)
    name = config.get(CONF_NAME)

    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    # If not exists a customer WOEID/calculation from Home Assistant
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        if woeid is None:
            _LOGGER.warning("Can't retrieve WOEID from Yahoo!")
            return False

    yahoo_api = YahooWeatherData(woeid, yunit)

    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from Yahoo!")
        return False

    if forecast >= len(yahoo_api.yahoo.Forecast):
        _LOGGER.error("Yahoo! only support %d days forecast",
                      len(yahoo_api.yahoo.Forecast))
        return False

    add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True)
Esempio n. 2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Yahoo! weather platform."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    name = config.get(CONF_NAME)

    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    # If not exists a customer WOEID/calculation from Home Assistant
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        if woeid is None:
            _LOGGER.warning("Can't retrieve WOEID from Yahoo!")
            return False

    yahoo_api = YahooWeatherData(woeid, yunit)

    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from Yahoo!")
        return False

    # create condition helper
    if DATA_CONDITION not in hass.data:
        hass.data[DATA_CONDITION] = [str(x) for x in range(0, 50)]
        for cond, condlst in CONDITION_CLASSES.items():
            for condi in condlst:
                hass.data[DATA_CONDITION][condi] = cond

    add_entities([YahooWeatherWeather(yahoo_api, name, unit)], True)
Esempio n. 3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Yahoo! weather platform."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    name = config.get(CONF_NAME)

    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    # If not exists a customer WOEID/calculation from Home Assistant
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        if woeid is None:
            _LOGGER.warning("Can't retrieve WOEID from Yahoo!")
            return False

    yahoo_api = YahooWeatherData(woeid, yunit)

    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from Yahoo!")
        return False

    # create condition helper
    if DATA_CONDITION not in hass.data:
        hass.data[DATA_CONDITION] = [str(x) for x in range(0, 50)]
        for cond, condlst in CONDITION_CLASSES.items():
            for condi in condlst:
                hass.data[DATA_CONDITION][condi] = cond

    add_entities([YahooWeatherWeather(yahoo_api, name, unit)], True)
Esempio n. 4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Yahoo! weather platform."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    forecast = config.get(CONF_FORECAST)
    name = config.get(CONF_NAME)

    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    # If not exists a customer WOEID/calculation from Home Assistant
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        if woeid is None:
            _LOGGER.warning("Can't retrieve WOEID from Yahoo!")
            return False

    yahoo_api = YahooWeatherData(woeid, yunit)

    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from Yahoo!")
        return False

    if forecast >= len(yahoo_api.yahoo.Forecast):
        _LOGGER.error("Yahoo! only support %d days forecast",
                      len(yahoo_api.yahoo.Forecast))
        return False

    add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True)
Esempio n. 5
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Yahoo! weather sensor."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    forecast = config.get(CONF_FORECAST)
    name = config.get(CONF_NAME)

    # convert unit
    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    # for print HA style temp
    SENSOR_TYPES["temperature"][1] = unit
    SENSOR_TYPES["temp_min"][1] = unit
    SENSOR_TYPES["temp_max"][1] = unit

    # if not exists a customer woeid / calc from HA
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        # receive a error?
        if woeid is None:
            _LOGGER.critical("Can't retrieve WOEID from yahoo!")
            return False

    # create api object
    yahoo_api = YahooWeatherData(woeid, yunit)

    # if update is false, it will never work...
    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from yahoo!")
        return False

    # check if forecast support by API
    if forecast >= len(yahoo_api.yahoo.Forecast):
        _LOGGER.error("Yahoo! only support %d days forcast!",
                      len(yahoo_api.yahoo.Forecast))
        return False

    dev = []
    for variable in config[CONF_MONITORED_CONDITIONS]:
        dev.append(YahooWeatherSensor(yahoo_api, name, forecast, variable))

    add_devices(dev)
Esempio n. 6
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Yahoo! weather sensor."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    forecast = config.get(CONF_FORECAST)
    name = config.get(CONF_NAME)

    # convert unit
    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    # for print HA style temp
    SENSOR_TYPES["temperature"][1] = unit
    SENSOR_TYPES["temp_min"][1] = unit
    SENSOR_TYPES["temp_max"][1] = unit

    # if not exists a customer woeid / calc from HA
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        # receive a error?
        if woeid is None:
            _LOGGER.critical("Can't retrieve WOEID from yahoo!")
            return False

    # create api object
    yahoo_api = YahooWeatherData(woeid, yunit)

    # if update is false, it will never work...
    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from yahoo!")
        return False

    # check if forecast support by API
    if forecast >= len(yahoo_api.yahoo.Forecast):
        _LOGGER.error("Yahoo! only support %d days forcast!",
                      len(yahoo_api.yahoo.Forecast))
        return False

    dev = []
    for variable in config[CONF_MONITORED_CONDITIONS]:
        dev.append(YahooWeatherSensor(yahoo_api, name, forecast, variable))

    add_devices(dev)
Esempio n. 7
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Yahoo! weather sensor."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    forecast = config.get(CONF_FORECAST)
    name = config.get(CONF_NAME)

    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    SENSOR_TYPES['temperature'][1] = unit
    SENSOR_TYPES['temp_min'][1] = unit
    SENSOR_TYPES['temp_max'][1] = unit

    # If not exists a customer WOEID/calculation from Home Assistant
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        if woeid is None:
            _LOGGER.critical("Can't retrieve WOEID from yahoo!")
            return False

    yahoo_api = YahooWeatherData(woeid, yunit)

    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from Yahoo!")
        return False

    if forecast >= len(yahoo_api.yahoo.Forecast):
        _LOGGER.error("Yahoo! only support %d days forecast!",
                      len(yahoo_api.yahoo.Forecast))
        return False

    dev = []
    for variable in config[CONF_MONITORED_CONDITIONS]:
        dev.append(YahooWeatherSensor(yahoo_api, name, forecast, variable))

    add_entities(dev, True)
Esempio n. 8
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Yahoo! weather sensor."""
    from yahooweather import get_woeid, UNIT_C, UNIT_F

    unit = hass.config.units.temperature_unit
    woeid = config.get(CONF_WOEID)
    forecast = config.get(CONF_FORECAST)
    name = config.get(CONF_NAME)

    yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F

    SENSOR_TYPES['temperature'][1] = unit
    SENSOR_TYPES['temp_min'][1] = unit
    SENSOR_TYPES['temp_max'][1] = unit

    # If not exists a customer WOEID/calculation from Home Assistant
    if woeid is None:
        woeid = get_woeid(hass.config.latitude, hass.config.longitude)
        if woeid is None:
            _LOGGER.critical("Can't retrieve WOEID from yahoo!")
            return False

    yahoo_api = YahooWeatherData(woeid, yunit)

    if not yahoo_api.update():
        _LOGGER.critical("Can't retrieve weather data from Yahoo!")
        return False

    if forecast >= len(yahoo_api.yahoo.Forecast):
        _LOGGER.error("Yahoo! only support %d days forecast!",
                      len(yahoo_api.yahoo.Forecast))
        return False

    dev = []
    for variable in config[CONF_MONITORED_CONDITIONS]:
        dev.append(YahooWeatherSensor(yahoo_api, name, forecast, variable))

    add_devices(dev, True)
Esempio n. 9
0
import logging
from yahooweather import YahooWeather, get_woeid, UNIT_C

logging.basicConfig(level=logging.DEBUG)

yweather = YahooWeather(91543049, UNIT_C)
if yweather.updateWeather():
    print("RawData: %s" % str(yweather.RawData))
    print("Units: %s" % str(yweather.Units))
    print("Now: %s" % str(yweather.Now))
    print("Forecast: %s" % str(yweather.Forecast))
    print("Wind: %s" % str(yweather.Wind))
    print("Atmosphere: %s" % str(yweather.Atmosphere))
    print("Astronomy: %s" % str(yweather.Astronomy))

    data = yweather.Now
    print("Weather image from current: %s" %
          yweather.getWeatherImage(data["code"]))

    print("The woeid from Gstaad is: %s" % get_woeid(46.475661, 7.283469))

else:
    print("Can't read data from yahoo!")
Esempio n. 10
0
                gui("found: %s" % join(root, lookfor))
                break
        if d==False:
            speak('File not found\n')
            time.sleep(5)

    #weather
    elif 'weather' in data:
        data=data.split(' ')
        k=data.index('weather')
        city=data[k+2]
        geolocator = Nominatim()
        location = geolocator.geocode(city)
        logging.basicConfig(level=logging.WARNING)

        yweather = yahooweather.YahooWeather(yahooweather.get_woeid(location.latitude,location.longitude), UNIT_C)
        if yweather.updateWeather():
           
            
            data = yweather.Now
            
            speak('The temperature is '+data['temp']+' degree celcius.'+' Condition is '+data['text'])
            gui('The temperature is '+data['temp']+' degree celcius.'+' Condition is '+data['text'])

            
        else:
            print("Can't read data from yahoo!\n")
            time.sleep(5)
        

    #jokes