Voice-Plugins/car-weather-skill/__init__.py

36 lines
962 B
Python
Raw Normal View History

2020-12-21 17:59:23 +01:00
from mycroft import MycroftSkill, intent_file_handler
import requests
def emit(osd_url, event, data):
json = {
"event": event,
"data": data
}
print(json)
return requests.post(osd_url, json=json)
class CarWeather(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
@intent_file_handler('weather.car.intent')
def handle_weather_car(self, message):
osd_url = self.settings.get("OSD_API", "http://localhost:5050/send")
car_url = self.settings.get("CAR_API", "http://localhost:5000")
temp = requests.get(f"{car_url}/data/OutsideTemperature").json()["value"]
emission = {
"plugin": "temperature",
"data": {
"temperature": temp
},
"time": 5000
}
emit(osd_url, "switchPlugin", emission)
self.speak_dialog('weather.car', {"temp": temp})
def create_skill():
return CarWeather()