def datagramReceived(self, data, handler=None, timedelta=None): if len(data) < 2: raise WrongDatagram(data) if self.last_dgram is not None and timedelta is not None and self.last_dgram == data and timedelta < 0.15: return self.last_dgram = data fcode = ord(data[1]) if fcode & 0x20: if len(data) != 3: raise WrongDatagram(data) ext = ord(data[2]) else: if len(data) != 2: raise WrongDatagram(data) ext = None dc = ord(data[0]) try: dev = self.devs[dc] except KeyError: simple_event( Context(), "fs20", "unknown", "device", to_hc(self.code), to_dev(dc), "".join("%02x" % ord(x) for x in data), ) return try: fn = switch_names[fcode & 0x1F] except KeyError: simple_event( Context(), "fs20", "unknown", "function", to_hc(self.code), fcode & 0x1F, "".join("%02x" % ord(x) for x in data), ) return if fcode & 0x80: hdl = dev.getReply else: hdl = dev.get if ext is not None: hdl(fn, ext, handler=handler) else: hdl(fn, handler=handler) data = chr(dc) + chr(fcode | 0x80) + data[2:] self.send(data, handler)
def list(self): yield ("name", self.name) yield ("code", to_dev(self.code)) yield ("parent", self.parent.name) yield ("parentcode", to_hc(self.parent.code)) for d in self.does: yield ("does", d) if self.state is not None: yield ("state", self.state) if self.handler: yield ("via", self.handler.name)
def run(self,ctx,**k): event = self.params(self.ctx) if self.new_hc is None: raise SyntaxError(u"‹fs20 switch› without sub-statements does nothing!") if self.hc is None: if self.code is None: raise SyntaxError(u"A new ‹fs20 switch› needs a ‹code› sub-statement!") self.hc = SwitchGroup(self.code, SName(event)) elif self.code is not None: self.hc.code = self.code ## update for s in self.old_sw: if s.parent != self.hc: raise RuntimeError("The named device has house code %d, not %d" % (to_hc(s.parent.code),to_hc(self.hc.code))) s.delete() for s in self.new_sw: if s.code in self.hc.devs: raise RuntimeError(u"The code ‹%d› is already known in ‹%d›" % (to_dev(s.code),to_hc(self.hc.code))) s.parent = self.hc s.add()
def info(self): return str(self.parent.name) + " " + str(to_dev(self.code))