Exemplo n.º 1
0
    def notify_hubs(self):
        """Notify the subscribed SmartThings hubs that a state change has
           occurred"""
        if self.garage_door_status['last_state'] == 'closed':
            cmd = 'status-closed'
        else:
            cmd = 'status-open'
        for subscription in self.subscription_list:
            if self.subscription_list[subscription]['expiration'] > time():
                logging.info("Notifying hub %s", subscription)
		global urllist
		mytuple = urllist.partition("/status/")
		logging.info("Meter Number %s", mytuple[2])
		try:
                	msg = dbfunc_st.getMeterValues(mytuple[2])
		
			#msg = '<msg><cmd>%s</cmd><usn>[uuid:%s::%s]</usn></msg>' % (cmd, UUID, self.device_target)
			logging.info("Message: %s", msg)
                	body = StringProducer(msg)
                	agent = Agent(reactor)
                	req = agent.request(
                    	    'POST',
                    	    subscription,
                    	    Headers({'CONTENT-LENGTH': [len(msg)]}),
                    	    body)
                	req.addCallback(self.handle_response)
                	req.addErrback(self.handle_error)
		except:
                        logging.info("Database Error")
Exemplo n.º 2
0
    def render_GET(self, request): # pylint: disable=invalid-name
        """Handle polling requests from ST hub"""
        if request.path == '/status':
            if self.garage_door_status['last_state'] == 'closed':
                cmd = 'status-closed'
            else:
                cmd = 'status-open'
	    global urllist
            mytuple = urllist.partition("/status/")
            logging.info("Meter Number %s", mytuple[2])
            #msg='[1:[Reading:9845152, ind:12996, DT:1444417239.67782, M_Usage:3], 0:[Reading:9844274, ind:12799, DT:1444363355.41579, M_Usage:5], REQ:1]'
	    msg = dbfunc_st.getMeterValues(mytuple[2])
	   # msg = '<msg><cmd>%s</cmd><usn>uuid:%s::%s</usn></msg>' % (cmd, UUID, self.device_target)
	    #msg = '<msg><cmd>%s</cmd><usn>uuid:%s::%s</usn></msg>' % (cmd, UUID, self.device_target)
            logging.info("Polling request from %s for %s - returned %s",
                         request.getClientIP(),
                         request.path,
                         msg)
            return msg
        else:
            logging.info("Received bogus request from %s for %s",
                         request.getClientIP(),
                         request.path)
            return ""