示例#1
0
async def get_advice(intent: NluIntent):
    """Giving life advice."""
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(URL) as response:
                data = await response.read()
                message = json.loads(data)
                return EndSession(str(message['slip']['advice']))
    except aiohttp.ClientConnectionError:
        _LOGGER.exception("No Connection could be established.")
    except:  # pylint: disable=W0702
        _LOGGER.exception("An Exception occured")
    return EndSession("Sadly i cannot connect to my spring my whisdom. Maybe try later again.")
示例#2
0
def hass_TurnOn(intent: NluIntent):
    try:
        text = hass.handle_service_intent(intent) or None
    except:
        pass
    else:
        text = "Passing no Entity is not yet supported"
    return EndSession(text)
示例#3
0
async def yes(intent: NluIntent):
    """The user confirms."""
    if intent.custom_data == "TurnOffLight":
        response = "OK, turning off the light"
    elif intent.custom_data == "TurnOnLight":
        response = "OK, turning on the light"
    else:
        response = "We can!"

    return EndSession(response)
示例#4
0
async def get_temperature_intent(intent: NluIntent):
    """Tell the temperature."""

    raw_geolocation, raw_value = get_slot(intent, "geolocation",
                                          owm_default_geolocation)
    geolocation = raw_geolocation.split(",")

    poi = raw_value.title() if raw_value else "Default Location"

    _LOGGER.info(f"GetTemperature: {poi} ({geolocation})")

    try:

        weather = mgr.one_call(lat=float(geolocation[0]),
                               lon=float(geolocation[1]))
        temperature_forecast = weather.forecast_daily[0].temperature('celsius')
        temperature = weather.current.temperature('celsius')

        _LOGGER.info("Temperature: %s", temperature)

        temp_current = round(temperature.get("temp"))
        temp_max = round(temperature_forecast.get("max", -999))
        temp_min = round(temperature_forecast.get("min", -999))
        temp_feels_like = round(temperature.get("feels_like", -999))

        text_temp = f"In {poi} beträgt die Temperatur aktuell {temp_current} °C." if raw_geolocation != owm_default_geolocation else f"Aktuell sind es {temp_current} °C."

        if temp_feels_like != -999 and temp_feels_like != temp_current:
            text_temp += f" Es fühlt sich an wie {temp_feels_like} °C."

        if temp_min != -999 and temp_min != temp_current:
            text_temp += f" Die Tiefsttemperatur beträgt {temp_min} °C."

        if temp_max != -999 and temp_max != temp_current:
            text_temp += f" Die Höchsttemperatur beträgt {temp_max} °C."

        return EndSession(text_temp)
    except PyOWMError as e:
        _LOGGER.exception("Could not get current temperature.", exc_info=e)

    return EndSession(f"Etwas ist schiefgelaufen.")
def end_session(intent, sentence):
    print('session: ' + intent + ': ' + sentence)
    return EndSession(sentence)
示例#6
0
def get_time(intent: NluIntent):
    """Tell the time."""
    now = datetime.now().strftime("%H %M")
    return EndSession(f"It's {now}")
示例#7
0
async def no(intent: NluIntent):
    """The user says no."""
    return EndSession()
async def get_weather(intent: NluIntent):
    """Get weather"""
    forecast = weather.get_weather_forecast(intent, config_path=config["rhasspy_weather"]["config"])
    return EndSession(forecast)
async def get_date(intent: NluIntent):
    """Tell the weekday."""
    return EndSession(rhasspy_datetime.get_weekday(config_path=config["rhasspy_datetime"]["config"]))
示例#10
0
async def get_weather_intent(intent: NluIntent):
    """Tell the weather."""

    # In H betr temp momentan 3 bei bew himmel. heute nacht höchstwahrscheinlich regenschauer bei tiefst 1 grad
    # Hier ist der Wetterb für morgen in HE höchstwahr gibt es Schnee bei einer Höchsttemperatur von 4 und Tiefsttemperat von 2
    # Sonntag 1C und wechselnd bewölkt usw...
    # Morgen gibt es in Hamburg vereinzelte Schauer bei Temperaturen zwischen 2 und 4 Grad.
    # Morgen wird es in Berlin schneien bei Temperat...

    # In {poi} beträgt die Temperatur {temp} °C bei {condition}. Heute Nacht höchstwahrscheinlich {condition_forecast_night} bei einer Tiefsttemperatur von {} °C.

    # Hier ist der Wetterbericht für

    raw_geolocation, raw_value = get_slot(intent, "geolocation",
                                          owm_default_geolocation)
    geolocation = raw_geolocation.split(",")

    relative_time, _ = get_slot(intent, "relative_time")
    relative_date, _ = get_slot(intent, "relative_date")
    absolute_date, _ = get_slot(intent, "absolute_date")

    poi = raw_value.title() if raw_value else "Default Location"

    _LOGGER.info(f"GetWeatherForecast: {poi} ({geolocation})")

    try:

        weather = mgr.one_call(lat=float(geolocation[0]),
                               lon=float(geolocation[1]))

        forecast_data = weather.forecast_daily[0]

        if relative_date:
            rel = int(relative_date)

            if rel < 0:
                return EndSession(
                    random.choice([
                        "Ich kann leider keine historischen Wetterberichte abrufen.",
                        "Historische Wetterberichte werden zurzeit nicht unterstützt.",
                        "Wetterdaten aus der Vergangenheit sind aktuell nicht verfügbar."
                    ]))
            elif rel > 6:
                return EndSession(
                    random.choice([
                        "Wetterdaten sind nur bis maximal 7 Tage in der Zukunft verfügbar.",
                        "Der Wetterbericht kann nur für maximal eine Woche im Voraus abgefragt werden."
                    ]))

            forecast_data = weather.forecast_daily[rel]

        temperature = forecast_data.temperature('celsius')

        _LOGGER.info("Temperature: %s", temperature)

        condition = forecast_data.detailed_status
        temp_current = round(temperature.get("day"))
        temp_max = round(temperature.get("max", -999))
        temp_min = round(temperature.get("min", -999))
        temp_feels_like = round(temperature.get("feels_like_day", -999))

        is_default_location = raw_geolocation == owm_default_geolocation

        if relative_date:
            poi_data = f" in {poi}" if not is_default_location else ""
            text_temp = f"Wetter {relative_date_to_str(int(relative_date))}{poi_data}: {condition} bei Temperaturen zwischen {temp_min} und {temp_max} Grad."

        else:
            poi_data = f"In {poi} ist es {condition.lower()}" if not is_default_location else condition
            text_temp = f"{poi_data} bei aktuell {temp_current} Grad. Es fühlt sich an wie {temp_feels_like} Grad."

            if temp_min != -999 and temp_min != temp_current:
                text_temp += f" Die Tiefsttemperatur beträgt {temp_min} Grad."

            if temp_max != -999 and temp_max != temp_current:
                text_temp += f" Die Höchsttemperatur beträgt {temp_max} Grad."

        return EndSession(text_temp)
    except PyOWMError as e:
        _LOGGER.exception("Could not get current temperature.", exc_info=e)

    return EndSession(f"Etwas ist schiefgelaufen.")
示例#11
0
async def tell_joke(intent: NluIntent):
    """Tell a random joke."""
    _LOGGER.info("TellJoke")
    
    return EndSession(random.choice(jokes))
示例#12
0
async def get_date(intent: NluIntent):
    """Tell the date."""
    _LOGGER.info("GetDate")
    now = datetime.now().strftime("%d.%m.%Y")
    return EndSession(f"Heute ist der {now}.")
示例#13
0
async def get_time(intent: NluIntent):
    """Tell the time."""
    _LOGGER.info("GetTime")
    now = datetime.now().strftime("%H:%M")
    return EndSession(f"Es ist {now} Uhr.")