コード例 #1
0
ファイル: client.py プロジェクト: smarthall/python-lifx-sdk
    def __init__(self,
                 broadcast='255.255.255.255',
                 address='0.0.0.0',
                 discoverpoll=60,
                 devicepoll=5):
        """
        The Client object is responsible for discovering lights and managing
        incoming and outgoing packets. This is the class most people will use to
        interact with the lights.

        :param broadcast: The address to broadcast to when discovering devices.
        :param address: The address to receive packet on.
        :param discoverpoll: The time in second between attempts to discover new bulbs.
        :param devicepoll: The time is seconds between polls to check if devices still respond.
        """

        # Get Transport
        self._transport = network.NetworkTransport(address=address,
                                                   broadcast=broadcast)

        # Arguments
        self._discoverpolltime = discoverpoll
        self._devicepolltime = devicepoll

        # Generate Random Client ID
        self._source = random.randrange(1, pow(2, 32) - 1)

        # Start packet sequence at zero
        self._sequence = 0

        # Storage for devices
        self._devices = {}
        self._groups = {}
        self._locations = {}

        # Install our service packet handler
        pktfilter = lambda p: p.protocol_header.pkt_type == protocol.TYPE_STATESERVICE
        self._transport.register_packet_handler(self._servicepacket, pktfilter)

        # Install the group packet handler
        pktfilter = lambda p: p.protocol_header.pkt_type == protocol.TYPE_STATEGROUP
        self._transport.register_packet_handler(self._grouppacket, pktfilter)

        # Install the location packet handler
        pktfilter = lambda p: p.protocol_header.pkt_type == protocol.TYPE_STATELOCATION
        self._transport.register_packet_handler(self._locationpacket,
                                                pktfilter)

        # Send initial discovery packet
        self.discover()

        # Start polling threads
        self._discoverpoll = util.RepeatTimer(discoverpoll, self.discover)
        self._discoverpoll.daemon = True
        self._discoverpoll.start()
        self._devicepoll = util.RepeatTimer(devicepoll, self.poll_devices)
        self._devicepoll.daemon = True
        self._devicepoll.start()
コード例 #2
0
    def __init__(self):
        self.init = json.load(open("ws.ini", "rw"))
        self.init_logging = self.init["Init"]["Logging"]
        self.init_logfile = self.init["Init"]["Logfile"]
        self.init_rain = self.init["Init"]["Total rain"]
        self.prev_rain = 0

        logging.basicConfig(level=logging.DEBUG) if self.init_logging == "DEBUG" \
            else logging.basicConfig(level=logging.INFO)

        self.logger = logging.getLogger('WS1080')
        fh = RotatingFileHandler(self.init_logfile, mode='a', maxBytes=5 * 1024 * 1024, backupCount=2)
        fh.setLevel(logging.DEBUG)
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        ch.setFormatter(formatter)
        self.logger.addHandler(fh)
        self.logger.addHandler(ch)

        self.ws = ws.WS()

        self.timer = util.RepeatTimer(WS1080_UPDATE_INTERVAL, self.sync)
        self.timer.start()

        self.client = MongoClient()
        self.db_weather = self.client.WS
        self.cl_min = self.db_weather.minute
        self.cl_hourly = self.db_weather.hourly
        self.cl_daily = self.db_weather.daily
        self.cl_monthly = self.db_weather.monthly
        self.cl_yearly = self.db_weather.yearly
コード例 #3
0
    def __init__(self):
        self.frames = {}
        self.values = {}
        self.check()
        self.timer = util.RepeatTimer(30, self.check)
        self.start = self.timer.start
        self.stop = self.timer.stop

        self.on_fullscreen = funcs.Delegate()
コード例 #4
0
ファイル: MsnHttpSocket.py プロジェクト: sgricci/digsby
    def __init__(self, *a, **k):
        self._session_id = None
        msn.MSNSocketBase.__init__(self, *a, **k)
        self._q = []
        self._waiting = False
        self._poller = util.RepeatTimer(self.POLLINTERVAL, self._poll)
        self._poller._verbose = False
        self._closed = False
        self._poll_in_queue = False

        self._paused = False
コード例 #5
0
    def setup(self):
        log.info("UpdateManager setup")

        self.updating = False
        self.cancelling = False
        self.updater = None
        self.downloader = None
        self.update_checker = UpdateChecker()

        self._timer = util.RepeatTimer(
            common.pref("digsby.updater.update_interval",
                        type=int,
                        default=6 * 60 * 60), self.update)
        self._timer.start()

        self.fast_mode = False