Exemple #1
0
def setup(hass, config):
    """Set up the Melnor RainCloud component."""
    conf = config[DOMAIN]
    username = conf.get(CONF_USERNAME)
    password = conf.get(CONF_PASSWORD)
    scan_interval = conf.get(CONF_SCAN_INTERVAL)

    try:
        from raincloudy.core import RainCloudy

        raincloud = RainCloudy(username=username, password=password)
        if not raincloud.is_connected:
            raise HTTPError
        hass.data[DATA_RAINCLOUD] = RainCloudHub(raincloud)
    except (ConnectTimeout, HTTPError) as ex:
        _LOGGER.error("Unable to connect to Rain Cloud service: %s", str(ex))
        hass.components.persistent_notification.create(
            'Error: {}<br />'
            'You will need to restart hass after fixing.'
            ''.format(ex),
            title=NOTIFICATION_TITLE,
            notification_id=NOTIFICATION_ID)
        return False

    def hub_refresh(event_time):
        """Call Raincloud hub to refresh information."""
        _LOGGER.debug("Updating RainCloud Hub component.")
        hass.data[DATA_RAINCLOUD].data.update()
        dispatcher_send(hass, SIGNAL_UPDATE_RAINCLOUD)

    # Call the Raincloud API to refresh updates
    track_time_interval(hass, hub_refresh, scan_interval)

    return True
Exemple #2
0
    def setUp(self, mock):
        """Initialize rdy object for unittests."""
        from raincloudy.core import RainCloudy

        mock.get(LOGIN_ENDPOINT, text=load_fixture('home.html'))
        mock.post(LOGIN_ENDPOINT, text=load_fixture('home.html'))
        mock.post(DAJAXICE_ENDPOINT,
                  text=load_fixture('get_cu_and_fu_status.json'))
        mock.get(HOME_ENDPOINT, text=load_fixture('home.html'))

        # initialize self.rdy object
        self.rdy = RainCloudy(USERNAME, PASSWORD, ssl_warnings=False)
        self.rdy.update()
def setup(hass, config):
    """Set up the Melnor RainCloud component."""
    conf = config[DOMAIN]
    username = conf.get(CONF_USERNAME)
    password = conf.get(CONF_PASSWORD)
    scan_interval = conf.get(CONF_SCAN_INTERVAL)

    try:
        raincloud = RainCloudy(username=username, password=password)
        if not raincloud.is_connected:
            raise HTTPError
        hass.data[DATA_RAINCLOUD] = RainCloudHub(raincloud)
    except (ConnectTimeout, HTTPError) as ex:
        _LOGGER.error("Unable to connect to Rain Cloud service: %s", str(ex))
        hass.components.persistent_notification.create(
            f"Error: {ex}<br />"
            "You will need to restart hass after fixing.",
            title=NOTIFICATION_TITLE,
            notification_id=NOTIFICATION_ID,
        )
        return False

    def handle_rain_delay(call):
        """Set the rain delay for all valves"""

        days = call.data.get(RAIN_DELAY_DAYS_ATTR, 0)

        for controller in hass.data[DATA_RAINCLOUD].data.controllers:
            for faucet in controller.faucets:
                for zone in faucet.zones:
                    zone.rain_delay = days

        hass.data[DATA_RAINCLOUD].data.update()
        dispatcher_send(hass, SIGNAL_UPDATE_RAINCLOUD)

        return True

    hass.services.register(DOMAIN, RAIN_DELAY_SERVICE_ATTR, handle_rain_delay)

    def hub_refresh(event_time):
        """Call Raincloud hub to refresh information."""
        _LOGGER.debug("Updating RainCloud Hub component")
        hass.data[DATA_RAINCLOUD].data.update()
        dispatcher_send(hass, SIGNAL_UPDATE_RAINCLOUD)

    # Call the Raincloud API to refresh updates
    track_time_interval(hass, hub_refresh, scan_interval)

    return True
Exemple #4
0
DEBUG = False
app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '326240760871083756038276035325'

valid_commands = ["open", "auto", "close", "status", "rain"]
api_commands = "[controllerid]/[faucetid]/[open|close|status|rain/[zone#]/[time in mins/0/1]"

config = {
    "email": "EMAIL",  # fill in your email
    "password": "******"
}

controllers = {}

rdy = RainCloudy(config['email'], config['password'], ssl_warnings=False)
rdy.update()
for controller in rdy.controllers:
    print("Controller: " + controller.id + "  Status: " + controller.status)
    for faucet in controller.faucets:
        print("> Faucet: " + faucet.id + "  Status: " + faucet.status)


def status(rc):
    rc.update()
    # get controllers
    for controller in rc.controllers:
        if not controllers.get("controllers"):
            controllers['controllers'] = {}
        if not controllers['controllers'].get(controller.id):
            controllers["controllers"][controller.id] = {}