コード例 #1
0
def setup(hass, config):
    """Set up the Hunter Hydrawise component."""
    conf = config[DOMAIN]
    access_token = conf[CONF_ACCESS_TOKEN]
    scan_interval = conf.get(CONF_SCAN_INTERVAL)

    try:
        from hydrawiser.core import Hydrawiser

        hydrawise = Hydrawiser(user_token=access_token)
        hass.data[DATA_HYDRAWISE] = HydrawiseHub(hydrawise)
    except (ConnectTimeout, HTTPError) as ex:
        _LOGGER.error(
            "Unable to connect to Hydrawise 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 Hydrawise hub to refresh information."""
        _LOGGER.debug("Updating Hydrawise Hub component")
        hass.data[DATA_HYDRAWISE].data.update_controller_info()
        dispatcher_send(hass, SIGNAL_UPDATE_HYDRAWISE)

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

    return True
コード例 #2
0
ファイル: test_base.py プロジェクト: ptcryan/hydrawiser
    def setUp(self, mock):
        """Initialize rdy object for unittests."""
        from hydrawiser.core import Hydrawiser

        mock.get(STATUS_SCHEDULE, text=load_fixture('statusschedule.json'))
        mock.get(CUSTOMER_DETAILS, text=load_fixture('customerdetails.json'))
        mock.get(SET_ZONE, text=load_fixture('setzone.json'))

        # initialize self.rdy object
        self.rdy = Hydrawiser(GOOD_API_KEY)