コード例 #1
0
    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()
コード例 #2
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	def add_switch(self,switch):
		dc = to_hc(switch.code)
#		if dc % 100 == 44 or dc // 100 == 44:
#			raise SyntaxError("Devices cannot have group or master codes")
		if switch.code in self.devs:
			raise RuntimeError("Device exists (%s in %s)" % (six.text_type(self.codes[switch.code]), six.text_type(self)))

		self.devs[switch.code] = switch
コード例 #3
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	def __init__(self,code,name):
		self.code = code
		self.name = SName(name)
		self.devs = {}
		self.last_dgram = None

		if self.code in codes:
			raise RuntimeError("Device exists (%s)" % (to_hc(self.code),))
		super(SwitchGroup,self).__init__()
		codes[self.code] = self
コード例 #4
0
    def __init__(self, code, name):
        self.code = code
        self.name = SName(name)
        self.devs = {}
        self.last_dgram = None

        if self.code in codes:
            raise RuntimeError("Device exists (%s)" % (to_hc(self.code), ))
        super(SwitchGroup, self).__init__()
        codes[self.code] = self
コード例 #5
0
    def add_switch(self, switch):
        dc = to_hc(switch.code)
        #		if dc % 100 == 44 or dc // 100 == 44:
        #			raise SyntaxError("Devices cannot have group or master codes")
        if switch.code in self.devs:
            raise RuntimeError(
                "Device exists (%s in %s)" %
                (six.text_type(self.codes[switch.code]), six.text_type(self)))

        self.devs[switch.code] = switch
コード例 #6
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	def list(self):
		yield super(Switch,self)
		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)
コード例 #7
0
    def list(self):
        yield super(Switch, self)
        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)
コード例 #8
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	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()
コード例 #9
0
ファイル: fs20sw.py プロジェクト: M-o-a-T/moat
	def dataReceived(self, ctx, data, handler=None, timedelta=None):
		if len(data) < 4:
			return # obviously way too short

		qs = 0
		for d in data:
			qs += ord(d)
		qs -= ord(data[-1]) # the above loop added it, that's nonsense
		qs = (ord(data[-1]) - qs) & 0xFF # we want the actual difference

		code = ord(data[0])*256+ord(data[1])
		try:
			g = groups[(code,qs)]
		except KeyError:
			simple_event("fs20","unknown","hc", hc=to_hc(code),checksum=qs,data=data)
			
		else:
			return g.datagramReceived(data[2:-1], handler, timedelta=timedelta)
コード例 #10
0
    def dataReceived(self, ctx, data, handler=None, timedelta=None):
        if len(data) < 4:
            return  # obviously way too short

        qs = 0
        for d in data:
            qs += ord(d)
        qs -= ord(data[-1])  # the above loop added it, that's nonsense
        qs = (ord(data[-1]) - qs) & 0xFF  # we want the actual difference

        code = ord(data[0]) * 256 + ord(data[1])
        try:
            g = groups[(code, qs)]
        except KeyError:
            simple_event("fs20",
                         "unknown",
                         "hc",
                         hc=to_hc(code),
                         checksum=qs,
                         data=data)

        else:
            return g.datagramReceived(data[2:-1], handler, timedelta=timedelta)
コード例 #11
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	def __repr__(self):
		try:
			return u"‹%s:%s:%s›" % (self.__class__.__name__, to_hc(self.code), self.name)
		except Exception:
			return "‹"+self.__class__.__name__+"›"
コード例 #12
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	def list(self):
		yield super(SwitchGroup,self)
		yield("code",to_hc(self.code))
		for d in self.devs.values():
			yield("device",d.name)
コード例 #13
0
ファイル: fs20switch.py プロジェクト: M-o-a-T/moat
	def info(self):
		return str(to_hc(self.code))
コード例 #14
0
 def __repr__(self):
     try:
         return u"‹%s:%s:%s›" % (self.__class__.__name__, to_hc(
             self.code), self.name)
     except Exception:
         return "‹" + self.__class__.__name__ + "›"
コード例 #15
0
 def list(self):
     yield super(SwitchGroup, self)
     yield ("code", to_hc(self.code))
     for d in self.devs.values():
         yield ("device", d.name)
コード例 #16
0
 def info(self):
     return str(to_hc(self.code))