Example #1
0
    def tests_update_weather_400(self):
        def weather_callback(payload):
            self.assertEqual(payload, {
                'temp': 30,
                'weather': 'error getting weather data'
            })

        def request_callback(request):
            resp_body = {
                'who knows': {
                    'summary': 'sunny and meatballs',
                    'temperature': 77
                }
            }
            headers = {}
            return (400, headers, json.dumps(resp_body))

        responses.add_callback(
            responses.GET,
            _get_weather_url(),
            callback=request_callback,
            content_type='application/json',
        )

        # this tests the callback
        update_weather(callback=weather_callback)
Example #2
0
def main_loop():
    switch_led(False)
    # run once
    moisture_start = update_moisture_reading()
    weather_start = update_weather(callback=callback)
    while True:
        time.sleep(3)  # Yield for a while but keep main thread running
        moisture_start = update_moisture_reading(start_time=moisture_start)
        weather_start = update_weather(start_time=weather_start, callback=callback)
Example #3
0
def main_loop():
    switch_led(False)
    # run once
    moisture_start = update_moisture_reading()
    weather_start = update_weather(callback=callback)
    while True:
        time.sleep(3)  # Yield for a while but keep main thread running
        moisture_start = update_moisture_reading(start_time=moisture_start)
        weather_start = update_weather(start_time=weather_start,
                                       callback=callback)
Example #4
0
File: dawn.py Project: cknduru/dawn
def main():
    weather.update_weather()

    h, m = utils.format_current_time()

    # split this up to make pronounciation more fluent?
    greeting = """Good morning. The time is {} {} and it is time to wake up.
The weather is {} so im sure it will be a lovely day. I have prepared a song to start the day. Remember to book
christmas holiday and that you have visitors at six o clock""".format(
        h, m, weather.last_weather)

    if event_manager.should_trigger():
        utils.speak(greeting)

        utils.play_song('/home/pi/Desktop/dawn/music/fr.mp3')
Example #5
0
    def tests_update_weather_400(self):
        def weather_callback(payload):
            self.assertEqual(payload, {'temp': 30, 'weather': 'error getting weather data'})

        def request_callback(request):
            resp_body = {'who knows': {'summary': 'sunny and meatballs', 'temperature': 77}}
            headers = {}
            return (400, headers, json.dumps(resp_body))
        responses.add_callback(
            responses.GET, _get_weather_url(),
            callback=request_callback,
            content_type='application/json',
        )

        # this tests the callback
        update_weather(callback=weather_callback)
Example #6
0
    def tests_update_weather(self):
        def weather_callback(payload):
            self.assertEqual(payload, {'temp': 77, 'weather': 'sunny and meatballs'})

        def request_callback(request):
            resp_body = {'currently': {'summary': 'sunny and meatballs', 'temperature': 77}}
            headers = {}
            return (200, headers, json.dumps(resp_body))
        responses.add_callback(
            responses.GET, _get_weather_url(),
            callback=request_callback,
            content_type='application/json',
        )
        # get a time to start with
        start = time.time()
        # get a new time from update_weather since we didn't pass in start_time
        start_time = update_weather()
        self.assertLess(start, start_time)
        # start_time should be less that the returned time from update_weather
        self.assertLess(start_time, update_weather())
        # passing in a time should return that same time if one hour hasn't passed
        self.assertEqual(start_time, update_weather(start_time=start_time))
        # if our refresh threshold is passed we should get a new start time
        self.assertLess(start, update_weather(start_time=start, refresh_threshold_sec=0.00001))
        # this tests the callback
        update_weather(callback=weather_callback)
Example #7
0
    def tests_update_weather(self):
        def weather_callback(payload):
            self.assertEqual(payload, {
                'temp': 77,
                'weather': 'sunny and meatballs'
            })

        def request_callback(request):
            resp_body = {
                'currently': {
                    'summary': 'sunny and meatballs',
                    'temperature': 77
                }
            }
            headers = {}
            return (200, headers, json.dumps(resp_body))

        responses.add_callback(
            responses.GET,
            _get_weather_url(),
            callback=request_callback,
            content_type='application/json',
        )
        # get a time to start with
        start = time.time()
        # get a new time from update_weather since we didn't pass in start_time
        start_time = update_weather()
        self.assertLess(start, start_time)
        # start_time should be less that the returned time from update_weather
        self.assertLess(start_time, update_weather())
        # passing in a time should return that same time if one hour hasn't passed
        self.assertEqual(start_time, update_weather(start_time=start_time))
        # if our refresh threshold is passed we should get a new start time
        self.assertLess(
            start,
            update_weather(start_time=start, refresh_threshold_sec=0.00001))
        # this tests the callback
        update_weather(callback=weather_callback)
Example #8
0
 def test_update(self):
     w = weather.update_weather(weather.URL)
     self.assertIsNotNone(w)
     self.assertIsInstance(w, weather.WeatherInfo)
Example #9
0
 def test_update(self):
     w = weather.update_weather(weather.URL)
     self.assertIsNotNone(w)
     self.assertIsInstance(w, weather.WeatherInfo)