コード例 #1
0
    def __init__(
        self,
        output=None,
        eufy=True,
        location=None,
        filename="/home/pi/rpi-terminal-hub/data/eufy.json",
        increment=15,
        autorun=True,
    ):
        schedule = getData("schedule.json")
        locations = getData("locations.json")

        if eufy:
            from src.eufy import Eufy

            self.startup()
            self.eufy = Eufy(filename=filename)
        self.webTime = WebTime()
        self.weather = Weather(locations, location)
        self.alerts = Alerts(location or list(locations.keys())[0])

        self.retry = False
        self.increment = increment
        self.schedule = {
            k: datetime.strptime(schedule[k], "%I:%M%p")
            for k in schedule.keys()
        }
        self.output = output
        self.start = True

        self.data = State()

        if autorun:
            self.loop()
コード例 #2
0
class TestWeather(unittest.TestCase):
    def setUp(self):
        self.weather = Weather()

    def test_weather_can_be_stormy(self):
        with mock.patch.object(self.weather, 'check_stormy') as mock_weather:
            mock_weather.return_value = (True)
            self.assertIs(self.weather.check_stormy(), True)

    def test_weather_can_be_not_stormy(self):
        with mock.patch.object(self.weather, 'check_stormy') as mock_weather:
            mock_weather.return_value = (False)
            self.assertIs(self.weather.check_stormy(), False)
コード例 #3
0
ファイル: test_weather.py プロジェクト: rskyte/airportpy-git
class WeatherTest(unittest.TestCase):
    def setUp(self):
        self.weather = Weather()

    def test_can_inform_on_whether_it_is_stormy(self):
        value = self.weather.is_stormy()
        self.assertEqual(type(value), bool)
コード例 #4
0
ファイル: test_weather.py プロジェクト: rskyte/airportpy-git
 def setUp(self):
     self.weather = Weather()
コード例 #5
0
 def test_getForecastTemperature(self):
     temp = Weather().getForecastTemperature()
     print temp
     self.assertTrue(hasattr(temp, 'min'))
     self.assertTrue(hasattr(temp, 'max'))
コード例 #6
0
 def __init__(self):
     self.timer = None
     self.viewIndex = 0  # defines which info will be displayed
     self.weather = Weather()
     self.display = Display()
     self._setupButtons()
コード例 #7
0
class ZerosegWeatherClock(object):
    def __init__(self):
        self.timer = None
        self.viewIndex = 0  # defines which info will be displayed
        self.weather = Weather()
        self.display = Display()
        self._setupButtons()

    def _setupButtons(self):
        GPIO.setmode(GPIO.BCM)  # Use BCM GPIO numbers
        GPIO.setup(SWITCH_1, GPIO.IN)
        GPIO.setup(SWITCH_2, GPIO.IN)

    def _resetViewIndex(self):
        """
        Reset the viewIndex to 0 ( = time and date) and the timer to None.
        """
        self.timer = None
        self.viewIndex = 0
        self.display.clear()
        self.updateView(
        )  # call the updateView method directly so the changes are displayed immediately.

    def _incrementViewIndex(self):
        """
        Increment the viewIndex to switch to the next view.
        """
        if self.timer is not None:
            self.timer.cancel()
        self.viewIndex += 1
        self.viewIndex = self.viewIndex % VIEW_TOTAL_NUMBER  # overflow
        self.timer = threading.Timer(DEFAULT_VIEW_DISPLAY_TIME,
                                     self._resetViewIndex)
        self.timer.start()
        self.display.clear()
        self.updateView(
        )  # call the updateView method directly so the changes are displayed immediately.

    def _updateDateTime(self):
        self.display.writeDateAndTime(datetime.now())

    def _updateTime(self):
        self.display.writeTime(dateTimeObject=datetime.now())

    def _updateDate(self):
        self.display.writeDate(dateTimeObject=datetime.now())

    def _updateTemperatureForecast(self):
        temperature = self.weather.getForecastTemperature()
        self.display.writeTemperatureLowHigh(tempLow=temperature.min,
                                             tempHigh=temperature.max)

    def _updateCurrentTemperature(self):
        temperature = self.weather.getCurrentTemperature()
        self.display.writeTemperatureCurrent(temp=temperature.current)

    def updateView(self):
        """
        Update the current view.
        """
        # check the viewIndex and call the corresponding function
        if self.viewIndex == VIEW_INDEX_TIME:
            self._updateTime()
        elif self.viewIndex == VIEW_INDEX_DATE:
            self._updateDate()
        elif self.viewIndex == VIEW_INDEX_TEMPERATURE_FORECAST:
            self._updateTemperatureForecast()
        elif self.viewIndex == VIEW_INDEX_TEMPERATURE_CURRENT:
            self._updateCurrentTemperature()

    def main(self):
        while True:
            try:
                if not GPIO.input(SWITCH_1) or not GPIO.input(SWITCH_2):
                    self._incrementViewIndex()
                self.updateView()
                time.sleep(DEFAULT_UPDATE_INTERVAL)
            except KeyboardInterrupt:
                # self._incrementViewIndex()
                # continue
                self.display.clear()
                raise
コード例 #8
0
 def __init__(self, capacity = DEFAULT_CAPACITY, weather = Weather()):
     self.planes = []
     self.capacity = capacity
     self.weather = weather
コード例 #9
0
ファイル: sb.py プロジェクト: Samael500/sev-boats
# -*- coding: utf-8 -*-
# import settings
# import pyowm
from src.weather import Weather
# from src.twitter import Twitter

weth = Weather()
# t = Twitter()

# t.post_image_weather()

# # print dir(weth.owm)

# # print dir(tomorrow)


# day = '{date} %d:00:00+00'.format(date=pyowm.timeutils.tomorrow().date())



# # wf = weth.forecast()

# # for w in wf:
# #     print w
# #     print w.get_wind()




out, date_title = weth.draw_img()
コード例 #10
0
import os

print(os.getcwd())
from src.gdp import GDP
from src.longlat import LongLat
from src.population import Population
from src.prices import Prices
from src.sales import Sales
from src.weather import Weather

GDP.write_gdp()
LongLat.write_longlat()
Weather.write_weather()
Population.write_population()
Prices.write_prices()
Sales.write_sales()
コード例 #11
0
class Loop:
    def __init__(
        self,
        output=None,
        eufy=True,
        location=None,
        filename="/home/pi/rpi-terminal-hub/data/eufy.json",
        increment=15,
        autorun=True,
    ):
        schedule = getData("schedule.json")
        locations = getData("locations.json")

        if eufy:
            from src.eufy import Eufy

            self.startup()
            self.eufy = Eufy(filename=filename)
        self.webTime = WebTime()
        self.weather = Weather(locations, location)
        self.alerts = Alerts(location or list(locations.keys())[0])

        self.retry = False
        self.increment = increment
        self.schedule = {
            k: datetime.strptime(schedule[k], "%I:%M%p")
            for k in schedule.keys()
        }
        self.output = output
        self.start = True

        self.data = State()

        if autorun:
            self.loop()

    # initialization
    def startup(self):
        os.system("sudo pigpiod")

    # calculate seconds until next minute interval
    def delayCalc(self):
        time_sec = round(time())
        self.delay = 60 - time_sec % 60

    # track schedule and see if task needs to be run
    def scheduler(self):
        try:
            weekday = self.webTime.weekday
            hour = self.webTime.hour
            minute = self.webTime.minute

            # reset status at midnight or on start
            if (hour == 0 and minute == 0) or self.start:
                self.eufy.status = 0  # reset status

            # if there a schedule for today and it is not scheduled, change to scheduled
            if weekday in self.schedule.keys() and self.eufy.status == 0:
                self.eufy.status = 1

            # if vacuum is supposed to be run today, check for the correct time
            if self.eufy.status == 1:
                if (hour == self.schedule[weekday].hour
                        and minute == self.schedule[weekday].minute):
                    self.eufy.status = 2
                    self.time = time()
                    return True

            # if vacuum is running, after 1.5 hours mark as complete
            if self.eufy.status == 2 and time() - self.time > 90 * 60:
                self.eufy.status = 3
        except Exception as e:
            self.eufy.status = 0  # reset status on error & log
            traceback.print_exc()

        return False

    # fetch data with retry logic
    def fetch(self):
        try:
            # fetch data
            self.weather.fetch()
            self.webTime.fetch()
            self.alerts.fetch()

            # write data to state
            self.data.update("weather", self.weather.data)
            self.data.update("updated", self.webTime.timestamp)
            self.data.update(
                "alerts",
                f"Alerts{' ['+self.alerts.name+']' if self.alerts.name != '' else self.alerts.name}: {', '.join(self.alerts.data) or None}",
            )

            self.retry = False
        except Exception as e:  # if error, retry in the next minute
            self.retry = True

    def loop(self):
        while True:
            # fetch data on first run or retry request or based on minute interval
            if self.start or self.retry or self.webTime.minute % self.increment == 0:
                self.fetch()

            # run vacuum checks
            if hasattr(self, "eufy") and self.scheduler():
                self.eufy.emit("start_stop")
            self.data.update(
                "eufy",
                f"Eufy Status: {self.eufy.print() if hasattr(self, 'eufy') else 'N/A'}",
            )

            # if data is changed, push data to queue
            if self.data.changed:
                self.output.put(self.data.__dict__)  # return data
                self.data.clear()  # clear changed state

            # clear start up triggers
            if self.start:
                self.start = False

            # pause until next interval
            self.delayCalc()
            self.webTime.inc(
            )  # increment minute (not polling API every minute)
            sleep(self.delay)
コード例 #12
0
 def __init__(self, weather=Weather()):
     self.hanger = []
     self.weather = weather
コード例 #13
0
def test_weather_is_stormy():
    random.seed(1)
    weather = Weather()

    assert weather.is_stormy() == False
コード例 #14
0
def test_weather_is_not_stormy():
    random.seed(2)
    weather = Weather()

    assert weather.is_stormy() == True