def switch_toggle_loop(): """Toggle the switch on all devices in the directory""" global switch_state if Registry.size() > 0 and sendSwitchTimer.check(): print("transmit") radio.transmitter() for sensorid in Registry.get_sensorids(): # Only try to toggle the switch for devices that actually have a switch header = Registry.get_info(sensorid)["header"] mfrid = header["mfrid"] productid = header["productid"] if Devices.hasSwitch(mfrid, productid): request = OpenThings.alterMessage(Messages.SWITCH, header_sensorid=sensorid, recs_0_value=switch_state) p = OpenThings.encode(request) print("Sending switch message to %s %s" % (hex(productid), hex(sensorid))) # Transmit multiple times, hope one of them gets through radio.transmit(p, inner_times=2) radio.receiver() switch_state = (switch_state + 1) % 2 # toggle
def switch_toggle_loop(): """Toggle the switch on all devices in the directory""" global switch_state if Registry.size() > 0 and sendSwitchTimer.check(): print("transmit") radio.transmitter() for sensorid in Registry.get_sensorids(): # Only try to toggle the switch for devices that actually have a switch header = Registry.get_info(sensorid)["header"] mfrid = header["mfrid"] productid = header["productid"] if Devices.hasSwitch(mfrid, productid): request = OpenThings.alterMessage(Messages.SWITCH, header_sensorid=sensorid, recs_0_value=switch_state) p = OpenThings.encode(request) print("Sending switch message to %s %s" % (hex(productid), hex(sensorid))) # Transmit multiple times, hope one of them gets through radio.transmit(p, inner_times=2) radio.receiver() switch_state = (switch_state+1) % 2 # toggle
def updateDirectory(message): """Update the local directory with information about this device""" now = time.time() header = message["header"] sensorId = header["sensorid"] if not directory.has_key(sensorId): # new device discovered desc = Devices.getDescription(header["mfrid"], header["productid"]) print("ADD device:%s %s" % (hex(sensorId), desc)) directory[sensorId] = {"header": message["header"]} print(allkeys(directory)) directory[sensorId]["time"] = now
def updateDirectory(self, message): '''Update the local directory with information about this device''' now = time.time() header = message["header"] sensorId = header["sensorid"] if not self.directory.has_key(sensorId): # new device discovered desc = Devices.getDescription(header["mfrid"], header["productid"]) self.logger.info("ADD device:%s %s" % (hex(sensorId), desc)) self.directory[sensorId] = {"header": message["header"]} self.logger.info(self.allkeys(self.directory)) self.directory[sensorId]["time"] = now
def updateDirectory(self, message): '''Update the local directory with information about this device''' now = time.time() header = message["header"] sensorId = header["sensorid"] if not self.directory.has_key(sensorId): # new device discovered desc = Devices.getDescription(header["mfrid"], header["productid"]) self.logger.debug("ADD device:%s %s" % (hex(sensorId), desc)) self.directory[sensorId] = {"header": message["header"]} self.logger.debug(self.allkeys(self.directory)) self.directory[sensorId]["time"] = now
def updateDirectory(message): # Add the data from the most recent message into our storage directory. header = message['header'] mfrid = header['mfrid'] productid = header['productid'] sensorid = header['sensorid'] deviceID = "OT_%s-%s-%s" % (mfrid, productid, sensorid) if not directory.has_key(deviceID): directory[deviceID] = {} directory[deviceID]['Description'] = Devices.getDescription(header["mfrid"], header["productid"]) directory[deviceID]["time"] = int(time.time()) directory[deviceID]["data"] = getData(message) directory["__META"]["time"] = directory[deviceID]["time"]
def test_getDescription(self): self.assertEqual("Manufactuer:Energenie Product:C1 MONITOR", Devices.getDescription(0x04,0x01)) self.assertEqual("Manufactuer:Energenie Product:R1 MONITOR/CONTROL", Devices.getDescription(0x04,0x02)) self.assertEqual("Manufactuer:Energenie Product:eTRV", Devices.getDescription(0x04,0x03)) self.assertEqual("Manufactuer:Energenie Product:UNKNOWN", Devices.getDescription(0x04,0xff)) self.assertEqual("Manufactuer:UNKNOWN Product:UNKNOWN", Devices.getDescription(0xff,0x03), "Product ID should be manufacturer specific")